mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
Replace Epoch1900DateTimeValue Duplicate Logic Instances (#4207)
* Replace LastSaved8a With Epoch1900DateTimeValue Since LastSaved8a basically implemented the same logic, replace it and update Epoch1900DateTimeValue.DisplayValue to not display seconds if they aren't present * Replace PlayTime8 With PlayTime7b
This commit is contained in:
parent
d86469266b
commit
78fba23eae
12 changed files with 19 additions and 138 deletions
|
@ -1,4 +1,4 @@
|
|||
namespace PKHeX.Core;
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for Accessing named blocks within a Generation 8 <see cref="GameVersion.PLA"/> save file.
|
||||
|
@ -12,6 +12,6 @@ public interface ISaveBlock8LA
|
|||
BoxLayout8a BoxLayout { get; }
|
||||
MyItem8a Items { get; }
|
||||
Epoch1970Value AdventureStart { get; }
|
||||
LastSaved8a LastSaved { get; }
|
||||
Epoch1900DateTimeValue LastSaved { get; }
|
||||
PlayTime8a Played { get; }
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public interface ISaveBlock8Main
|
|||
Misc8 Misc { get; }
|
||||
Zukan8 Zukan { get; }
|
||||
BoxLayout8 BoxLayout { get; }
|
||||
PlayTime8 Played { get; }
|
||||
PlayTime7b Played { get; }
|
||||
Fused8 Fused { get; }
|
||||
Daycare8 Daycare { get; }
|
||||
Record8 Records { get; }
|
||||
|
|
|
@ -15,7 +15,7 @@ public sealed class SaveBlockAccessor8LA(SAV8LA sav) : SCBlockAccessor, ISaveBlo
|
|||
public MyItem8a Items { get; } = new(sav, Block(sav, KItemRegular));
|
||||
public Epoch1970Value AdventureStart { get; } = new(Block(sav, KAdventureStart));
|
||||
public Coordinates8a Coordinates { get; } = new(sav, Block(sav, KCoordinates));
|
||||
public LastSaved8a LastSaved { get; } = new(sav, Block(sav, KLastSaved));
|
||||
public Epoch1900DateTimeValue LastSaved { get; } = new(Block(sav, KLastSaved));
|
||||
public PlayerFashion8a FashionPlayer { get; } = new(sav, Block(sav, KFashionPlayer));
|
||||
public PlayTime8a Played { get; } = new(sav, Block(sav, KPlayTime));
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public sealed class SaveBlockAccessor8SWSH(SAV8SWSH sav) : SCBlockAccessor, ISav
|
|||
public Misc8 Misc { get; } = new(sav, Block(sav, KMisc));
|
||||
public Zukan8 Zukan { get; } = new(sav, Block(sav, KZukan), BlockSafe(sav, KZukanR1), BlockSafe(sav, KZukanR2));
|
||||
public BoxLayout8 BoxLayout { get; } = new(sav, Block(sav, KBoxLayout));
|
||||
public PlayTime8 Played { get; } = new(sav, Block(sav, KPlayTime));
|
||||
public PlayTime7b Played { get; } = new(sav, Block(sav, KPlayTime));
|
||||
public Fused8 Fused { get; } = new(sav, Block(sav, KFused));
|
||||
public Daycare8 Daycare { get; } = new(sav, Block(sav, KDaycare));
|
||||
public Record8 Records { get; } = new(sav, Block(sav, KRecord));
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace PKHeX.Core;
|
|||
/// </summary>
|
||||
public sealed class SAV8LA : SaveFile, ISaveBlock8LA, ISCBlockArray, ISaveFileRevision, IBoxDetailName, IBoxDetailWallpaper
|
||||
{
|
||||
protected internal override string ShortSummary => $"{OT} ({Version}) - {LastSaved.LastSavedTime}";
|
||||
protected internal override string ShortSummary => $"{OT} ({Version}) - {LastSaved.DisplayValue}";
|
||||
public override string Extension => string.Empty;
|
||||
|
||||
public SAV8LA(byte[] data) : this(SwishCrypto.Decrypt(data)) { }
|
||||
|
@ -114,7 +114,7 @@ public sealed class SAV8LA : SaveFile, ISaveBlock8LA, ISCBlockArray, ISaveFileRe
|
|||
public MyItem8a Items => Blocks.Items;
|
||||
public Epoch1970Value AdventureStart => Blocks.AdventureStart;
|
||||
public Coordinates8a Coordinates => Blocks.Coordinates;
|
||||
public LastSaved8a LastSaved => Blocks.LastSaved;
|
||||
public Epoch1900DateTimeValue LastSaved => Blocks.LastSaved;
|
||||
public PlayTime8a Played => Blocks.Played;
|
||||
public AreaSpawnerSet8a AreaSpawners => new(Blocks.GetBlock(SaveBlockAccessor8LA.KSpawners));
|
||||
#endregion
|
||||
|
|
|
@ -70,7 +70,7 @@ public sealed class SAV8SWSH : SaveFile, ISaveBlock8SWSH, ITrainerStatRecord, IS
|
|||
public Misc8 Misc => Blocks.Misc;
|
||||
public Zukan8 Zukan => Blocks.Zukan;
|
||||
public BoxLayout8 BoxLayout => Blocks.BoxLayout;
|
||||
public PlayTime8 Played => Blocks.Played;
|
||||
public PlayTime7b Played => Blocks.Played;
|
||||
public Fused8 Fused => Blocks.Fused;
|
||||
public Daycare8 Daycare => Blocks.Daycare;
|
||||
public Record8 Records => Blocks.Records;
|
||||
|
|
|
@ -3,8 +3,11 @@ using static System.Buffers.Binary.BinaryPrimitives;
|
|||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayTime7b(SAV7b sav, Memory<byte> raw) : SaveBlock<SAV7b>(sav, raw)
|
||||
public sealed class PlayTime7b : SaveBlock<SaveFile>
|
||||
{
|
||||
public PlayTime7b(SAV7b sav, Memory<byte> raw) : base(sav, raw) { }
|
||||
public PlayTime7b(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) { }
|
||||
|
||||
public int PlayedHours
|
||||
{
|
||||
get => ReadUInt16LittleEndian(Data);
|
||||
|
@ -24,23 +27,19 @@ public sealed class PlayTime7b(SAV7b sav, Memory<byte> raw) : SaveBlock<SAV7b>(s
|
|||
}
|
||||
|
||||
private Epoch1900DateTimeValue LastSaved => new(Raw.Slice(0x4, 4));
|
||||
public string LastSavedTime => $"{LastSaved.Year:0000}-{LastSaved.Month:00}-{LastSaved.Day:00} {LastSaved.Hour:00}ː{LastSaved.Minute:00}"; // not :
|
||||
public string LastSavedTime => LastSaved.DisplayValue;
|
||||
|
||||
public DateTime? LastSavedDate
|
||||
{
|
||||
get => !DateUtil.IsDateValid(LastSaved.Year, LastSaved.Month, LastSaved.Day)
|
||||
? null
|
||||
: new DateTime(LastSaved.Year, LastSaved.Month, LastSaved.Day, LastSaved.Hour, LastSaved.Minute, 0);
|
||||
: LastSaved.Timestamp;
|
||||
set
|
||||
{
|
||||
// Only update the properties if a value is provided.
|
||||
if (value is { } dt)
|
||||
{
|
||||
LastSaved.Year = dt.Year;
|
||||
LastSaved.Month = dt.Month;
|
||||
LastSaved.Day = dt.Day;
|
||||
LastSaved.Hour = dt.Hour;
|
||||
LastSaved.Minute = dt.Minute;
|
||||
LastSaved.Timestamp = dt;
|
||||
}
|
||||
else // Clear the date.
|
||||
{
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using static System.Buffers.Binary.BinaryPrimitives;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the <see cref="LastSavedDate"/> of the player.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Year value is offset by -1900.
|
||||
/// Month value is offset by -1.
|
||||
/// </remarks>
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public sealed class LastSaved8a(SAV8LA sav, SCBlock block) : SaveBlock<SAV8LA>(sav, block.Data)
|
||||
{
|
||||
private uint LastSaved { get => ReadUInt32LittleEndian(Data); set => WriteUInt32LittleEndian(Data, value); }
|
||||
private int LastSavedYear { get => (int)(LastSaved & 0xFFF); set => LastSaved = (LastSaved & 0xFFFFF000) | (uint)value; }
|
||||
private int LastSavedMonth { get => (int)((LastSaved >> 12) & 0xF); set => LastSaved = (LastSaved & 0xFFFF0FFF) | (((uint)value & 0xF) << 12); }
|
||||
private int LastSavedDay { get => (int)((LastSaved >> 16) & 0x1F); set => LastSaved = (LastSaved & 0xFFE0FFFF) | (((uint)value & 0x1F) << 16); }
|
||||
private int LastSavedHour { get => (int)((LastSaved >> 21) & 0x1F); set => LastSaved = (LastSaved & 0xFC1FFFFF) | (((uint)value & 0x1F) << 21); }
|
||||
private int LastSavedMinute { get => (int)((LastSaved >> 26) & 0x3F); set => LastSaved = (LastSaved & 0x03FFFFFF) | (((uint)value & 0x3F) << 26); }
|
||||
public string LastSavedTime => $"{LastSavedYear+1900:0000}-{LastSavedMonth+1:00}-{LastSavedDay:00} {LastSavedHour:00}ː{LastSavedMinute:00}"; // not :
|
||||
|
||||
public DateTime? LastSavedDate
|
||||
{
|
||||
get => !DateUtil.IsDateValid(LastSavedYear + 1900, LastSavedMonth + 1, LastSavedDay)
|
||||
? null
|
||||
: new DateTime(LastSavedYear + 1900, LastSavedMonth + 1, LastSavedDay, LastSavedHour, LastSavedMinute, 0);
|
||||
set
|
||||
{
|
||||
// Only update the properties if a value is provided.
|
||||
if (value is { } dt)
|
||||
{
|
||||
LastSavedYear = dt.Year - 1900;
|
||||
LastSavedMonth = dt.Month - 1;
|
||||
LastSavedDay = dt.Day;
|
||||
LastSavedHour = dt.Hour;
|
||||
LastSavedMinute = dt.Minute;
|
||||
}
|
||||
else // Clear the date.
|
||||
{
|
||||
// If code tries to access MetDate again, null will be returned.
|
||||
LastSavedYear = 0;
|
||||
LastSavedMonth = 0;
|
||||
LastSavedDay = 0;
|
||||
LastSavedHour = 0;
|
||||
LastSavedMinute = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,5 +18,5 @@ public sealed class PlayTime8a(SAV8LA sav, SCBlock block) : SaveBlock<SAV8LA>(sa
|
|||
|
||||
public byte PlayedMinutes { get => Data[2]; set => Data[2] = value; }
|
||||
public byte PlayedSeconds { get => Data[3]; set => Data[3] = value; }
|
||||
public string LastSavedTime => $"{PlayedHours:0000}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
|
||||
public string PlayedTime => $"{PlayedHours:0000}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
using static System.Buffers.Binary.BinaryPrimitives;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayTime8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SWSH>(sav, block.Data)
|
||||
{
|
||||
public int PlayedHours
|
||||
{
|
||||
get => ReadUInt16LittleEndian(Data);
|
||||
set => WriteUInt16LittleEndian(Data, (ushort)value);
|
||||
}
|
||||
|
||||
public int PlayedMinutes
|
||||
{
|
||||
get => Data[2];
|
||||
set => Data[2] = (byte)value;
|
||||
}
|
||||
|
||||
public int PlayedSeconds
|
||||
{
|
||||
get => Data[3];
|
||||
set => Data[3] = (byte)value;
|
||||
}
|
||||
|
||||
private uint LastSaved { get => ReadUInt32LittleEndian(Data[0x4..]); set => WriteUInt32LittleEndian(Data[0x4..], value); }
|
||||
private int LastSavedYear { get => (int)(LastSaved & 0xFFF) + 1900; set => LastSaved = (LastSaved & 0xFFFFF000) | (uint)(value - 1900); }
|
||||
private int LastSavedMonth { get => (int)((LastSaved >> 12) & 0xF) + 1; set => LastSaved = (LastSaved & 0xFFFF0FFF) | (((uint)(value - 1) & 0xF) << 12); }
|
||||
private int LastSavedDay { get => (int)((LastSaved >> 16) & 0x1F); set => LastSaved = (LastSaved & 0xFFE0FFFF) | (((uint)value & 0x1F) << 16); }
|
||||
private int LastSavedHour { get => (int)((LastSaved >> 21) & 0x1F); set => LastSaved = (LastSaved & 0xFC1FFFFF) | (((uint)value & 0x1F) << 21); }
|
||||
private int LastSavedMinute { get => (int)((LastSaved >> 26) & 0x3F); set => LastSaved = (LastSaved & 0x03FFFFFF) | (((uint)value & 0x3F) << 26); }
|
||||
public string LastSavedTime => $"{LastSavedYear:0000}-{LastSavedMonth:00}-{LastSavedDay:00} {LastSavedHour:00}ː{LastSavedMinute:00}"; // not :
|
||||
|
||||
public DateTime? LastSavedDate
|
||||
{
|
||||
get => !DateUtil.IsDateValid(LastSavedYear, LastSavedMonth, LastSavedDay)
|
||||
? null
|
||||
: new DateTime(LastSavedYear, LastSavedMonth, LastSavedDay, LastSavedHour, LastSavedMinute, 0);
|
||||
set
|
||||
{
|
||||
// Only update the properties if a value is provided.
|
||||
if (value is { } dt)
|
||||
{
|
||||
LastSavedYear = dt.Year;
|
||||
LastSavedMonth = dt.Month;
|
||||
LastSavedDay = dt.Day;
|
||||
LastSavedHour = dt.Hour;
|
||||
LastSavedMinute = dt.Minute;
|
||||
}
|
||||
else // Clear the date.
|
||||
{
|
||||
// If code tries to access MetDate again, null will be returned.
|
||||
LastSavedYear = 0;
|
||||
LastSavedMonth = 0;
|
||||
LastSavedDay = 0;
|
||||
LastSavedHour = 0;
|
||||
LastSavedMinute = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public sealed class Epoch1900DateTimeValue(Memory<byte> Data)
|
|||
}
|
||||
}
|
||||
|
||||
public string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}ː{Timestamp.Second:00}"; // not :
|
||||
public string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}" + (HasSeconds ? $"ː{Timestamp.Second:00}" : ""); // not :
|
||||
|
||||
/// <summary>
|
||||
/// time_t (seconds since 1900 Epoch)
|
||||
|
|
|
@ -62,11 +62,7 @@ public partial class SAV_Trainer8a : Form
|
|||
MT_Minutes.Text = SAV.PlayedMinutes.ToString();
|
||||
MT_Seconds.Text = SAV.PlayedSeconds.ToString();
|
||||
|
||||
if (SAV.LastSaved.LastSavedDate is { } d)
|
||||
CAL_LastSavedDate.Value = CAL_LastSavedTime.Value = d;
|
||||
else
|
||||
CAL_LastSavedDate.Enabled = CAL_LastSavedTime.Enabled = false;
|
||||
|
||||
CAL_LastSavedDate.Value = CAL_LastSavedTime.Value = SAV.LastSaved.Timestamp;
|
||||
CAL_AdventureStartDate.Value = CAL_AdventureStartTime.Value = SAV.AdventureStart.Timestamp;
|
||||
|
||||
LoadClamp(NUD_MeritCurrent, SaveBlockAccessor8LA.KMeritCurrent);
|
||||
|
@ -115,8 +111,7 @@ public partial class SAV_Trainer8a : Form
|
|||
|
||||
var advDay = CAL_AdventureStartDate.Value.Date;
|
||||
SAV.AdventureStart.Timestamp = advDay.AddSeconds(CAL_AdventureStartTime.Value.TimeOfDay.TotalSeconds);
|
||||
if (CAL_LastSavedDate.Enabled)
|
||||
SAV.LastSaved.LastSavedDate = CAL_LastSavedDate.Value.Date.AddSeconds(CAL_LastSavedTime.Value.TimeOfDay.TotalSeconds);
|
||||
SAV.LastSaved.Timestamp = CAL_LastSavedDate.Value.Date.AddSeconds(CAL_LastSavedTime.Value.TimeOfDay.TotalSeconds);
|
||||
|
||||
SAV.Blocks.SetBlockValue(SaveBlockAccessor8LA.KMeritCurrent, (uint)NUD_MeritCurrent.Value);
|
||||
SAV.Blocks.SetBlockValue(SaveBlockAccessor8LA.KMeritEarnedTotal, (uint)NUD_MeritEarned.Value);
|
||||
|
|
Loading…
Reference in a new issue