using Cryville.Common; using Cryville.Common.Pdt; using Cryville.Crtr.Browsing; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Cryville.Crtr { public class Skin : MetaInfo { public const long CURRENT_FORMAT = 2; [JsonRequired] public long format; public string @base; [JsonRequired] public string ruleset; public List frames = new List(); [JsonIgnore] public PdtSkin Root { get; private set; } public void LoadPdt(DirectoryInfo dir) { using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) { var src = pdtreader.ReadToEnd(); 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 { switch (format[1]) { case 1: Root = (PdtSkin)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(PdtSkin)); break; default: throw new NotSupportedException("Unsupported skin format"); } } } } } public class PdtSkin { public Dictionary animations = new Dictionary(); public Dictionary effects = new Dictionary(); public SkinElement elements; public void Optimize(PdtEvaluator etor) { foreach (var a in animations) { a.Value.Optimize(etor); } foreach (var e in effects) { var effect = e.Value; etor.ContextCascadeInsert(); etor.ContextCascadeUpdate(EffectInstance._VAR_EFFECT_INDEX, PropSrc.Error); etor.Optimize(effect.duration); effect.elements.Optimize(etor); etor.ContextCascadeDiscard(); } elements.Optimize(etor); } } public class SkinElement { [ElementList] public Dictionary elements = new Dictionary(); [PropertyList] public Dictionary properties = new Dictionary(); public bool IsDynamic { get; private set; } public void Optimize(PdtEvaluatorBase etor) { IsDynamic = true; foreach (var e in properties) { etor.Optimize(e.Value); if (!e.Value.IsConstant) IsDynamic = true; } foreach (var e in elements) { e.Key.Optimize(etor); e.Value.Optimize(etor); if (e.Value.IsDynamic) IsDynamic = true; } } } public class EffectDefinition { public PdtExpression duration; public SkinElement elements; } public class AnimationSpan { [ElementList] public Dictionary spans = new Dictionary(); [PropertyList] public Dictionary properties = new Dictionary(); public void Optimize(PdtEvaluator etor) { foreach (var p in properties) { etor.Optimize(p.Value); } foreach (var e in spans) { e.Value.Optimize(etor); } } } }