99{
100 data?.Validate();
102 {
104 }
105 }
106
107 public void ReloadBuiltInTextures()
108 {
109 dictTextureItems =
new DirectoryInfo(
CorePath.
packageCore +
"Texture/Item").GetFiles(
"*.png").ToDictionary((FileInfo f) => Path.GetFileNameWithoutExtension(f.Name), (FileInfo f) => Path.ChangeExtension(f.FullName,
null));
110 }
111
112 public void BuildSuffixData(string id, Dictionary<string, string> dictTexItems)
113 {
114 foreach (var (text3, path) in dictTexItems)
115 {
116 if (text3.StartsWith(id))
117 {
118 string text4 = text3[id.Length..];
120 {
121 path = path
122 };
124 suffixes[text4] = spriteData;
125 Debug.Log(
"#sprite replacer " + text4.IsEmpty(
"<base>") +
"/" + path.ShortPath());
126 }
127 }
128 }
129
130 public void Reload(
string id,
RenderData renderData =
null)
131 {
132 data = null;
133 suffixes.Clear();
134 try
135 {
136 if (dictModItems.ContainsKey(id))
137 {
138 BuildSuffixData(id, dictModItems);
139 }
140 else
141 {
142 if (dictTextureItems.Count == 0)
143 {
144 ReloadBuiltInTextures();
145 }
146 string text = dictTextureItems.TryGetValue(id);
147 if (text == null && renderData != null)
148 {
149 text = dictTextureItems.TryGetValue(renderData.name);
150 }
151 if (text != null)
152 {
153 BuildSuffixData(id, dictTextureItems);
154 }
155 }
156 data = suffixes.TryGetValue("");
157 if (data != null)
158 {
159 Debug.Log(
id +
":" + data.path);
160 }
161 }
162 catch (Exception ex)
163 {
164 Debug.LogError(
"#sprite error fetching sprite replacer:" + ex);
165 }
166 isChecked[id] = true;
167 }
168
169 public bool HasSprite(
string id,
RenderData renderData =
null)
170 {
171 if (!isChecked.GetValueOrDefault(id) || (data != null && data.id != id))
172 {
173 Reload(id, renderData);
174 }
175 return data != null;
176 }
177}
static string packageCore