Elin Decompiled Documentation EA 23.300 Nightly
Loading...
Searching...
No Matches
SpriteReplacer Class Reference

Public Member Functions

Sprite GetSprite (string suffix="")
 
Sprite GetSprite (int dir, int skin, bool snow)
 
void Validate ()
 
void ReloadBuiltInTextures ()
 
void BuildSuffixData (string id, Dictionary< string, string > dictTexItems)
 
void Reload (string id, RenderData renderData=null)
 
bool HasSprite (string id, RenderData renderData=null)
 

Static Public Member Functions

static Dictionary< string, SpriteReplacerListSkins ()
 

Public Attributes

SpriteData data
 
Dictionary< string, SpriteDatasuffixes = new Dictionary<string, SpriteData>()
 
Dictionary< string, bool > isChecked = new Dictionary<string, bool>()
 

Static Public Attributes

static Dictionary< string, SpriteReplacerdictSkins = new Dictionary<string, SpriteReplacer>()
 
static Dictionary< string, string > dictModItems = new Dictionary<string, string>()
 
static Dictionary< string, string > dictTextureItems = new Dictionary<string, string>()
 

Detailed Description

Definition at line 7 of file SpriteReplacer.cs.

Member Function Documentation

◆ BuildSuffixData()

void SpriteReplacer.BuildSuffixData ( string  id,
Dictionary< string, string >  dictTexItems 
)
inline

Definition at line 112 of file SpriteReplacer.cs.

113 {
114 foreach (var (text3, path) in dictTexItems)
115 {
116 if (text3.StartsWith(id))
117 {
118 string text4 = text3[id.Length..];
119 SpriteData spriteData = new SpriteData
120 {
121 path = path
122 };
123 spriteData.Init();
124 suffixes[text4] = spriteData;
125 Debug.Log("#sprite replacer " + text4.IsEmpty("<base>") + "/" + path.ShortPath());
126 }
127 }
128 }
void Init()
Definition: SpriteData.cs:32
Dictionary< string, SpriteData > suffixes

References Debug, SpriteData.Init(), and suffixes.

Referenced by Reload().

◆ GetSprite() [1/2]

Sprite SpriteReplacer.GetSprite ( int  dir,
int  skin,
bool  snow 
)
inline

Definition at line 71 of file SpriteReplacer.cs.

72 {
73 foreach (string item in new List<string>
74 {
75 $"_skin{skin}_dir{dir}",
76 $"_skin{skin}",
77 $"_dir{dir}",
78 ""
79 })
80 {
81 Sprite sprite = null;
82 if (snow)
83 {
84 sprite = GetSprite(item + "_snow");
85 }
86 if ((object)sprite == null)
87 {
88 sprite = GetSprite(item);
89 }
90 if ((bool)sprite)
91 {
92 return sprite;
93 }
94 }
95 return data?.GetSprite();
96 }
$
Definition: ModManager.cs:87
Sprite GetSprite()
Definition: SpriteData.cs:118
SpriteData data
Sprite GetSprite(string suffix="")

References $, data, SpriteData.GetSprite(), GetSprite(), and item.

◆ GetSprite() [2/2]

Sprite SpriteReplacer.GetSprite ( string  suffix = "")
inline

Definition at line 62 of file SpriteReplacer.cs.

63 {
64 if (!suffixes.TryGetValue(suffix, out var value))
65 {
66 return null;
67 }
68 return value.GetSprite();
69 }

References suffixes.

Referenced by GetSprite(), Chara.GetSprite(), RenderRow.GetSprite(), Card.SetImage(), and CharaRenderer.SetOwner().

◆ HasSprite()

bool SpriteReplacer.HasSprite ( string  id,
RenderData  renderData = null 
)
inline

Definition at line 169 of file SpriteReplacer.cs.

170 {
171 if (!isChecked.GetValueOrDefault(id) || (data != null && data.id != id))
172 {
173 Reload(id, renderData);
174 }
175 return data != null;
176 }
string id
Definition: SpriteData.cs:10
Dictionary< string, bool > isChecked
void Reload(string id, RenderData renderData=null)

References data, SpriteData.id, isChecked, and Reload().

Referenced by RenderRow.GetSprite(), and CardActor.OnRender().

◆ ListSkins()

static Dictionary< string, SpriteReplacer > SpriteReplacer.ListSkins ( )
inlinestatic

Definition at line 21 of file SpriteReplacer.cs.

22 {
23 List<string> list = new List<string>();
24 foreach (KeyValuePair<string, SpriteReplacer> dictSkin in dictSkins)
25 {
26 if (!File.Exists(dictSkin.Value.data.path + ".png"))
27 {
28 list.Add(dictSkin.Key);
29 }
30 }
31 foreach (string item in list)
32 {
33 dictSkins.Remove(item);
34 }
35 Dictionary<string, string> dictionary = new DirectoryInfo(CorePath.custom + "Skin").GetFiles("*.png").ToDictionary((FileInfo f) => Path.GetFileNameWithoutExtension(f.Name), (FileInfo f) => Path.ChangeExtension(f.FullName, null));
36 string key2;
37 foreach (KeyValuePair<string, string> item2 in dictionary)
38 {
39 item2.Deconstruct(out var key, out key2);
40 string key3 = key;
41 string path = key2;
42 if (!dictSkins.ContainsKey(key3))
43 {
44 dictSkins[key3] = new SpriteReplacer
45 {
46 data = new SpriteData
47 {
48 path = path
49 }
50 };
51 }
52 }
53 foreach (KeyValuePair<string, SpriteReplacer> dictSkin2 in dictSkins)
54 {
55 dictSkin2.Deconstruct(out key2, out var value);
56 string id = key2;
57 value.BuildSuffixData(id, dictionary);
58 }
59 return dictSkins;
60 }
static string custom
Definition: CorePath.cs:159
static Dictionary< string, SpriteReplacer > dictSkins

References CorePath.custom, data, dictSkins, and item.

Referenced by LayerEditSkin.RefreshList().

◆ Reload()

void SpriteReplacer.Reload ( string  id,
RenderData  renderData = null 
)
inline

Definition at line 130 of file SpriteReplacer.cs.

131 {
132 data = null;
133 suffixes.Clear();
134 try
135 {
136 if (dictModItems.ContainsKey(id))
137 {
139 }
140 else
141 {
142 if (dictTextureItems.Count == 0)
143 {
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 {
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 }
string path
Definition: SpriteData.cs:12
static Dictionary< string, string > dictTextureItems
void ReloadBuiltInTextures()
void BuildSuffixData(string id, Dictionary< string, string > dictTexItems)
static Dictionary< string, string > dictModItems

References BuildSuffixData(), data, Debug, dictModItems, dictTextureItems, isChecked, SpriteData.path, ReloadBuiltInTextures(), and suffixes.

Referenced by HasSprite().

◆ ReloadBuiltInTextures()

void SpriteReplacer.ReloadBuiltInTextures ( )
inline

Definition at line 107 of file SpriteReplacer.cs.

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 }
static string packageCore
Definition: CorePath.cs:153

References dictTextureItems, and CorePath.packageCore.

Referenced by Reload().

◆ Validate()

void SpriteReplacer.Validate ( )
inline

Definition at line 98 of file SpriteReplacer.cs.

99 {
100 data?.Validate();
101 foreach (SpriteData value in suffixes.Values)
102 {
103 value?.Validate();
104 }
105 }
void Validate()
Definition: SpriteData.cs:127

References data, suffixes, and SpriteData.Validate().

Member Data Documentation

◆ data

◆ dictModItems

Dictionary<string, string> SpriteReplacer.dictModItems = new Dictionary<string, string>()
static

Definition at line 11 of file SpriteReplacer.cs.

Referenced by ModPackage.ParseTexture(), and Reload().

◆ dictSkins

Dictionary<string, SpriteReplacer> SpriteReplacer.dictSkins = new Dictionary<string, SpriteReplacer>()
static

◆ dictTextureItems

Dictionary<string, string> SpriteReplacer.dictTextureItems = new Dictionary<string, string>()
static

Definition at line 13 of file SpriteReplacer.cs.

Referenced by Reload(), and ReloadBuiltInTextures().

◆ isChecked

Dictionary<string, bool> SpriteReplacer.isChecked = new Dictionary<string, bool>()

Definition at line 19 of file SpriteReplacer.cs.

Referenced by HasSprite(), and Reload().

◆ suffixes

Dictionary<string, SpriteData> SpriteReplacer.suffixes = new Dictionary<string, SpriteData>()

Definition at line 17 of file SpriteReplacer.cs.

Referenced by BuildSuffixData(), GetSprite(), CardActor.OnRender(), Reload(), and Validate().


The documentation for this class was generated from the following file: