Skip to content

Commit a7a44a4

Browse files
committed
Add support for custom image directory fallbacks
1 parent 0a4cf8c commit a7a44a4

File tree

9 files changed

+100
-41
lines changed

9 files changed

+100
-41
lines changed

Assets.Scripts.Core.AssetManagement/AssetManager.cs

+75-34
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@
99

1010
namespace Assets.Scripts.Core.AssetManagement
1111
{
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 {
1427
private static AssetManager _instance;
1528

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);
1733

1834
private Texture2D windowTexture;
1935

@@ -23,6 +39,54 @@ public class AssetManager
2339

2440
public static AssetManager Instance => _instance ?? (_instance = GameSystem.Instance.AssetManager);
2541

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+
2690
public void CompileFolder(string srcDir, string destDir)
2791
{
2892
string[] files = Directory.GetFiles(srcDir, "*.txt");
@@ -173,44 +237,21 @@ public Texture2D LoadTexture(string textureName)
173237
{
174238
return windowTexture;
175239
}
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;
182241
if (!GameSystem.Instance.UseEnglishText)
183242
{
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);
194244
}
195-
if (!flag)
245+
path = path ?? PathToAssetWithName(textureName.ToLower() + ".png", CurrentArtset);
246+
if (path == null)
196247
{
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;
210250
}
251+
byte[] array = File.ReadAllBytes(path);
211252
if (array == null || array.Length == 0)
212253
{
213-
throw new Exception("Failed loading texture " + textureName.ToLower());
254+
throw new Exception("Failed loading texture " + path);
214255
}
215256
byte[] array2 = new byte[4];
216257
Buffer.BlockCopy(array, 16, array2, 0, 4);

Assets.Scripts.Core.Buriko/BurikoMemory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void LoadGlobals()
506506
GameSystem.Instance.StopVoiceOnClick = GetGlobalFlag("GCutVoiceOnClick").BoolValue();
507507
GameSystem.Instance.UseSystemSounds = GetGlobalFlag("GUseSystemSound").BoolValue();
508508
GameSystem.Instance.UseEnglishText = GetGlobalFlag("GLanguage").BoolValue();
509-
AssetManager.Instance.UseNewArt = GetGlobalFlag("GArtStyle").BoolValue();
509+
AssetManager.Instance.CurrentArtsetIndex = GetGlobalFlag("GArtStyle").IntValue();
510510
GameSystem.Instance.AudioController.RefreshLayerVolumes();
511511
}
512512
catch (Exception message)
@@ -541,7 +541,7 @@ public void SaveGlobals()
541541
public void MODSyncState()
542542
{
543543
// Sync Art Style. This is really set up to support only init.txt initialization
544-
AssetManager.Instance.UseNewArt = GetGlobalFlag("GArtStyle").BoolValue();
544+
AssetManager.Instance.CurrentArtsetIndex = GetGlobalFlag("GArtStyle").IntValue();
545545
}
546546
}
547547
}

Assets.Scripts.Core.Buriko/BurikoOperations.cs

+1
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,6 @@ public enum BurikoOperations
141141
ModGetHighestChapterFlag,
142142
ModSetMainFontOutlineWidth,
143143
ModSetLayerFilter,
144+
ModAddArtset,
144145
}
145146
}

Assets.Scripts.Core.Buriko/BurikoScriptFile.cs

+12
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,8 @@ public BurikoVariable ExecuteOperation(BurikoOperations op)
21642164
return OperationMODSetMainFontOutlineWidth();
21652165
case BurikoOperations.ModSetLayerFilter:
21662166
return OperationMODSetLayerFilter();
2167+
case BurikoOperations.ModAddArtset:
2168+
return OperationMODAddArtset();
21672169
default:
21682170
ScriptError("Unhandled Operation : " + op);
21692171
return BurikoVariable.Null;
@@ -2599,5 +2601,15 @@ private BurikoVariable OperationMODSetLayerFilter()
25992601
MODSceneController.SetLayerFilter(layer, filter);
26002602
return BurikoVariable.Null;
26012603
}
2604+
2605+
public BurikoVariable OperationMODAddArtset()
2606+
{
2607+
SetOperationType("MODAddArtset");
2608+
string nameEN = ReadVariable().StringValue();
2609+
string nameJP = ReadVariable().StringValue();
2610+
string[] paths = ReadVariable().StringValue().Split(':');
2611+
AssetManager.Instance.AddArtset(new PathCascadeList(nameEN, nameJP, paths));
2612+
return BurikoVariable.Null;
2613+
}
26022614
}
26032615
}

Assets.Scripts.UI.Config/SwitchButton.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void UpdateButtonValues()
5252
flag = GameSystem.Instance.UseSystemSounds;
5353
break;
5454
case ConfigButtonType.ArtStyle:
55-
flag = AssetManager.Instance.UseNewArt;
55+
flag = AssetManager.Instance.CurrentArtsetIndex == 1;
5656
break;
5757
case ConfigButtonType.Language:
5858
flag = GameSystem.Instance.UseEnglishText;

