9
9
10
10
namespace Assets . Scripts . Core . AssetManagement
11
11
{
12
- public class AssetManager
13
- {
12
+ /// <summary>
13
+ /// Stores an ordered list of paths for the engine to check when trying to find a cg
14
+ /// </summary>
15
+ public struct PathCascadeList {
16
+ public readonly string nameEN ;
17
+ public readonly string nameJP ;
18
+ public readonly string [ ] paths ;
19
+ public PathCascadeList ( string nameEN , string nameJP , string [ ] paths )
20
+ {
21
+ this . nameEN = nameEN ;
22
+ this . nameJP = nameJP ;
23
+ this . paths = paths ;
24
+ }
25
+ }
26
+ public class AssetManager {
14
27
private static AssetManager _instance ;
15
28
16
- public bool UseNewArt = true ;
29
+ private List < PathCascadeList > artsets = new List < PathCascadeList > ( ) ;
30
+ public int CurrentArtsetIndex = 0 ;
31
+ public int ArtsetCount => artsets . Count == 0 ? 2 : artsets . Count ;
32
+ public PathCascadeList CurrentArtset => GetArtset ( CurrentArtsetIndex ) ;
17
33
18
34
private Texture2D windowTexture ;
19
35
@@ -23,6 +39,54 @@ public class AssetManager
23
39
24
40
public static AssetManager Instance => _instance ?? ( _instance = GameSystem . Instance . AssetManager ) ;
25
41
42
+ /// <summary>
43
+ /// Get the artset at the given index
44
+ /// </summary>
45
+ /// <param name="index">The index of the artset to get</param>
46
+ /// <returns></returns>
47
+ public PathCascadeList GetArtset ( int index )
48
+ {
49
+ // To maintain compatibility with scripts that don't specify artsets, if none have been added act like the base game
50
+ if ( artsets . Count == 0 )
51
+ {
52
+ if ( index == 0 )
53
+ {
54
+ return new PathCascadeList ( "Console" , "ゲーム機" , new string [ ] { "CG" } ) ;
55
+ }
56
+ if ( index == 1 )
57
+ {
58
+ return new PathCascadeList ( "Remake" , "リメーク" , new string [ ] { "CGAlt" , "CG" } ) ;
59
+ }
60
+ }
61
+ if ( index >= 0 && index < artsets . Count )
62
+ {
63
+ return artsets [ index ] ;
64
+ }
65
+ return new PathCascadeList ( "Unknown (" + index + ")" , "不明(" + index + ")" , new string [ ] { "CG" } ) ;
66
+ }
67
+
68
+ public void AddArtset ( PathCascadeList artset )
69
+ {
70
+ artsets . Add ( artset ) ;
71
+ }
72
+
73
+ /// <summary>
74
+ /// Gets the path to an asset with the given name in the given artset, or null if none are found
75
+ /// </summary>
76
+ /// <returns>A path to an on-disk asset or null</returns>
77
+ public string PathToAssetWithName ( string name , PathCascadeList artset )
78
+ {
79
+ foreach ( var path in artset . paths )
80
+ {
81
+ string filePath = Path . Combine ( Path . Combine ( assetPath , path ) , name ) ;
82
+ if ( File . Exists ( filePath ) )
83
+ {
84
+ return filePath ;
85
+ }
86
+ }
87
+ return null ;
88
+ }
89
+
26
90
public void CompileFolder ( string srcDir , string destDir )
27
91
{
28
92
string [ ] files = Directory . GetFiles ( srcDir , "*.txt" ) ;
@@ -173,44 +237,21 @@ public Texture2D LoadTexture(string textureName)
173
237
{
174
238
return windowTexture ;
175
239
}
176
- string path = Path . Combine ( assetPath , "CG/" + textureName . ToLower ( ) + "_j.png" ) ;
177
- string path2 = Path . Combine ( assetPath , "CGAlt/" + textureName . ToLower ( ) + "_j.png" ) ;
178
- string text = Path . Combine ( assetPath , "CG/" + textureName . ToLower ( ) + ".png" ) ;
179
- string path3 = Path . Combine ( assetPath , "CGAlt/" + textureName . ToLower ( ) + ".png" ) ;
180
- byte [ ] array = new byte [ 0 ] ;
181
- bool flag = false ;
240
+ string path = null ;
182
241
if ( ! GameSystem . Instance . UseEnglishText )
183
242
{
184
- if ( UseNewArt && File . Exists ( path2 ) )
185
- {
186
- array = File . ReadAllBytes ( path2 ) ;
187
- flag = true ;
188
- }
189
- else if ( File . Exists ( path ) )
190
- {
191
- array = File . ReadAllBytes ( path ) ;
192
- flag = true ;
193
- }
243
+ path = PathToAssetWithName ( textureName . ToLower ( ) + "_j.png" , CurrentArtset ) ;
194
244
}
195
- if ( ! flag )
245
+ path = path ?? PathToAssetWithName ( textureName . ToLower ( ) + ".png" , CurrentArtset ) ;
246
+ if ( path == null )
196
247
{
197
- if ( UseNewArt && File . Exists ( path3 ) )
198
- {
199
- array = File . ReadAllBytes ( path3 ) ;
200
- }
201
- else
202
- {
203
- if ( ! File . Exists ( text ) )
204
- {
205
- Logger . LogWarning ( "Could not find texture asset " + text ) ;
206
- return null ;
207
- }
208
- array = File . ReadAllBytes ( text ) ;
209
- }
248
+ Logger . LogWarning ( "Could not find texture asset " + textureName . ToLower ( ) + " in " + CurrentArtset . nameEN ) ;
249
+ return null ;
210
250
}
251
+ byte [ ] array = File . ReadAllBytes ( path ) ;
211
252
if ( array == null || array . Length == 0 )
212
253
{
213
- throw new Exception ( "Failed loading texture " + textureName . ToLower ( ) ) ;
254
+ throw new Exception ( "Failed loading texture " + path ) ;
214
255
}
215
256
byte [ ] array2 = new byte [ 4 ] ;
216
257
Buffer . BlockCopy ( array , 16 , array2 , 0 , 4 ) ;
0 commit comments