Skip to content

Commit

Permalink
Add Gen IV hall of fame date
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Nov 25, 2024
1 parent 292232b commit b428104
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,24 @@
<MudTimePicker Label="Time Started"
@bind-Time="@GameStartedTime"
@bind-Time:after="@UpdateGameStarted"
TimeFormat="hh:mm:ss"
TimeFormat="HH:mm:ss"
Variant="@Variant.Outlined"
PickerVariant="@PickerVariant.Inline" />
</div>

<div class="form-field">
<MudDatePicker Label="Hall of Fame Day"
@bind-Date="@HallOfFameDate"
@bind-Date:after="@UpdateHallOfFame"
Variant="@Variant.Outlined"
PickerVariant="@PickerVariant.Inline" />
</div>

<div class="form-field">
<MudTimePicker Label="Hall of Fame Time"
@bind-Time="@HallOfFameTime"
@bind-Time:after="@UpdateHallOfFame"
TimeFormat="HH:mm:ss"
Variant="@Variant.Outlined"
PickerVariant="@PickerVariant.Inline" />
</div>
Expand Down
45 changes: 45 additions & 0 deletions Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ public void Dispose() =>

private TimeSpan? GameStartedTime { get; set; }

private DateTime? HallOfFameDate { get; set; }

private TimeSpan? HallOfFameTime { get; set; }

protected override void OnParametersSet()
{
base.OnParametersSet();
(GameStartedDate, GameStartedTime) = GetGameStarted();
(HallOfFameDate, HallOfFameTime) = GetHallOfFame();
}

private void OnGenderToggle(Gender newGender)
Expand Down Expand Up @@ -117,4 +122,44 @@ private void UpdateGameStarted()
break;
};
}

private (DateTime? Date, TimeSpan? Time) GetHallOfFame()
{
if (AppState.SaveFile is not { } saveFile)
{
return (null, null);
}

DateTime date;
DateTime time;

switch (saveFile)
{
case SAV4 sav:
DateUtil.GetDateTime2000(sav.SecondsToFame, out date, out time);
break;
default:
return (null, null);
};

return (date, time.TimeOfDay);
}

private void UpdateHallOfFame()
{
if (AppState.SaveFile is not { } saveFile || HallOfFameDate is null || HallOfFameTime is null)
{
return;
}

var date = HallOfFameDate.Value;
var time = HallOfFameTime.Value;

switch (saveFile)
{
case SAV4 sav:
sav.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds));
break;
};
}
}

0 comments on commit b428104

Please sign in to comment.