Add frame list in skin data structure. Remove Cocos2d Plist support.

This commit is contained in:
2022-11-17 17:19:31 +08:00
parent cd8aa0e65c
commit fd9e2ce409
13 changed files with 127 additions and 1140 deletions

View File

@@ -1,7 +1,6 @@
#define BUILD
using Cryville.Common;
using Cryville.Common.Plist;
using Cryville.Crtr.Config;
using Cryville.Crtr.Event;
using Newtonsoft.Json;
@@ -26,8 +25,7 @@ namespace Cryville.Crtr {
Ruleset ruleset;
PdtRuleset pruleset;
Dictionary<string, Texture2D> texs;
public static Dictionary<string, Cocos2dFrames.Frame> frames;
List<Cocos2dFrames> plists;
public static Dictionary<string, SpriteFrame> frames;
readonly Queue<string> texLoadQueue = new Queue<string>();
#if UNITY_5_4_OR_NEWER
@@ -353,6 +351,13 @@ namespace Cryville.Crtr {
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
);
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (skin.format != 1) throw new FormatException("Invalid skin file version");
}
loadThread = new Thread(new ParameterizedThreadStart(Load));
loadThread.Start(new LoadInfo() {
chartFile = chartFile,
@@ -363,10 +368,10 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
texloadtimer = new diag::Stopwatch();
texloadtimer.Start();
frames = new Dictionary<string, SpriteFrame>();
texs = new Dictionary<string, Texture2D>();
var flist = skinFile.Directory.GetFiles("*.png");
foreach (FileInfo f in flist) {
texLoadQueue.Enqueue(f.FullName);
foreach (var f in skin.frames) {
texLoadQueue.Enqueue(Path.Combine(skinFile.Directory.FullName, f));
}
}
@@ -375,13 +380,12 @@ namespace Cryville.Crtr {
diag::Stopwatch timer = new diag::Stopwatch();
timer.Reset(); timer.Start();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
foreach (var i in plists) i.Init(texs);
foreach (var t in texs) {
if (frames.ContainsKey(t.Key)) {
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
continue;
}
var f = new Cocos2dFrames.Frame(t.Value);
var f = new SpriteFrame(t.Value);
f.Init();
frames.Add(t.Key, f);
}
@@ -559,23 +563,9 @@ namespace Cryville.Crtr {
void LoadSkin(FileInfo file) {
DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (skin.format != 1) throw new FormatException("Invalid skin file version");
skin.LoadPdt(dir);
pskin = skin.Root;
pskin.Optimize(etor);
}
plists = new List<Cocos2dFrames>();
frames = new Dictionary<string, Cocos2dFrames.Frame>();
foreach (FileInfo f in file.Directory.GetFiles("*.plist")) {
var pobj = PlistConvert.Deserialize<Cocos2dFrames>(f.FullName);
plists.Add(pobj);
foreach (var i in pobj.frames)
frames.Add(StringUtils.TrimExt(i.Key), i.Value);
}
skin.LoadPdt(dir);
pskin = skin.Root;
pskin.Optimize(etor);
}
#endregion
}