Skip to content

Commit

Permalink
Multiple logs for the same date are allowed; promotion editor; minor …
Browse files Browse the repository at this point in the history
…layout changes
  • Loading branch information
qkmaxware committed May 3, 2021
1 parent 1d72c51 commit 38f5157
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 130 deletions.
36 changes: 29 additions & 7 deletions TrekSharp.AdventureTools/Data/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,44 @@
namespace TrekSharp.AdventureTools {

public class Logbook : IEnumerable<LogEntry> {
public SortedList<double, LogEntry> Entries {get; set;}
public LogEntry Earliest => Entries?.Min().Value;
public LogEntry Latest => Entries?.Max().Value;
public SortedList<double, List<LogEntry>> Entries {get; set;}
public LogEntry Earliest => Entries?.Min().Value.FirstOrDefault();
public LogEntry Latest {
get {
var last_set = Entries?.Max().Value;
if (last_set.Count < 1)
return null;
var last_value = last_set[last_set.Count - 1];
return last_value;
}
}
public int Count => Entries?.Count ?? 0;
public Logbook() {
this.Entries = new SortedList<double, LogEntry>();
this.Entries = new SortedList<double, List<LogEntry>>();
}
public void Record(LogEntry entry) {
this.Entries.Add(entry.Stardate, entry);
if (Entries.ContainsKey(entry.Stardate)) {
this.Entries[entry.Stardate].Add(entry);
} else {
this.Entries.Add(entry.Stardate, new List<LogEntry> { entry });
}
}
public void Delete(LogEntry entry) {
this.Entries.Remove(entry.Stardate);
if (this.Entries.ContainsKey(entry.Stardate)) {
var list = this.Entries[entry.Stardate];
list.Remove(entry);
if (list.Count < 1) {
this.Entries.Remove(entry.Stardate);
}
}
}

public IEnumerator<LogEntry> GetEnumerator() {
return this.Entries?.Values?.GetEnumerator();
foreach (var log_set in this.Entries) {
foreach (var entry in log_set.Value) {
yield return entry;
}
}
}

IEnumerator IEnumerable.GetEnumerator() {
Expand Down
9 changes: 9 additions & 0 deletions TrekSharp.AdventureTools/Pages/ViewCharacterSheet.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<div class="w3-half w3-left-align">
&nbsp;
<button @onclick=AddMilestone>+ Milestone</button>
<button @onclick=Promote>+ Promotion</button>
</div>
<div class="w3-half w3-right-align">
<button @onclick="Export">Export Json</button>
Expand Down Expand Up @@ -114,6 +115,7 @@
}

<MilestoneEditor @ref=milestones OnSave=@(() => StateHasChanged())></MilestoneEditor>
<PromotionEditor @ref=promotions OnSave=@(() => StateHasChanged())></PromotionEditor>

<ConfirmationDialog @ref="confirm">
</ConfirmationDialog>
Expand Down Expand Up @@ -164,4 +166,11 @@
milestones.Open(this.Player);
}

private PromotionEditor promotions;
private void Promote() {
if (HasCharacter) {
promotions.Open(this.Player);
}
}

}
4 changes: 2 additions & 2 deletions TrekSharp.AdventureTools/Shared/AssetAddList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
</div>

<div class="w3-row">
<div class="w3-half">
<div class="w3-col s6">
<button class="w3-button" @onclick="Close"> Cancel</button>
</div>
<div class="w3-half w3-right-align">
<div class="w3-col s6 w3-right-align">
<button class="w3-button" @onclick="add"> Add</button>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions TrekSharp.AdventureTools/Shared/AssetImporter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

<LocalFileInput Accept=".json" OnFileLoad=@((txt) => { jsonData = txt; InvokeAsync(StateHasChanged); })></LocalFileInput>

