using System; using System.ComponentModel; using System.IO; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; namespace GameLauncher.Models { /// /// 動的プラグインの定義情報 /// public class ModPluginDefinition { public string Id { get; set; } = string.Empty; // プラグイン識別名 (例: "BattleSpeedUp") public string Name { get; set; } = string.Empty; // 表示名 public string Description { get; set; } = string.Empty; // 説明文 public string FileName { get; set; } = string.Empty; // ファイル名 (例: "BattleSpeedUp.js") public string FilePath { get; set; } = string.Empty; // フルパス /// 特定ゲーム専用プラグインかどうか public bool IsGameSpecific { get; set; } /// 対象ゲーム識別子 (例: "PrincessSynergy") public string TargetGameKey { get; set; } = string.Empty; /// 表示用グループ名 public string GroupName { get; set; } = "共通機能"; /// 初期チェックの既定値 (未設定時の初期値) public bool DefaultEnabled { get; set; } = true; /// /// .js ファイルから定義情報を解析・生成します。 /// public static ModPluginDefinition FromFile(string filePath) { var fileName = Path.GetFileName(filePath); var id = Path.GetFileNameWithoutExtension(filePath); string desc = string.Empty; try { string text = File.ReadAllText(filePath); var match = Regex.Match(text, @"@plugindesc\s+(.*)"); if (match.Success) { desc = match.Groups[1].Value.Trim(); } } catch { } string displayName = GetFriendlyName(id, desc); bool isSpecific = id is "AlwaysMaxHp" or "AlwaysMaxMp"; string targetKey = isSpecific ? "PrincessSynergy" : string.Empty; string groupName = isSpecific ? "固有ゲーム専用プラグイン" : "共通プラグイン"; bool defEnabled = id switch { "ShopMaxBuy" => false, "AlwaysMaxHp" => false, "AlwaysMaxMp" => false, _ => true }; return new ModPluginDefinition { Id = id, Name = displayName, Description = desc, FileName = fileName, FilePath = filePath, IsGameSpecific = isSpecific, TargetGameKey = targetKey, GroupName = groupName, DefaultEnabled = defEnabled }; } private static string GetFriendlyName(string id, string desc) { return id switch { "BattleSpeedUp" => "戦闘高速化 (ウェイト削除・アニメ早送り)", "DashSpeedUp" => "ダッシュ高速化 (移動速度+2)", "ItemNoConsume" => "アイテム消費無効 (何度でも使用可能)", "ShopMaxBuy" => "ショップ初期個数最大 (購入初期値をMAXに)", "ItemGainMax" => "アイテム入手時MAX (所持数最大99個)", "BattleTurnRecoverHp" => "ターン開始時HP全回復 (味方HP全快)", "BattleTurnRecoverMp" => "ターン開始時MP全回復 (味方MP全快)", "BattleTurnRecoverTp" => "ターン開始時TP全回復 (味方TP全快)", "BattleTurnRecover" => "ターン開始時全回復 (HP/MP/TP全快)", "GoldGainMax" => "所持金増減時MAX (9999999G)", "ExpGainMax" => "経験値獲得時MAX (一気にLv99)", "MessageInstant" => "メッセージ瞬間表示 (ウェイトスキップ)", "AlwaysMaxHp" => "HP常時MAX (プリンセスシナジー専用)", "AlwaysMaxMp" => "MP常時MAX (プリンセスシナジー専用)", _ => !string.IsNullOrEmpty(desc) ? $"{id} ({desc})" : id }; } } /// /// ゲームごとのプラグイン有効/無効設定アイテム(UIバインド用) /// public class ModPluginOptionItem : INotifyPropertyChanged { private bool _isEnabled = true; public ModPluginDefinition Definition { get; set; } = null!; public string Id => this.Definition.Id; public string Name => this.Definition.Name; public string Description => this.Definition.Description; public string GroupName => this.Definition.GroupName; public bool IsGameSpecific => this.Definition.IsGameSpecific; public bool IsEnabled { get => this._isEnabled; set { if (this._isEnabled != value) { this._isEnabled = value; this.OnPropertyChanged(); } } } public event PropertyChangedEventHandler? PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string? name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } } }