Elin Decompiled Documentation EA 23.153 Nightly
Loading...
Searching...
No Matches
SpriteReplacer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using UnityEngine;
5
6public class SpriteReplacer
7{
8 public static Dictionary<string, SpriteReplacer> dictSkins = new Dictionary<string, SpriteReplacer>();
9
10 public static Dictionary<string, string> dictModItems = new Dictionary<string, string>();
11
12 public bool hasChacked;
13
15
16 public static Dictionary<string, SpriteReplacer> ListSkins()
17 {
18 List<string> list = new List<string>();
19 foreach (KeyValuePair<string, SpriteReplacer> dictSkin in dictSkins)
20 {
21 if (!File.Exists(dictSkin.Value.data.path + ".png"))
22 {
23 list.Add(dictSkin.Key);
24 }
25 }
26 foreach (string item in list)
27 {
28 dictSkins.Remove(item);
29 }
30 FileInfo[] files = new DirectoryInfo(CorePath.custom + "Skin").GetFiles();
31 foreach (FileInfo fileInfo in files)
32 {
33 if (fileInfo.Extension == ".png")
34 {
35 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
36 if (!dictSkins.ContainsKey(fileNameWithoutExtension))
37 {
38 SpriteReplacer spriteReplacer = new SpriteReplacer();
39 spriteReplacer.data = new SpriteData
40 {
41 path = fileInfo.GetFullFileNameWithoutExtension()
42 };
43 spriteReplacer.data.Init();
44 dictSkins.Add(fileNameWithoutExtension, spriteReplacer);
45 }
46 }
47 }
48 return dictSkins;
49 }
50
51 public bool HasSprite(string id)
52 {
53 if (!hasChacked)
54 {
55 try
56 {
57 if (dictModItems.ContainsKey(id))
58 {
59 Debug.Log(id + ":" + dictModItems[id]);
60 data = new SpriteData
61 {
62 path = dictModItems[id]
63 };
64 data.Init();
65 }
66 else
67 {
68 string text = CorePath.packageCore + "Texture/Item/" + id;
69 if (File.Exists(text + ".png"))
70 {
71 data = new SpriteData
72 {
73 path = text
74 };
75 data.Init();
76 }
77 }
78 hasChacked = true;
79 }
80 catch (Exception ex)
81 {
82 Debug.Log("Error during fetching spirte:" + ex);
83 }
84 }
85 return data != null;
86 }
87}
static string custom
Definition: CorePath.cs:163
void Init()
Definition: SpriteData.cs:29
SpriteData data
static Dictionary< string, SpriteReplacer > dictSkins
static Dictionary< string, string > dictModItems
bool HasSprite(string id)
static Dictionary< string, SpriteReplacer > ListSkins()