using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace GameLauncher.Models
{
///
/// セーブデータ内の1つのプロパティ(変数・項目)を表すGUI表示・編集モデル
///
public class SaveDataPropertyEntry : INotifyPropertyChanged
{
private string _key = string.Empty;
private string _category = string.Empty;
private string _type = string.Empty;
private string _editValue = string.Empty;
private bool _isModified;
private string _description = string.Empty;
private ValueKind _kind = ValueKind.Unknown;
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// 項目名(キー名、変数名)
public string Key
{
get => this._key;
set { if (this._key != value) { this._key = value; this.OnPropertyChanged(); } }
}
/// 分類・カテゴリ(セクション、オブジェクト名など)
public string Category
{
get => this._category;
set { if (this._category != value) { this._category = value; this.OnPropertyChanged(); } }
}
/// データ型(Int, Float, Bool, String など)
public string Type
{
get => this._type;
set { if (this._type != value) { this._type = value; this.OnPropertyChanged(); } }
}
/// GUI編集用の値文字列
public string EditValue
{
get => this._editValue;
set
{
if (this._editValue != value)
{
this._editValue = value;
this._isModified = true;
this.OnPropertyChanged();
this.OnPropertyChanged(nameof(this.IsModified));
}
}
}
/// 値がユーザーによって変更されたかどうか
public bool IsModified
{
get => this._isModified;
set { if (this._isModified != value) { this._isModified = value; this.OnPropertyChanged(); } }
}
/// 備考・説明・オフセット位置など
public string Description
{
get => this._description;
set { if (this._description != value) { this._description = value; this.OnPropertyChanged(); } }
}
/// 内部保持用の生データや元データ(再エンコード用)
public object? RawData { get; set; }
///
/// 真偽値として編集できる項目かどうか。
///
public bool IsBool => this._kind == ValueKind.Boolean;
///
/// 数値(整数・小数)として編集できる項目かどうか。
///
public bool IsNumeric => this._kind is ValueKind.Integer or ValueKind.Float or ValueKind.Enum;
///
/// 文字列などテキスト入力で編集する項目かどうか。
///
public bool IsStringLike => !this.IsBool && !this.IsNumeric;
///
/// 真偽値エディタ(チェックボックス)用の値。
/// 設定すると も "true"/"false" に同期します。
///
public bool BoolValue
{
get => bool.TryParse(this._editValue, out var parsed) && parsed;
set => this.EditValue = value ? "true" : "false";
}
///
/// 値の種別。設定すると型別エディタの表示切り替えに反映されます。
///
public ValueKind Kind
{
get => this._kind;
set
{
if (this._kind != value)
{
this._kind = value;
this.OnPropertyChanged();
this.OnPropertyChanged(nameof(this.IsBool));
this.OnPropertyChanged(nameof(this.IsNumeric));
this.OnPropertyChanged(nameof(this.IsStringLike));
}
}
}
///
/// 値の種別(型別エディタの切り替え用)。
///
public enum ValueKind
{
/// 不明・未判定。
Unknown,
/// 真偽値。
Boolean,
/// 整数。
Integer,
/// 浮動小数。
Float,
/// 文字列。
String,
/// 列挙体。
Enum,
/// 配列・辞書・オブジェクトなど複合型。
Complex
}
}
}