Skip to content

Commit d887f2c

Browse files
committed
Make build code writable (Closes #1358) (#1364)
1 parent b079be2 commit d887f2c

File tree

5 files changed

+68
-29
lines changed

5 files changed

+68
-29
lines changed

Daybreak.Shared/Services/BuildTemplates/BuildTemplateManager.cs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -399,36 +399,44 @@ public IBuildEntry DecodeTemplate(string template)
399399

400400
public bool TryDecodeTemplate(string template, [NotNullWhen(true)] out IBuildEntry? build)
401401
{
402-
var maybeBuilds = this.DecodeTemplatesInner(template);
403-
if (maybeBuilds is not null)
402+
try
404403
{
405-
var randomName = Guid.NewGuid().ToString();
406-
build = maybeBuilds.Length == 1 ?
407-
new SingleBuildEntry
408-
{
409-
Name = randomName,
410-
PreviousName = randomName,
411-
Primary = maybeBuilds[0].Primary,
412-
Secondary = maybeBuilds[0].Secondary,
413-
Attributes = maybeBuilds[0].Attributes,
414-
Skills = maybeBuilds[0].Skills
415-
} :
416-
new TeamBuildEntry
417-
{
418-
Name = randomName,
419-
PreviousName = randomName,
420-
Builds = maybeBuilds.Select(b => new SingleBuildEntry
404+
var maybeBuilds = this.DecodeTemplatesInner(template);
405+
if (maybeBuilds is not null)
406+
{
407+
var randomName = Guid.NewGuid().ToString();
408+
build = maybeBuilds.Length == 1 ?
409+
new SingleBuildEntry
421410
{
422411
Name = randomName,
423412
PreviousName = randomName,
424-
Primary = b.Primary,
425-
Secondary = b.Secondary,
426-
Attributes = b.Attributes,
427-
Skills = b.Skills
428-
}).ToList()
429-
};
430-
431-
return true;
413+
Primary = maybeBuilds[0].Primary,
414+
Secondary = maybeBuilds[0].Secondary,
415+
Attributes = maybeBuilds[0].Attributes,
416+
Skills = maybeBuilds[0].Skills
417+
} :
418+
new TeamBuildEntry
419+
{
420+
Name = randomName,
421+
PreviousName = randomName,
422+
Builds = maybeBuilds.Select(b => new SingleBuildEntry
423+
{
424+
Name = randomName,
425+
PreviousName = randomName,
426+
Primary = b.Primary,
427+
Secondary = b.Secondary,
428+
Attributes = b.Attributes,
429+
Skills = b.Skills
430+
}).ToList()
431+
};
432+
433+
return true;
434+
}
435+
}
436+
catch (Exception e)
437+
{
438+
var scopedLogger = this.logger.CreateScopedLogger();
439+
scopedLogger.LogError(e, "Failed to decode build template");
432440
}
433441

434442
build = default;

Daybreak/Views/BuildTemplateViewModelBase.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,30 @@ public bool ShowSkillSnippet
7575

7676
public void BuildNameChanged(string buildName)
7777
{
78-
if (this.View is null)
78+
this.ChangeBuildName(buildName);
79+
this.RefreshView();
80+
}
81+
82+
public void BuildCodeChanged(string buildCode)
83+
{
84+
if (!this.buildTemplateManager.TryDecodeTemplate(buildCode, out var build))
7985
{
8086
return;
8187
}
8288

83-
this.ChangeBuildName(buildName);
89+
if (build is SingleBuildEntry s1 && this.BuildEntry is SingleBuildEntry thisBuild)
90+
{
91+
thisBuild.Skills = s1.Skills;
92+
thisBuild.Attributes = s1.Attributes;
93+
thisBuild.Primary = s1.Primary;
94+
thisBuild.Secondary = s1.Secondary;
95+
}
96+
else
97+
{
98+
// Currently only SingleBuildEntry is supported to change build code.
99+
return;
100+
}
101+
84102
this.RefreshView();
85103
}
86104

Daybreak/Views/Components/Builds/BuildEditor.razor

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="build-info-section">
55
<div class="build-field">
66
<label for="build-code">Build Code:</label>
7-
<input id="build-code" type="text" @bind="this.BuildTemplateCode" readonly class="build-code-input" />
7+
<input id="build-code" type="text" @bind="this.BuildTemplateCode" @oninput="this.BuildCodeChangedHandler" class="build-code-input" />
88
</div>
99

1010
<div class="build-field">
@@ -187,6 +187,9 @@
187187
[Parameter]
188188
public required Action<string> BuildNameChanged { get; init; }
189189

190+
[Parameter]
191+
public required Action<string> BuildCodeChanged { get; init; }
192+
190193
private bool isSkillsPanelExpanded = false;
191194
private int selectedSkillIndex = -1;
192195
private string searchTerm = string.Empty;
@@ -257,4 +260,12 @@
257260
this.BuildNameChanged(newName);
258261
}
259262
}
263+
264+
private void BuildCodeChangedHandler(ChangeEventArgs e)
265+
{
266+
if (e.Value is string newCode)
267+
{
268+
this.BuildCodeChanged(newCode);
269+
}
270+
}
260271
}

Daybreak/Views/SingleBuildTemplateView.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
PrimaryProfessionChanged="@this.ViewModel.PrimaryProfessionChanged"
2222
SecondaryProfessionChanged="@this.ViewModel.SecondaryProfessionChanged"
2323
BuildNameChanged="@this.ViewModel.BuildNameChanged"
24+
BuildCodeChanged="@this.ViewModel.BuildCodeChanged"
2425
OnSkillHoverEnter="@this.ViewModel.OpenSkillSnippet"
2526
OnSkillHoverLeave="@this.ViewModel.CloseSkillSnippet" />
2627
}

Daybreak/Views/TeamBuildTemplateView.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
PrimaryProfessionChanged="@this.ViewModel.PrimaryProfessionChanged"
4949
SecondaryProfessionChanged="@this.ViewModel.SecondaryProfessionChanged"
5050
BuildNameChanged="@this.ViewModel.BuildNameChanged"
51+
BuildCodeChanged="@this.ViewModel.BuildCodeChanged"
5152
OnSkillHoverEnter="@this.ViewModel.OpenSkillSnippet"
5253
OnSkillHoverLeave="@this.ViewModel.CloseSkillSnippet" />
5354
}

0 commit comments

Comments
 (0)