Skip to content

Commit

Permalink
Can convert support characters to player characters
Browse files Browse the repository at this point in the history
  • Loading branch information
qkmaxware committed May 26, 2021
1 parent 32c23d3 commit be79af6
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 124 deletions.
26 changes: 16 additions & 10 deletions TrekSharp.AdventureTools/Shared/CharacterEditorPopoutTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
<div class="w3-bar-block w3-padding">
<button class="w3-bar-item w3-margin-bottom" style="font-size: medium;" @onclick=AddMilestone>+ Milestone</button>
<button class="w3-bar-item w3-margin-bottom" style="font-size: medium;" @onclick=Promote>+ Promotion</button>
@if (Character is SupportCharacter sc) {
<button class="w3-bar-item w3-margin-bottom" style="font-size: medium;" @onclick=assumingDirectControl>Reintroduce</button>
@if (sc.IsPlayerEquivalent) {
<button class="w3-bar-item w3-margin-bottom" style="font-size: medium;" @onclick=upgradeToPlayer>Convert to Player Character</button>
} else {
<button class="w3-bar-item w3-margin-bottom w3-grey" style="font-size: medium;" title="requires at least 6 focuses, 4 values, and 1 talent">Upgrade to Player Character</button>
}
}
</div>
@if (Character is SupportCharacter sc) {
if (!sc.HasBeenIntroduced) {
<div class="typeface text-secondary w3-border-bottom w3-large">
<b>Player Options</b>
</div>
<div class="w3-bar-block w3-padding">
<button class="w3-bar-item w3-margin-bottom" style="font-size: medium;" @onclick=assumingDirectControl>Assume Player Control</button>
</div>
}
}

<div class="typeface text-secondary w3-border-bottom w3-large">
<b>Other</b>
</div>
Expand Down Expand Up @@ -75,6 +74,13 @@
}
}

private void upgradeToPlayer() {
if (HasCharacter && Character is SupportCharacter sc) {
this.Data.Supports.Remove(sc);
this.Data.Party.Add(sc.UpgradeToPlayer());
}
}

private ConfirmationDialog confirm;
private void confirmDelete() {
confirm.Open($"Are you sure you want to delete the character '{this.Character.Name}'?", () => Delete());
Expand Down
4 changes: 3 additions & 1 deletion TrekSharp.AdventureTools/Shared/FilePopup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
private Popup popup;
private AssetImporter<AppData> importer;

[Parameter] public Action OnFileLoaded {get; set;}

public void Open() {
popup.Open();
}
Expand All @@ -57,7 +59,7 @@
}
private void onAppDataLoaded(AppData data) {
this.Data.Overwrite(data);
this.StateHasChanged();
OnFileLoaded?.Invoke();
this.NavigateHome();
}

Expand Down
31 changes: 19 additions & 12 deletions TrekSharp.AdventureTools/Shared/MilestoneEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</TabPage>
@if (Character is PlayableCharacter pc) {
<TabPage Title="Change Talent">
<TalentPicker @ref=spotlightTalentSwap RequireDelete=true GetPlayer=@(() => pc)></TalentPicker>
<TalentSwap @ref=spotlightTalentSwap Character=pc></TalentSwap>
</TabPage>
}
</TabLayout>
Expand All @@ -89,7 +89,7 @@
</TabPage>
@if (Character is PlayableCharacter pc) {
<TabPage Title="Add Talent">
<TalentPicker @ref=arcNewTalent GetPlayer=@(() => pc)></TalentPicker>
<TalentSelect @ref=arcNewTalent Character=pc></TalentSelect>
</TabPage>
}
<TabPage Title="Add Focus">
Expand Down Expand Up @@ -129,16 +129,15 @@

spotlightAttributeDelta = new Attributes(0);
if (spotlightTalentSwap != null) {
spotlightTalentSwap.DeletedTalent = null;
spotlightTalentSwap.SelectedTalent = null;
spotlightTalentSwap.Deselect();
}

arcDisciplineDelta = new Disciplines(0);
arcAttributeDelta = new Attributes(0);
arcNewFocus = null;
arcNewValue = null;
if (arcNewTalent != null)
arcNewTalent.SelectedTalent = null;
arcNewTalent.Deselect();
StateHasChanged();
}

Expand All @@ -153,9 +152,11 @@

