105 lines
3.9 KiB
C#
105 lines
3.9 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>
|
|
/// .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);
|
|
|
|
return new ModPluginDefinition
|
|
{
|
|
Id = id,
|
|
Name = displayName,
|
|
Description = desc,
|
|
FileName = fileName,
|
|
FilePath = filePath
|
|
};
|
|
}
|
|
|
|
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" => "メッセージ瞬間表示 (ウェイトスキップ)",
|
|
_ => !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 => Definition.Id;
|
|
public string Name => Definition.Name;
|
|
public string Description => Definition.Description;
|
|
|
|
public bool IsEnabled
|
|
{
|
|
get => _isEnabled;
|
|
set
|
|
{
|
|
if (_isEnabled != value)
|
|
{
|
|
_isEnabled = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
protected void OnPropertyChanged([CallerMemberName] string? name = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
}
|
|
}
|