Assets.Scripts.UI.Tips/TipsEntry.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Init(TipsDataEntry t, TipsManager mg)
2828
}
2929
string name = $"tips{t.Id:D3}na_normal";
3030
UISpriteData uISpriteData = sprite.atlas.GetSprite(name);
31-
if (uISpriteData != null && AssetManager.Instance.UseNewArt)
31+
if (uISpriteData != null && AssetManager.Instance.CurrentArtsetIndex == 1)
3232
{
3333
button.normalSprite = $"tips{t.Id:D3}na_normal";
3434
button.hoverSprite = $"tips{t.Id:D3}na_hover";

Assets.Scripts.UI/MainUIController.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,11 @@ public void OnGUI()
619619
}
620620
var videoOpeningValue = BurikoMemory.Instance.GetGlobalFlag("GVideoOpening").IntValue();
621621
var videoOpeningDescription = videoOpeningValue == 0 ? "Unset" : videoOpeningValue == 1 ? "Disabled" : videoOpeningValue == 2 ? "In-game" : videoOpeningValue == 3 ? "At launch + in-game" : "Unknown";
622-
string text7 = "[MOD SETTINGS]\nADV-MODE = " + array2[0] + "\nLip-Sync = " + array2[5] + "\nAlternative BGM = " + array2[1] + "\nAlternative BGM Flow = " + array6[2] + array5[2] + "\nAlternative SE = " + array2[2] + "\nAlternative SE Flow = " + array6[3] + array5[3] + "\nAlternative Voice = " + array2[3] + "\nAlternative Voice Priority = " + array2[4] + "\nVoice Matching Level = " + array6[0] + array5[0] + "\nEffect Level = " + array6[1] + array5[1] + "\nVoice Volume = " + text2 + $"\nOP movies = {videoOpeningDescription} ({videoOpeningValue})" + "\n\n[Restore Game Settings]" + text + "\n\n[Status]\n" + text4 + text3 + text5 + text6;
622+
var artsetDescription = "Art: " + GameSystem.Instance.ChooseJapaneseEnglish(
623+
japanese: Core.AssetManagement.AssetManager.Instance.CurrentArtset.nameJP,
624+
english: Core.AssetManagement.AssetManager.Instance.CurrentArtset.nameEN
625+
);
626+
string text7 = "[MOD SETTINGS]\nADV-MODE = " + array2[0] + "\nLip-Sync = " + array2[5] + "\nAlternative BGM = " + array2[1] + "\nAlternative BGM Flow = " + array6[2] + array5[2] + "\nAlternative SE = " + array2[2] + "\nAlternative SE Flow = " + array6[3] + array5[3] + "\nAlternative Voice = " + array2[3] + "\nAlternative Voice Priority = " + array2[4] + "\nVoice Matching Level = " + array6[0] + array5[0] + "\nEffect Level = " + array6[1] + array5[1] + "\nVoice Volume = " + text2 + $"\nOP movies = {videoOpeningDescription} ({videoOpeningValue})\n" + artsetDescription + "\n\n[Restore Game Settings]" + text + "\n\n[Status]\n" + text4 + text3 + text5 + text6;
623627
GUI.TextArea(new Rect(0f, 0f, 320f, 1080f), text7, 900);
624628
}
625629
if (BurikoMemory.Instance.GetFlag("LFlagMonitor").IntValue() == 2)

BGICompiler.Compiler/OperationHandler.cs

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public void FillParamValues()
169169
paramLookup.Add("ModGetHighestChapterFlag", new OpType(BurikoOperations.ModGetHighestChapterFlag, "i"));
170170
paramLookup.Add("ModSetMainFontOutlineWidth", new OpType(BurikoOperations.ModSetMainFontOutlineWidth, "i"));
171171
paramLookup.Add("ModSetLayerFilter", new OpType(BurikoOperations.ModSetLayerFilter, "iis"));
172+
paramLookup.Add("ModAddArtset", new OpType(BurikoOperations.ModAddArtset, "sss"));
172173
}
173174

174175
public void ParamCheck(string op, BGIParameters param)

MOD.Scripts.Core.Scene/MODTextureController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void RestoreTextures()
4444

4545
public void ToggleArtStyle()
4646
{
47-
AssetManager.Instance.UseNewArt = !AssetManager.Instance.UseNewArt;
48-
BurikoMemory.Instance.SetGlobalFlag("GArtStyle", AssetManager.Instance.UseNewArt ? 1 : 0);
47+
AssetManager.Instance.CurrentArtsetIndex = (AssetManager.Instance.CurrentArtsetIndex + 1) % AssetManager.Instance.ArtsetCount;
48+
BurikoMemory.Instance.SetGlobalFlag("GArtStyle", AssetManager.Instance.CurrentArtsetIndex);
4949
RestoreTextures();
5050
GameSystem.Instance.SceneController.ReloadAllImages();
5151
}

0 commit comments

Comments
 (0)