ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Data/KeyValueList.cs

55 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace TKS.OutGame
{
/// <summary>key,value 표(economy.csv · gacha.csv) 공용 — 값은 문자열로 두고 읽을 때 변환한다.</summary>
[Serializable]
public class KeyValueList
{
[Serializable]
public class Entry
{
public string key;
public string value;
}
public List<Entry> entries = new List<Entry>();
public bool Has(string key)
{
foreach (var e in entries)
if (e.key == key) return true;
return false;
}
public string S(string key)
{
foreach (var e in entries)
if (e.key == key) return e.value;
Debug.LogError("[TKS] 표에 키 없음: " + key + " (TKS/Import OutGame Data)");
return "";
}
public float F(string key)
{
float v;
return float.TryParse(S(key), NumberStyles.Float, CultureInfo.InvariantCulture, out v) ? v : 0f;
}
public int I(string key)
{
return Mathf.RoundToInt(F(key));
}
/// <summary>「a;b;c」 목록.</summary>
public string[] List(string key)
{
var s = S(key);
return s.Length == 0 ? new string[0] : s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
}
}