2using System.Collections.Generic;
5using System.Text.RegularExpressions;
10 public static Dictionary<string, SpriteReplacer>
dictSkins =
new Dictionary<string, SpriteReplacer>();
12 public static Dictionary<string, SpriteReplacer>
dictOverrides =
new Dictionary<string, SpriteReplacer>();
14 public static List<(
string suffix, Func<Card, bool> when)>
states =
new List<(
string, Func<Card, bool>)>();
16 public static Dictionary<string, string>
dictModItems =
new Dictionary<string, string>();
22 private static Dictionary<(int, int, bool, string), List<string>>
suffixKeys =
new Dictionary<(
int,
int,
bool,
string), List<string>>();
24 private static HashSet<string>
failedStates =
new HashSet<string>();
28 public Dictionary<string, SpriteData>
suffixes =
new Dictionary<string, SpriteData>();
30 public Dictionary<string, bool>
isChecked =
new Dictionary<string, bool>();
32 public static Dictionary<string, SpriteReplacer>
ListSkins()
34 List<string> list =
new List<string>();
35 foreach (KeyValuePair<string, SpriteReplacer> dictSkin
in dictSkins)
37 if (!File.Exists(dictSkin.Value.data.path +
".png"))
39 list.Add(dictSkin.Key);
42 foreach (
string item in list)
47 List<string> sortedIds = dictionary.Keys.OrderBy((
string k) => k).ToList();
48 foreach (KeyValuePair<string, string> item2
in dictionary)
50 item2.Deconstruct(out var key, out var value);
61 if (spriteReplacer.
suffixes.TryGetValue(
"", out var value2))
63 spriteReplacer.data = value2;
76 List<DirectoryInfo> list =
new List<DirectoryInfo>();
78 list.AddRange(PackageIterator.GetDirectories(
"Skin", useCache:
false));
79 IEnumerable<FileInfo> enumerable = list.SelectMany((DirectoryInfo d) => from f in d.GetFiles(
"*.png", SearchOption.TopDirectoryOnly)
82 Dictionary<string, string> dictionary =
new Dictionary<string, string>();
83 foreach (FileInfo
item in enumerable)
85 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(
item.Name);
86 string value = Path.ChangeExtension(
item.FullName,
null);
87 dictionary[fileNameWithoutExtension] = value;
94 if (!
suffixes.TryGetValue(suffix, out var value))
98 return value.GetSprite();
113 foreach (var state
in states)
115 string item = state.suffix;
116 Func<Card, bool> item2 = state.when;
118 if (spriteData2 == spriteData)
129 catch (Exception arg)
133 Debug.LogError(
$"#sprite failed to load state {item} on {card.id}\n{arg}");
142 if (!
suffixKeys.TryGetValue((dir, skin, snow, state), out var value))
144 value =
new List<string>
146 $"_skin{skin}_dir{dir}",
153 value = value.SelectMany((
string k) =>
new string[2]
161 value = value.Select((
string k) => state + k).Concat(value).ToList();
165 foreach (
string item in value)
169 Sprite[] sprites = value2.sprites;
170 if (sprites ==
null || sprites.Length != 0)
188 public void BuildSuffixData(
string id, IReadOnlyDictionary<string, string> dictTexItems, List<string> sortedIds =
null)
190 List<string> list = sortedIds ?? dictTexItems.Keys.OrderBy((
string k) => k).ToList();
191 int num = list.BinarySearch(
id);
196 for (
int num2 = num; num2 < list.Count; num2++)
198 string text = list[num2];
199 if (!text.StartsWith(
id))
203 string text2 = text[
id.Length..];
204 if (text2.StartsWith(
"_"))
206 text2 =
string.Concat(from t in text2.Split(
'_').Skip(1)
207 orderby (!(t ==
"snow")) ? ((!Regex.IsMatch(t,
"^dir\\d+$")) ? (Regex.IsMatch(t,
"^skin\\d+$") ? 1 : 0) : 2) : 3
212 path = dictTexItems[text]
216 Debug.Log(
"#sprite replacer " + text2.IsEmpty(
"<base>") +
"/" + dictTexItems[text].ShortPath());
240 else if (renderData !=
null &&
dictModItems.ContainsKey(
"Item/" +
id))
252 Debug.LogError(
"#sprite error fetching sprite replacer '" +
id +
"' : " + ex);
Dictionary< string, SpriteData > suffixes
bool HasSprite(string id, RenderData renderData=null)
Dictionary< string, bool > isChecked
static Dictionary< string, string > ListSkinItems()
static HashSet< string > failedStates
static Dictionary<(int, int, bool, string), List< string > > suffixKeys
Sprite GetSprite(string suffix="")
static Dictionary< string, SpriteReplacer > dictSkins
void Reload(string id, RenderData renderData=null)
SpriteData GetData(int dir, int skin, bool snow, Card card=null)
static Dictionary< string, string > dictModItems
static Dictionary< string, SpriteReplacer > dictOverrides
static List< string > sortedModIds
Sprite GetSprite(int dir, int skin, bool snow)
SpriteData FindData(int dir, int skin, bool snow, string state)
static List<(string suffix, Func< Card, bool > when)> states
void BuildSuffixData(string id, IReadOnlyDictionary< string, string > dictTexItems, List< string > sortedIds=null)
static Dictionary< string, SpriteReplacer > ListSkins()