Character.Attributes.Add(spotlightAttributeDelta);
if (Character is PlayableCharacter pc) {
if (spotlightTalentSwap != null && spotlightTalentSwap.DeletedTalent != null && spotlightTalentSwap.SelectedTalent != null) {
pc.Talents.Remove(spotlightTalentSwap.DeletedTalent);
pc.Talents.Add(spotlightTalentSwap.SelectedTalent);
if (pc.Talents == null) {
pc.Talents = new List<CharacterTalent>();
}
if (spotlightTalentSwap != null) {
spotlightTalentSwap.Swap();
}
}

Expand All @@ -169,8 +170,14 @@
Character.Values.Add(arcNewValue);
}
if (Character is PlayableCharacter ppc) {
if (arcNewTalent != null && arcNewTalent.SelectedTalent != null) {
ppc.Talents.Add(arcNewTalent.SelectedTalent);
if (arcNewTalent != null ) {
var t = arcNewTalent.Talent;
if (t != null) {
if (ppc.Talents == null) {
ppc.Talents = new List<CharacterTalent>();
}
ppc.Talents.Add(t);
}
}
}
OnSave?.Invoke();
Expand All @@ -190,13 +197,13 @@
private Disciplines normalDisciplineDelta = new Disciplines(0);

private Attributes spotlightAttributeDelta = new Attributes(0);
private TalentPicker spotlightTalentSwap;
private TalentSwap spotlightTalentSwap;


private Disciplines arcDisciplineDelta = new Disciplines(0);
private Attributes arcAttributeDelta = new Attributes(0);
private string arcNewFocus = null;
private string arcNewValue = null;
private TalentPicker arcNewTalent;
private TalentSelect arcNewTalent;

}
2 changes: 1 addition & 1 deletion TrekSharp.AdventureTools/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
</div>
</div>

<FilePopup @ref=files></FilePopup>
<FilePopup @ref=files OnFileLoaded=StateHasChanged></FilePopup>
<HelpPopup @ref=help></HelpPopup>

@code {
Expand Down
35 changes: 35 additions & 0 deletions TrekSharp.AdventureTools/Shared/Select.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@typeparam T

<input class="w3-input w3-margin-bottom" list="select_list_@ComponentGuid" placeholder="@Placeholder" @bind=selectedString />
<datalist id="select_list_@ComponentGuid">
@if(Items != null) {
foreach (var item in Items) {
<option value="@Stringify(item)"/>
}
}
</datalist>

@code {
[Parameter] public IEnumerable<T> Items {get; set;}
[Parameter] public string Placeholder {get; set;}
private string selectedString;
public T Selected => Items == null ? default(T) : Items.Where(item => string.Equals(Stringify(item), selectedString, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

private string ComponentGuid;

[Parameter] public Func<T, string> Stringify {get; set;} = defaultStringify;

private static string defaultStringify(T value) {
return value?.ToString();
}

protected override void OnInitialized() {
base.OnInitialized();
ComponentGuid = System.Guid.NewGuid().ToString();
}

public void Deselect() {
selectedString = null;
StateHasChanged();
}
}
98 changes: 0 additions & 98 deletions TrekSharp.AdventureTools/Shared/TalentPicker.razor

This file was deleted.

25 changes: 25 additions & 0 deletions TrekSharp.AdventureTools/Shared/TalentSelect.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Select @ref=select Placeholder="Talent" Items=talents></Select>

@code {

private Select<CharacterTalent> select;

public CharacterTalent Talent => select?.Selected;

private List<CharacterTalent> talents;

[Parameter] public Character Character {get; set;}

protected override void OnInitialized() {
talents = new Data.RulebookContainer()
.AllRulebooks
.SelectMany(book => book.Value.Talents)
.Where(talent => Character == null || talent.CanBeUsedBy(Character))
.ToList();
}

public void Deselect() {
select?.Deselect();
}

}
42 changes: 42 additions & 0 deletions TrekSharp.AdventureTools/Shared/TalentSwap.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="row">
<div class="hbar elbow-left knee-left" style="width: 32px;"></div>
<span class="spacer typeface text-secondary w3-large">
DELETE
</span>
<div class="hbar row-fill elbow-right knee-right" style="margin-right: 10px;"></div>
</div>
<div class="w3-padding">
<Select @ref=toDelete Placeholder="Talent" Items=@Character.Talents></Select>
</div>

<div class="row">
<div class="hbar elbow-left knee-left" style="width: 32px;"></div>
<span class="spacer typeface text-secondary w3-large">
ADD
</span>
<div class="hbar row-fill elbow-right knee-right" style="margin-right: 10px;"></div>
</div>
<div class="w3-padding">
<TalentSelect @ref=toAdd Character=@Character></TalentSelect>
</div>

@code {
private Select<CharacterTalent> toDelete;
private TalentSelect toAdd;

[Parameter] public PlayableCharacter Character {get; set;}

public void Swap() {
var delete = toDelete.Selected;
var add = toAdd.Talent;
if (delete != null && add != null) {
Character.Talents.Remove(delete);
Character.Talents.Add(add);
}
}

public void Deselect() {
toDelete.Deselect();
toAdd.Deselect();
}
}
9 changes: 9 additions & 0 deletions TrekSharp/src/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ public Attributes () : this(0) {

}

public Attributes(Attributes other) {
this.Control = other.Control;
this.Daring = other.Daring;
this.Fitness = other.Daring;
this.Insight = other.Insight;
this.Presence = other.Presence;
this.Reason = other.Reason;
}

public Attributes (int values) {
this[0] = values;
this[1] = values;
Expand Down
Loading

0 comments on commit be79af6

Please sign in to comment.