-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b447eb8
commit b014cb3
Showing
5 changed files
with
188 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@inherits BasePkmdsComponent | ||
|
||
@if (SaveFile is not null) | ||
{ | ||
<MudSelect Label="Record" | ||
@bind-Value="CurrentRecordIndex" | ||
@bind-Value:after="GetRecord" | ||
Variant="Variant.Filled"> | ||
@foreach (var (index, record) in RecordComboItems.Index()) | ||
{ | ||
var localIndex = index; | ||
<MudSelectItem Value="@localIndex" | ||
@key="@localIndex"> | ||
@record.Text | ||
</MudSelectItem> | ||
} | ||
</MudSelect> | ||
|
||
<MudNumericField Label="Record Value" | ||
Variant="@Variant.Outlined" | ||
Min="@uint.MinValue" | ||
Max="@uint.MaxValue" | ||
@bind-Value:get="@CurrentRecordValue" | ||
@bind-Value:set="@SetCurrentRecordValue" /> | ||
|
||
@if (HallOfFameIndexSelected) | ||
{ | ||
<div class="form-grid"> | ||
<div class="form-field"> | ||
<MudNumericField Label="Hours" | ||
T="@uint" | ||
Variant="@Variant.Outlined" | ||
Min="0" | ||
Max="9999" | ||
@bind-Value="@HallOfFameHours" | ||
@bind-Value:after="@ChangeFame" /> | ||
</div> | ||
<div class="form-field"> | ||
<MudNumericField Label="Minutes" | ||
T="@byte" | ||
Variant="@Variant.Outlined" | ||
Min="0" | ||
Max="59" | ||
@bind-Value="@HallOfFameMinutes" | ||
@bind-Value:after="@ChangeFame" /> | ||
</div> | ||
<div class="form-field"> | ||
<MudNumericField Label="Seconds" | ||
T="@byte" | ||
Variant="@Variant.Outlined" | ||
Min="0" | ||
Max="59" | ||
@bind-Value="@HallOfFameSeconds" | ||
@bind-Value:after="@ChangeFame" /> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
namespace Pkmds.Web.Components.MainTabPages; | ||
|
||
public partial class RecordsTab | ||
{ | ||
[Parameter, EditorRequired] | ||
public SAV3? SaveFile { get; set; } | ||
|
||
private int CurrentRecordIndex { get; set; } | ||
|
||
private uint? CurrentRecordValue { get; set; } | ||
|
||
private Record3? Records { get; set; } | ||
|
||
private IList<ComboItem> RecordComboItems { get; set; } = []; | ||
|
||
private uint HallOfFameHours { get; set; } | ||
|
||
private byte HallOfFameMinutes { get; set; } | ||
|
||
private byte HallOfFameSeconds { get; set; } | ||
|
||
private bool HallOfFameIndexSelected => CurrentRecordIndex switch | ||
{ | ||
(int)RecID3RuSa.FIRST_HOF_PLAY_TIME or (int)RecID3Emerald.FIRST_HOF_PLAY_TIME or (int)RecID3FRLG.FIRST_HOF_PLAY_TIME => true, | ||
_ => false, | ||
}; | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
base.OnParametersSet(); | ||
LoadRecords(); | ||
} | ||
|
||
private void LoadRecords() | ||
{ | ||
if (SaveFile is null) | ||
{ | ||
return; | ||
} | ||
|
||
Records = new Record3(SaveFile); | ||
RecordComboItems = Record3.GetItems(SaveFile); | ||
GetRecord(); | ||
} | ||
|
||
private void GetRecord() | ||
{ | ||
if (SaveFile is null || Records is null) | ||
{ | ||
return; | ||
} | ||
|
||
CurrentRecordValue = Records.GetRecord(CurrentRecordIndex); | ||
|
||
if (HallOfFameIndexSelected) | ||
{ | ||
SetFameTime(CurrentRecordValue ?? 0U); | ||
} | ||
} | ||
|
||
private void SetCurrentRecordValue(uint? newValue) | ||
{ | ||
if (SaveFile is null || Records is null) | ||
{ | ||
return; | ||
} | ||
|
||
CurrentRecordValue = newValue; | ||
Records.SetRecord(CurrentRecordIndex, newValue ?? 0U); | ||
|
||
if (HallOfFameIndexSelected) | ||
{ | ||
SetFameTime(newValue ?? 0U); | ||
} | ||
} | ||
|
||
void ChangeFame() | ||
{ | ||
if (!HallOfFameIndexSelected || Records is null) | ||
{ | ||
return; | ||
} | ||
|
||
Records.SetRecord(1, (uint)(CurrentRecordValue = GetFameTime())); | ||
} | ||
|
||
public uint GetFameTime() | ||
{ | ||
if (!HallOfFameIndexSelected || Records is null) | ||
{ | ||
return 0U; | ||
} | ||
|
||
var hrs = Math.Min(9999U, HallOfFameHours); | ||
var min = Math.Min((byte)59, HallOfFameMinutes); | ||
var sec = Math.Min((byte)59, HallOfFameSeconds); | ||
|
||
return (uint)((hrs << 16) | (min << 8) | sec); | ||
} | ||
|
||
public void SetFameTime(uint time) | ||
{ | ||
if (!HallOfFameIndexSelected || Records is null) | ||
{ | ||
return; | ||
} | ||
|
||
HallOfFameHours = Math.Min(9999U, time >> 16); | ||
HallOfFameMinutes = Math.Min((byte)59, (byte)(time >> 8)); | ||
HallOfFameSeconds = Math.Min((byte)59, (byte)time); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters