mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-07-24 12:06:34 +00:00
* Setup templates rework * Update docs * Implement backwards compatible parsing * Work * Finish build templates
176 lines
4.2 KiB
C#
176 lines
4.2 KiB
C#
using Daybreak.Shared.Models.Builds;
|
|
using Daybreak.Shared.Models.Guildwars;
|
|
using Daybreak.Shared.Services.BuildTemplates;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using TrailBlazr.Services;
|
|
|
|
namespace Daybreak.Views;
|
|
|
|
public sealed class TeamBuildTemplateViewModel(
|
|
IBuildTemplateManager buildTemplateManager,
|
|
IAttributePointCalculator attributePointCalculator,
|
|
IViewManager viewManager)
|
|
: BuildTemplateViewModelBase<TeamBuildTemplateViewModel, TeamBuildTemplateView>(buildTemplateManager, attributePointCalculator, viewManager)
|
|
{
|
|
public TeamBuildEntry? TeamEntry
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
field = value;
|
|
this.NotifyPropertyChanged(nameof(this.TeamEntry));
|
|
this.UpdateTeamCode();
|
|
}
|
|
}
|
|
|
|
public string TeamCode
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
field = value;
|
|
this.NotifyPropertyChanged(nameof(this.TeamCode));
|
|
}
|
|
} = string.Empty;
|
|
|
|
public int BuildEntryIndex
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
field = value;
|
|
this.NotifyPropertyChanged(nameof(this.BuildEntryIndex));
|
|
}
|
|
}
|
|
|
|
public bool SummaryVisible
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
field = value;
|
|
this.NotifyPropertyChanged(nameof(this.SummaryVisible));
|
|
}
|
|
} = false;
|
|
|
|
protected override void LoadBuild(IBuildEntry? buildEntry)
|
|
{
|
|
if (buildEntry is not TeamBuildEntry teamBuildEntry)
|
|
{
|
|
throw new InvalidOperationException($"Expected build entry to be of type {nameof(TeamBuildEntry)} but got {buildEntry?.GetType().Name}");
|
|
}
|
|
|
|
this.TeamEntry = teamBuildEntry;
|
|
this.BuildEntry = teamBuildEntry.Builds.FirstOrDefault();
|
|
this.BuildEntryIndex = 0;
|
|
}
|
|
|
|
protected override IBuildEntry SaveBuild()
|
|
{
|
|
return this.TeamEntry ?? throw new InvalidOperationException("Team build is null");
|
|
}
|
|
|
|
protected override void ChangeBuildName(string buildName)
|
|
{
|
|
if (this.TeamEntry is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.TeamEntry.Name = buildName;
|
|
}
|
|
|
|
public void SummarySkillMouseEnter(Skill skill, MouseEventArgs e)
|
|
{
|
|
this.OpenSkillSnippet(skill, e);
|
|
}
|
|
|
|
public void SummarySkillMouseLeave(Skill skill, MouseEventArgs e)
|
|
{
|
|
this.CloseSkillSnippet(skill, e);
|
|
}
|
|
|
|
public void BuildNameChanged(string buildName)
|
|
{
|
|
if (this.TeamEntry is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.TeamEntry.Name = buildName;
|
|
this.RefreshView();
|
|
}
|
|
|
|
public void BuildSelectionChanged(ChangeEventArgs args)
|
|
{
|
|
if (this.TeamEntry is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args.Value?.ToString(), out var index))
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.BuildEntry = this.TeamEntry.Builds.Skip(index).FirstOrDefault();
|
|
this.BuildEntryIndex = index;
|
|
this.UpdateBuildCode();
|
|
this.FilterSkillsByProfessionsAndString();
|
|
}
|
|
|
|
public void ShowSummary()
|
|
{
|
|
this.SummaryVisible = true;
|
|
this.RefreshView();
|
|
}
|
|
|
|
public void HideSummary()
|
|
{
|
|
this.SummaryVisible = false;
|
|
this.RefreshView();
|
|
}
|
|
|
|
protected override void UpdateBuildCode()
|
|
{
|
|
base.UpdateBuildCode();
|
|
this.UpdateTeamCode();
|
|
}
|
|
|
|
private void UpdateTeamCode()
|
|
{
|
|
if (this.TeamEntry is null)
|
|
{
|
|
this.TeamCode = string.Empty;
|
|
return;
|
|
}
|
|
|
|
this.TeamCode = this.buildTemplateManager.EncodeTemplate(this.TeamEntry);
|
|
}
|
|
|
|
public void TeamCodeChanged(string teamCode)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(teamCode))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!this.buildTemplateManager.TryDecodeTemplate(teamCode, out var buildEntry))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (buildEntry is not TeamBuildEntry teamBuildEntry)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.TeamEntry = teamBuildEntry;
|
|
this.BuildEntry = teamBuildEntry.Builds.FirstOrDefault();
|
|
this.BuildEntryIndex = 0;
|
|
this.FilterSkillsByProfessionsAndString();
|
|
this.RefreshView();
|
|
}
|
|
}
|