Files
GameLauncher/Models/ModPluginDefinition.cs
T
armonica ae86b53147 スタイル: コーディング規約に準拠したコードフォーマットの適用(this.の明示、空白スタイルの統一)
- 自インスタンスメンバーアクセスへの this. 付与(28ファイル)
- .editorconfig に準拠したインデント・波括弧・空白スタイルの適用
- UTF-8 (BOMあり)、CRLF改行コード、行末空白除去の整合性検証
2026-10-20 10:14:26 +09:00

135 lines
5.4 KiB
C#

using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
namespace GameLauncher.Models
{
/// <summary>
/// 動的プラグインの定義情報
/// </summary>
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; // フルパス
/// <summary>特定ゲーム専用プラグインかどうか</summary>
public bool IsGameSpecific { get; set; }
/// <summary>対象ゲーム識別子 (例: "PrincessSynergy")</summary>
public string TargetGameKey { get; set; } = string.Empty;
/// <summary>表示用グループ名</summary>
public string GroupName { get; set; } = "共通機能";
/// <summary>初期チェックの既定値 (未設定時の初期値)</summary>
public bool DefaultEnabled { get; set; } = true;
/// <summary>
/// .js ファイルから定義情報を解析・生成します。
/// </summary>
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
};
}
}
/// <summary>
/// ゲームごとのプラグイン有効/無効設定アイテム(UIバインド用)
/// </summary>
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));
}
}
}