<textarea style="width: 100%; height: 480px; max-height: 80%; resize: vertical;" @bind="jsonData"></textarea>
<textarea style="width: 100%; height: 480px; max-height: 50vh; resize: vertical;" @bind="jsonData"></textarea>
@if (loadError != null) {
<div class="w3-panel w3-red">
<p>@loadError.Message</p>
</div>
}
<div class="w3-row">
<div class="w3-half">
<div class="w3-col s6">
<button class="w3-button" @onclick="Close"> Cancel</button>
</div>
<div class="w3-half w3-right-align">
<div class="w3-col s6 w3-right-align">
<button class="w3-button" @onclick="Load"> Load</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions TrekSharp.AdventureTools/Shared/ConfirmationDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
@question
</div>
<div class="w3-row">
<div class="w3-half w3-left-align">
<div class="w3-col s6 w3-left-align">
<button class="w3-red" @onclick=@(() => Cancel())>Cancel</button>
</div>
<div class="w3-half w3-right-align">
<div class="w3-col s6 w3-right-align">
<button class="w3-green" @onclick=@(() => Confirm())>Confirm</button>
</div>
</div>
Expand Down
216 changes: 105 additions & 111 deletions TrekSharp.AdventureTools/Shared/MilestoneEditor.razor
Original file line number Diff line number Diff line change
@@ -1,130 +1,124 @@
<div class="no-print w3-modal no-print @(CssClass)">
<div class="w3-modal-content">
<div class="lcars w3-container w3-padding elbow-left elbow-right knee-left knee-right w3-black lcars-border-primary">
@if (mode == ModeState.None) {
<div class="w3-center typeface">
<p class="w3-large">
Milestones describe events in which a character has grown. There are 3 types of milestones. Select the milestone appropriate to this character's growth.
<Popup @ref=popup>
@if (mode == ModeState.None) {
<div class="w3-center typeface">
<p class="w3-large">
Milestones describe events in which a character has grown. There are 3 types of milestones. Select the milestone appropriate to this character's growth.
</p>
<hr>
<div class="w3-padding">
<p>
Awarded to a character who has challenged a value, been injured by a lethal attack, or has used on value positively or negatively
</p>
<hr>
<div class="w3-padding">
<p>
Awarded to a character who has challenged a value, been injured by a lethal attack, or has used on value positively or negatively
</p>
<button @onclick=@(() => mode = ModeState.Normal)>
Normal Milestone
</button>
</div>
<div class="w3-padding">
<p>
Awarded to a character that has significant impact to a mission or has reached a key level of character development.
</p>
<button @onclick=@(() => mode = ModeState.Spotlight)>
Spotlight Milestone
</button>
</div>
<div class="w3-padding">
<p>
Awarded to a character when they reach a significant point in a story arc.
</p>
<button @onclick=@(() => mode = ModeState.Arc)>
Arc Milestone
</button>
</div>
<button @onclick=@(() => mode = ModeState.Normal)>
Normal Milestone
</button>
</div>
<div class="w3-padding">
<p>
Awarded to a character that has significant impact to a mission or has reached a key level of character development.
</p>
<button @onclick=@(() => mode = ModeState.Spotlight)>
Spotlight Milestone
</button>
</div>
<div class="w3-padding">
<p>
Awarded to a character when they reach a significant point in a story arc.
</p>
<button @onclick=@(() => mode = ModeState.Arc)>
Arc Milestone
</button>
</div>
<button class="w3-red" @onclick=@(() => Close())>
Cancel
</button>
} else {
if (mode == ModeState.Normal) {
</div>
<button class="w3-red" @onclick=@(() => Close())>
Cancel
</button>
} else {
if (mode == ModeState.Normal) {
<TabLayout>
<TabPage Title="Redistribute Disciplines">
<DisciplineRedistribute
MaxChanges=1
MaxValue=5
MinValue=1
ToBalance="Character.Disciplines"
Reference="normalDisciplineDelta"
/>
</TabPage>
<TabPage Title="Change Value">
<StringEditor Items=Character.Values></StringEditor>
</TabPage>
<TabPage Title="Change Focus">
<StringEditor Items=Character.Focuses></StringEditor>
</TabPage>
</TabLayout>
} else if (mode == ModeState.Spotlight) {
<TabLayout>
<TabPage Title="Redistribute Disciplines">
<DisciplineRedistribute
<TabPage Title="Redistribute Attributes">
<AttributeRedistribute
MaxChanges=1
MaxValue=5
MinValue=1
ToBalance="Character.Disciplines"
Reference="normalDisciplineDelta"
MaxValue=11
MinValue=7
ToBalance="Character.Attributes"
Reference="spotlightAttributeDelta"
/>
</TabPage>
<TabPage Title="Change Value">
<StringEditor Items=Character.Values></StringEditor>
<TabPage Title="Change Talent">
<TalentPicker @ref=spotlightTalentSwap RequireDelete=true GetPlayer=@(() => this.Character)></TalentPicker>
</TabPage>
<TabPage Title="Change Focus">
<StringEditor Items=Character.Focuses></StringEditor>
</TabLayout>
} else if (mode == ModeState.Arc) {
<TabLayout>
<TabPage Title="Increment Attribute">
<AttributeIncrement
Points=1
MaxPointsPerItem=12
Mask=allAttributeMask
Reference=arcAttributeDelta
/>
</TabPage>
<TabPage Title="Increment Discipline">
<DisciplineIncrement
Points=1
MaxPointsPerItem=5
Mask=allDisciplineMask
Reference=arcDisciplineDelta
/>
</TabPage>
<TabPage Title="Add Talent">
<TalentPicker @ref=arcNewTalent GetPlayer=@(() => this.Character)></TalentPicker>
</TabPage>
<TabPage Title="Add Focus">
<input class="w3-input" placeholder="New Focus" @bind=arcNewFocus />
</TabPage>
<TabPage Title="Add Value">
<input class="w3-input" placeholder="New Value" @bind=arcNewValue />
</TabPage>
</TabLayout>
} else if (mode == ModeState.Spotlight) {
<TabLayout>
<TabPage Title="Redistribute Attributes">
<AttributeRedistribute
MaxChanges=1
MaxValue=11
MinValue=7
ToBalance="Character.Attributes"
Reference="spotlightAttributeDelta"
/>
</TabPage>
<TabPage Title="Change Talent">
<TalentPicker @ref=spotlightTalentSwap RequireDelete=true GetPlayer=@(() => this.Character)></TalentPicker>
</TabPage>
</TabLayout>
} else if (mode == ModeState.Arc) {
<TabLayout>
<TabPage Title="Increment Attribute">
<AttributeIncrement
Points=1
MaxPointsPerItem=12
Mask=allAttributeMask
Reference=arcAttributeDelta
/>
</TabPage>
<TabPage Title="Increment Discipline">
<DisciplineIncrement
Points=1
MaxPointsPerItem=5
Mask=allDisciplineMask
Reference=arcDisciplineDelta
/>
</TabPage>
<TabPage Title="Add Talent">
<TalentPicker @ref=arcNewTalent GetPlayer=@(() => this.Character)></TalentPicker>
</TabPage>
<TabPage Title="Add Focus">
<input class="w3-input" placeholder="New Focus" @bind=arcNewFocus />
</TabPage>
<TabPage Title="Add Value">
<input class="w3-input" placeholder="New Value" @bind=arcNewValue />
</TabPage>
</TabLayout>
}
<div class="w3-row">
<div class="w3-half w3-left-align">
<button class="w3-red" @onclick=@(() => Close())>
Cancel
</button>
</div>
<div class="w3-half w3-right-align">
<button class="w3-green" @onclick=@(() => Save())>
Confirm
</button>
</div>
</div>
}

</div>
</div>
</div>
<div class="w3-row">
<div class="w3-col s6 w3-left-align">
<button class="w3-red" @onclick=@(() => Close())>
Cancel
</button>
</div>
<div class="w3-col s6 w3-right-align">
<button class="w3-green" @onclick=@(() => Save())>
Confirm
</button>
</div>
</div>
}
</Popup>

@code {
private bool isOpen = false;
private string CssClass => isOpen ? "w3-show" : "w3-hide";
private Popup popup;

private PlayerCharacter Character;
[Parameter] public Action OnSave {get; set;}

public void Open(PlayerCharacter character) {
isOpen = true;
popup.Open();
this.Character = character;
normalDisciplineDelta = new Disciplines(0);

Expand All @@ -144,7 +138,7 @@
}

public void Close() {
isOpen = false;
popup.Close();
mode = ModeState.None;
StateHasChanged();
}
Expand Down
Loading

0 comments on commit 38f5157

Please sign in to comment.