91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using UnityEngine;
|
|
|
|
namespace TKS.OutGame
|
|
{
|
|
/// <summary>
|
|
/// 화면 설정 표(키 · 값 · 같은 키 여러 줄 = 목록 · 값 안 | = 칸) — 투기장(ArenaLeague)과 같은 형식을 편성 · 영웅 정보 배경이 같이 쓴다(C45 · 좌표·색·그림 경로는 표에만).
|
|
/// </summary>
|
|
public class ScreenTable
|
|
{
|
|
readonly Dictionary<string, List<string>> kv = new Dictionary<string, List<string>>();
|
|
|
|
/// <summary>Resources 경로(확장자 없음)의 표를 읽는다 · 없으면 null.</summary>
|
|
public static ScreenTable Load(string path)
|
|
{
|
|
var rows = UiText.Rows(path);
|
|
if (rows == null) return null;
|
|
var t = new ScreenTable();
|
|
foreach (var r in rows)
|
|
{
|
|
string k, v;
|
|
if (!r.TryGetValue("s_key", out k) || string.IsNullOrEmpty(k)) continue;
|
|
r.TryGetValue("s_value", out v);
|
|
List<string> l;
|
|
if (!t.kv.TryGetValue(k, out l)) t.kv[k] = l = new List<string>();
|
|
l.Add(v ?? "");
|
|
}
|
|
return t;
|
|
}
|
|
|
|
public bool Has(string key)
|
|
{
|
|
return kv.ContainsKey(key);
|
|
}
|
|
|
|
public string S(string key, string def = "")
|
|
{
|
|
List<string> l;
|
|
return kv.TryGetValue(key, out l) && l.Count > 0 && l[0].Length > 0 ? l[0] : def;
|
|
}
|
|
|
|
public string[] L(string key)
|
|
{
|
|
return S(key).Split('|');
|
|
}
|
|
|
|
public List<string[]> All(string key)
|
|
{
|
|
var list = new List<string[]>();
|
|
List<string> l;
|
|
if (kv.TryGetValue(key, out l))
|
|
foreach (var v in l)
|
|
list.Add(v.Split('|'));
|
|
return list;
|
|
}
|
|
|
|
public static float F(string v, float def = 0f)
|
|
{
|
|
float f;
|
|
return v != null && float.TryParse(v.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out f) ? f : def;
|
|
}
|
|
|
|
public static float At(string[] a, int i, float def = 0f)
|
|
{
|
|
return a != null && i < a.Length && a[i].Trim().Length > 0 ? F(a[i], def) : def;
|
|
}
|
|
|
|
public static string Str(string[] a, int i)
|
|
{
|
|
return a != null && i < a.Length ? a[i].Trim() : "";
|
|
}
|
|
|
|
public static Color Col(string[] a, int i, Color def)
|
|
{
|
|
Color c;
|
|
return a != null && i < a.Length && ColorUtility.TryParseHtmlString(a[i].Trim(), out c) ? c : def;
|
|
}
|
|
|
|
public float Num(string key, float def = 0f)
|
|
{
|
|
return F(S(key), def);
|
|
}
|
|
|
|
public Color Color(string key, Color def)
|
|
{
|
|
return Col(L(key), 0, def);
|
|
}
|
|
}
|
|
}
|