NHSE/NHSE.Core/Structures/Misc/GSaveDate.cs
Kurt d22ac35f73 Add Museum Editor
game stores all donation types in the same array (chunked into date[], item[], playerID[]); no dedicated indexes for a donation, so no empty slots, and all donation types are intermixed (based on donation date)
2020-05-12 22:55:26 -07:00

32 lines
1.1 KiB
C#

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
#pragma warning disable CS8618, CA1815, CA1819, IDE1006
namespace NHSE.Core
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
[TypeConverter(typeof(ValueTypeTypeConverter))]
public struct GSaveDate
{
public const int SIZE = 4;
public override string ToString() => $"{Year:0000}-{Month:00}-{Day:00}";
public ushort Year { get; set; }
public byte Month { get; set; }
public byte Day { get; set; }
private GSaveDate(int year, int month, int day)
{
Year = (ushort) year;
Month = (byte) month;
Day = (byte) day;
}
public bool IsEmpty => Year == 0 && Month == 0 && Day == 0;
public static implicit operator GSaveDate(DateTime dt) => dt == DateTime.MinValue ? new GSaveDate() : new GSaveDate(dt.Year, dt.Month, dt.Day);
public static implicit operator DateTime(GSaveDate dt) => dt.IsEmpty ? DateTime.MinValue : new DateTime(dt.Year, dt.Month, dt.Day);
}
}