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

136 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace TKS.OutGame
{
/// <summary>
/// 외형(코스튬) 표 4장(2026-11-20 개발요청_코스튬 §1 · 기획 tables/ 사본) — costume_slots(부위 4 · 그리는 순서 · 기준점 · 외형 = 추후) · costume_items(꾸미기 9) ·
/// costume_config · costume_anchors(유닛별 기준점 · 그림 비율 · 왼쪽 위 0) + 유닛 그림 알파 경계(frames · 임포트가 PNG 에서 계산 · 프레임 윗선 이동 · 자동 기준점).
/// 임포트 = TKS/Import Costume → Resources/OutGame/CostumeDb.asset · 값은 전부 표(C45).
/// </summary>
public class CostumeDb : ScriptableObject
{
[Serializable]
public class Slot
{
public string slot = "";
public int order;
public string nameKo = "";
public int layer;
public string anchor = "";
public bool open;
}
[Serializable]
public class Item
{
public string id = "";
public string slot = "";
public string nameKo = "";
public string rarity = "";
public string source = "";
public string sourceKo = "";
public string art = "";
}
[Serializable]
public class Anchor
{
public string unit = "";
public string anchor = "";
public float x;
public float y;
public float scale = 1f;
public float rot;
}
/// <summary>유닛 그림 한 프레임의 알파 경계(px · 왼쪽 위 0 · 프레임 크기 w × h).</summary>
[Serializable]
public class Frame
{
public string art = "";
public string clip = "";
public int index;
public int w;
public int h;
public int left;
public int top;
public int right;
public int bottom;
}
[Serializable]
public class KV
{
public string key = "";
public string value = "";
}
public List<Slot> slots = new List<Slot>();
public List<Item> items = new List<Item>();
public List<Anchor> anchors = new List<Anchor>();
public List<KV> config = new List<KV>();
public List<Frame> frames = new List<Frame>();
Dictionary<string, Frame> frameIndex;
public string Cfg(string key)
{
foreach (var c in config)
if (c.key == key) return c.value;
return "";
}
public Slot SlotOf(string s)
{
foreach (var x in slots)
if (x.slot == s) return x;
return null;
}
public Item ItemOf(string id)
{
foreach (var x in items)
if (x.id == id) return x;
return null;
}
public Anchor AnchorOf(string unit, string anchor)
{
foreach (var a in anchors)
if (a.unit == unit && a.anchor == anchor) return a;
return null;
}
public Frame FrameOf(string art, string clip, int index)
{
if (frameIndex == null || frameIndex.Count != frames.Count)
{
frameIndex = new Dictionary<string, Frame>();
foreach (var f in frames) frameIndex[f.art + "/" + f.clip + "/" + f.index] = f;
}
Frame r;
return frameIndex.TryGetValue(art + "/" + clip + "/" + index, out r) ? r : null;
}
/// <summary>costume_config rarity_color(Normal:white;…) → 등급 키(gear_grades · ui_theme gear_*).</summary>
public string RarityGrade(string rarity)
{
foreach (var p in Cfg("rarity_color").Split(';'))
{
var kv = p.Split(':');
if (kv.Length == 2 && kv[0] == rarity) return kv[1];
}
return "white";
}
public static float F(string s)
{
float v;
return float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out v) ? v : 0f;
}
}
}