Add backward compatibility for skin.

This commit is contained in:
2023-02-17 16:24:24 +08:00
parent db0165d145
commit 675ce68073
5 changed files with 32 additions and 17 deletions

View File

@@ -22,7 +22,7 @@ namespace Cryville.Crtr {
public void LoadPdt(DirectoryInfo dir) {
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
var src = pdtreader.ReadToEnd();
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret();
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret(typeof(PdtRuleset));
}
}
}

View File

@@ -5,7 +5,7 @@ using System.Reflection;
namespace Cryville.Crtr {
internal class RulesetInterpreter : PdtInterpreter {
public RulesetInterpreter(string src, Binder binder) : base(src, typeof(PdtRuleset), binder) { }
public RulesetInterpreter(string src, Binder binder) : base(src, binder) { }
readonly List<RulesetSelector> s = new List<RulesetSelector>();
readonly List<string> a = new List<string>();

View File

@@ -26,12 +26,21 @@ namespace Cryville.Crtr {
public void LoadPdt(DirectoryInfo dir) {
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
var src = pdtreader.ReadToEnd();
Root = (PdtSkin)new SkinInterpreter(src, null).Interpret();
var interpreter = new SkinInterpreter(src, null);
var format = interpreter.GetFormatVersion();
if (format.Length == 1) {
Root = new PdtSkin();
Root.elements = (SkinElement)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(SkinElement));
}
else {
if (format[1] == 1) {
Root = (PdtSkin)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(PdtSkin));
}
}
}
}
}
[Binder(typeof(PdtBinder))]
public class PdtSkin {
public Dictionary<Identifier, AnimationSpan> animations
= new Dictionary<Identifier, AnimationSpan>();

View File

@@ -7,7 +7,7 @@ using System.Reflection;
namespace Cryville.Crtr {
public class SkinInterpreter : PdtInterpreter {
public SkinInterpreter(string src, Binder binder) : base(src, typeof(PdtSkin), binder) { }
public SkinInterpreter(string src, Binder binder) : base(src, binder) { }
readonly List<SkinSelector> s = new List<SkinSelector>();
readonly HashSet<string> a = new HashSet<string>();