mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Donut9a: guard against bad donuts
moldy donuts yuck
This commit is contained in:
parent
47cd845d05
commit
29d364067a
|
|
@ -117,9 +117,9 @@ public void LoadDonut(Donut9a donut)
|
|||
{
|
||||
_donut = donut;
|
||||
|
||||
NUD_Stars.Value = donut.Stars;
|
||||
NUD_Calories.Value = donut.Calories;
|
||||
NUD_LevelBoost.Value = donut.LevelBoost;
|
||||
LoadClamp(NUD_Stars, donut.Stars);
|
||||
LoadClamp(NUD_Calories, donut.Calories);
|
||||
LoadClamp(NUD_LevelBoost, donut.LevelBoost);
|
||||
|
||||
CB_Donut.SelectedValue = (int)donut.Donut;
|
||||
|
||||
|
|
@ -142,9 +142,20 @@ public void LoadDonut(Donut9a donut)
|
|||
dt = Epoch;
|
||||
else
|
||||
dt = donut.DateTime1900.Timestamp;
|
||||
CAL_Date.Value = dt;
|
||||
try
|
||||
{
|
||||
CAL_Date.Value = dt;
|
||||
}
|
||||
catch
|
||||
{
|
||||
CAL_Date.Value = Epoch;
|
||||
}
|
||||
|
||||
TB_Unknown.Text = donut.Unknown.ToString();
|
||||
|
||||
return;
|
||||
|
||||
static void LoadClamp(NumericUpDown nud, decimal value) => nud.Value = Math.Clamp(value, nud.Minimum, nud.Maximum);
|
||||
}
|
||||
|
||||
public void SaveDonut()
|
||||
|
|
@ -175,10 +186,21 @@ public void SaveDonut()
|
|||
var dt = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
|
||||
|
||||
// if date is sufficiently equal to the Epoch (zero), set to zero. Can't set a date of 1900/00/00 via the controls...
|
||||
if (dt is { Year: 1900, Month: 1, Day: 1 } and { Day: 1, Hour: 0, Minute: 0, Second: 0 })
|
||||
if (dt is { Year: 1900, Month: <= 1, Day: <= 1 } and { Day: 1, Hour: 0, Minute: 0, Second: 0 })
|
||||
{
|
||||
donut.ClearDateTime();
|
||||
}
|
||||
else
|
||||
donut.DateTime1900.Timestamp = dt;
|
||||
{
|
||||
try
|
||||
{
|
||||
donut.DateTime1900.Timestamp = dt;
|
||||
}
|
||||
catch
|
||||
{
|
||||
donut.ClearDateTime();
|
||||
}
|
||||
}
|
||||
donut.Unknown = ulong.TryParse(TB_Unknown.Text, out var unk) ? unk : 0;
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +217,7 @@ private static void LoadDonutFlavorHash(ComboBox cb, ulong flavorHash)
|
|||
|
||||
private static ulong GetDonutFlavorHash(ComboBox cb)
|
||||
{
|
||||
if (cb.SelectedIndex == 0)
|
||||
if (cb.SelectedIndex <= 0)
|
||||
return 0; // No flavor
|
||||
|
||||
// Grab the internal value (not the localized display value)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user