diff --git a/MedusaPluginChargeMachine/ChargeMachineDbContext.cs b/MedusaPluginChargeMachine/ChargeMachineDbContext.cs index a580aaa..506eef7 100644 --- a/MedusaPluginChargeMachine/ChargeMachineDbContext.cs +++ b/MedusaPluginChargeMachine/ChargeMachineDbContext.cs @@ -7,4 +7,15 @@ public class ChargeMachineDbContext(DbContextOptions opt { public DbSet ChargeHistories { get; set; } public DbSet ArticleContents { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + // Store ArticleType enum as its member name string (e.g. "DOCMT_0001") so the + // value is human-readable in the DB and matches the wire protocol exactly. + modelBuilder.Entity() + .Property(a => a.ArticleType) + .HasConversion(); + } } diff --git a/MedusaPluginChargeMachine/ChargeMachinePlugin.cs b/MedusaPluginChargeMachine/ChargeMachinePlugin.cs index 9b8dd8e..a5edada 100644 --- a/MedusaPluginChargeMachine/ChargeMachinePlugin.cs +++ b/MedusaPluginChargeMachine/ChargeMachinePlugin.cs @@ -41,21 +41,29 @@ public class ChargeMachinePlugin : IMedusaPlugin if (await db.ArticleContents.AnyAsync()) return; + // Order matches the enum table in gamemode.dll (0x2C160-0x2C228). + // DOCMT_* = document text displayed on screen; URL_* = URLs/QR targets. + // _A/_B variants = primary/secondary display; only 0001-0004 have both; + // 0005-0008 exist only as _B (secondary). var defaults = new List { - new() { ArticleType = "DOCMT_0000", ArticleDoc = "" }, - new() { ArticleType = "DOCMT_0001", ArticleDoc = "PASELI Charge Machine" }, - new() { ArticleType = "DOCMT_0002", ArticleDoc = "" }, - new() { ArticleType = "DOCMT_0003", ArticleDoc = "" }, - new() { ArticleType = "URL_0001_A", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0001_B", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0002_A", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0002_B", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0003_A", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0003_B", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0004_A", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "URL_0041_B", ArticleDoc = "https://localhost:5173/" }, - new() { ArticleType = "PASELIUNIT", ArticleDoc = "P" }, + new() { ArticleType = ArticleType.DOCMT_0001, ArticleDoc = "PASELI Charge Machine" }, + new() { ArticleType = ArticleType.DOCMT_0002, ArticleDoc = "Top up your PASELI balance to play." }, + new() { ArticleType = ArticleType.DOCMT_0003, ArticleDoc = "Charges are non-refundable. Ensure your card is registered before charging." }, + new() { ArticleType = ArticleType.URL_0001_A, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0001_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0002_A, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0002_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0003_A, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0003_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0004_A, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0004_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.PASELIUNIT, ArticleDoc = "P" }, + new() { ArticleType = ArticleType.DOCMT_0004, ArticleDoc = "For support, contact your arcade operator." }, + new() { ArticleType = ArticleType.URL_0005_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0006_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0007_B, ArticleDoc = "https://localhost:5173/" }, + new() { ArticleType = ArticleType.URL_0008_B, ArticleDoc = "https://localhost:5173/" }, }; db.ArticleContents.AddRange(defaults); diff --git a/MedusaPluginChargeMachine/Entities/ArticleContent.cs b/MedusaPluginChargeMachine/Entities/ArticleContent.cs index 84c6210..0f33d66 100644 --- a/MedusaPluginChargeMachine/Entities/ArticleContent.cs +++ b/MedusaPluginChargeMachine/Entities/ArticleContent.cs @@ -5,6 +5,6 @@ namespace MedusaPluginChargeMachine.Entities; public class ArticleContent { [Key] - public required string ArticleType { get; set; } + public required ArticleType ArticleType { get; set; } public required string ArticleDoc { get; set; } } diff --git a/MedusaPluginChargeMachine/Entities/ArticleType.cs b/MedusaPluginChargeMachine/Entities/ArticleType.cs new file mode 100644 index 0000000..0631256 --- /dev/null +++ b/MedusaPluginChargeMachine/Entities/ArticleType.cs @@ -0,0 +1,29 @@ +namespace MedusaPluginChargeMachine.Entities; + +/// +/// All article type keys used by the LA9 charge machine firmware (gamemode.dll 0x2C160). +/// Member names are the exact strings stored in the DB and sent on the wire. +/// DOCMT_* = on-screen document text; URL_* = URL/QR targets; +/// 0001-0004 have both _A (primary) and _B (secondary) variants; +/// 0005-0008 only have a _B variant. +/// +public enum ArticleType +{ + DOCMT_0001, + DOCMT_0002, + DOCMT_0003, + URL_0001_A, + URL_0001_B, + URL_0002_A, + URL_0002_B, + URL_0003_A, + URL_0003_B, + URL_0004_A, + URL_0004_B, + PASELIUNIT, + DOCMT_0004, + URL_0005_B, + URL_0006_B, + URL_0007_B, + URL_0008_B, +} diff --git a/MedusaPluginChargeMachine/Handlers/LA9/GetConfigEaChargeHandler.cs b/MedusaPluginChargeMachine/Handlers/LA9/GetConfigEaChargeHandler.cs index 92982e0..212926f 100644 --- a/MedusaPluginChargeMachine/Handlers/LA9/GetConfigEaChargeHandler.cs +++ b/MedusaPluginChargeMachine/Handlers/LA9/GetConfigEaChargeHandler.cs @@ -21,7 +21,7 @@ public class GetConfigEaChargeHandler(ChargeMachineDbContext db) : Handler new EaChargeConfigChargeArticleItem { - ArticleType = new XrpcString(a.ArticleType), + ArticleType = new XrpcString(a.ArticleType.ToString()), ArticleDoc = new XrpcString(a.ArticleDoc) }) .ToList(); diff --git a/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.Designer.cs b/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.Designer.cs new file mode 100644 index 0000000..fcdd371 --- /dev/null +++ b/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.Designer.cs @@ -0,0 +1,63 @@ +// +using System; +using MedusaPluginChargeMachine; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace MedusaPluginChargeMachine.Migrations +{ + [DbContext(typeof(ChargeMachineDbContext))] + [Migration("20260810081653_ArticleTypeEnumConversion")] + partial class ArticleTypeEnumConversion + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.10"); + + modelBuilder.Entity("MedusaPluginChargeMachine.Entities.ArticleContent", b => + { + b.Property("ArticleType") + .HasColumnType("TEXT"); + + b.Property("ArticleDoc") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("ArticleType"); + + b.ToTable("ArticleContents"); + }); + + modelBuilder.Entity("MedusaPluginChargeMachine.Entities.ChargeHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CardId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ChargeAmount") + .HasColumnType("INTEGER"); + + b.Property("ChargeNum") + .HasColumnType("INTEGER"); + + b.Property("OrderDate") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("ChargeHistories"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.cs b/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.cs new file mode 100644 index 0000000..aeb6977 --- /dev/null +++ b/MedusaPluginChargeMachine/Migrations/20260810081653_ArticleTypeEnumConversion.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MedusaPluginChargeMachine.Migrations +{ + /// + public partial class ArticleTypeEnumConversion : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +}