diff --git a/Assets/Cryville/Crtr/PdtBinder.cs b/Assets/Cryville/Crtr/PdtBinder.cs new file mode 100644 index 0000000..579adf7 --- /dev/null +++ b/Assets/Cryville/Crtr/PdtBinder.cs @@ -0,0 +1,91 @@ +using Cryville.Common; +using Cryville.Common.Pdt; +using System; +using System.Globalization; +using System.Text.RegularExpressions; +using SIdentifier = Cryville.Common.Identifier; + +namespace Cryville.Crtr { + public class PdtBinder : EmptyBinder { + public override object ChangeType(object value, Type type, CultureInfo culture) { + if (value is PdtExpression) { + var exp = (PdtExpression)value; + if (type.Equals(typeof(bool))) { + bool result = false; + ChartPlayer.etor.Evaluate(new PropOp.Boolean(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(int))) { + int result = 0; + ChartPlayer.etor.Evaluate(new PropOp.Integer(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(float))) { + float result = 0; + ChartPlayer.etor.Evaluate(new PropOp.Float(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(string))) { + string result = default(string); + ChartPlayer.etor.Evaluate(new PropOp.String(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(Clip))) { + Clip result = default(Clip); + ChartPlayer.etor.Evaluate(new PropOp.Clip(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(Identifier))) { + Identifier result = default(Identifier); + ChartPlayer.etor.Evaluate(new pop_identstr(r => result = r), exp); + return result; + } + else if (type.Equals(typeof(Identifier[]))) { + Identifier[] result = null; + ChartPlayer.etor.Evaluate(new pop_identstrarr(r => result = r), exp); + return result; + } + } + else if (value is string) { + var exp = (string)value; + if (type.Equals(typeof(Identifier))) { + return (Identifier)exp; + } + else if (type == typeof(ScoreOperation)) { + var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$"); + var name = new Identifier(m.Groups[1].Value); + if (!m.Groups[2].Success) return new ScoreOperation { name = name }; + var op = new Identifier(m.Groups[2].Value); + return new ScoreOperation { name = name, op = op }; + } + } + return base.ChangeType(value, type, culture); + } +#pragma warning disable IDE1006 + class pop_identstr : PropOp { + readonly Action _cb; + public pop_identstr(Action cb) { _cb = cb; } + protected override void Execute() { + var op = GetOperand(0); + if (op.Type == PdtInternalType.Undefined) _cb(new SIdentifier(op.AsIdentifier())); + else if (op.Type == PdtInternalType.String) _cb(new SIdentifier(op.AsString())); + else throw new InvalidCastException("Not an identifier or string"); + } + } + class pop_identstrarr : PdtOperator { + readonly Action _cb; + public pop_identstrarr(Action cb) : base(16) { _cb = cb; } + protected override void Execute() { + var result = new SIdentifier[LoadedOperandCount]; + for (int i = 0; i < LoadedOperandCount; i++) { + var op = GetOperand(i); + if (op.Type != PdtInternalType.Undefined) + throw new InvalidCastException("Not an identifier"); + result[i] = new SIdentifier(op.AsIdentifier()); + } + _cb(result); + } + } +#pragma warning restore IDE1006 + } +} diff --git a/Assets/Cryville/Crtr/PdtBinder.cs.meta b/Assets/Cryville/Crtr/PdtBinder.cs.meta new file mode 100644 index 0000000..71a39f2 --- /dev/null +++ b/Assets/Cryville/Crtr/PdtBinder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ba16fc9fce48644b9c7bd49f2c9121d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cryville/Crtr/Ruleset.cs b/Assets/Cryville/Crtr/Ruleset.cs index ced1016..54d47d7 100644 --- a/Assets/Cryville/Crtr/Ruleset.cs +++ b/Assets/Cryville/Crtr/Ruleset.cs @@ -4,11 +4,8 @@ using Cryville.Crtr.Browsing; using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Text; -using System.Text.RegularExpressions; -using SIdentifier = Cryville.Common.Identifier; namespace Cryville.Crtr { public class Ruleset : MetaInfo { @@ -30,7 +27,7 @@ namespace Cryville.Crtr { } } - [Binder(typeof(PdtRulesetBinder))] + [Binder(typeof(PdtBinder))] public class PdtRuleset { public Dictionary inputs; public Dictionary judges; @@ -126,88 +123,6 @@ namespace Cryville.Crtr { Property, Variable, } - public class PdtRulesetBinder : EmptyBinder { - public override object ChangeType(object value, Type type, CultureInfo culture) { - if (value is PdtExpression) { - var exp = (PdtExpression)value; - if (type.Equals(typeof(bool))) { - bool result = false; - ChartPlayer.etor.Evaluate(new PropOp.Boolean(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(int))) { - int result = 0; - ChartPlayer.etor.Evaluate(new PropOp.Integer(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(float))) { - float result = 0; - ChartPlayer.etor.Evaluate(new PropOp.Float(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(string))) { - string result = default(string); - ChartPlayer.etor.Evaluate(new PropOp.String(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(Clip))) { - Clip result = default(Clip); - ChartPlayer.etor.Evaluate(new PropOp.Clip(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(Identifier))) { - Identifier result = default(Identifier); - ChartPlayer.etor.Evaluate(new pop_identstr(r => result = r), exp); - return result; - } - else if (type.Equals(typeof(Identifier[]))) { - Identifier[] result = null; - ChartPlayer.etor.Evaluate(new pop_identstrarr(r => result = r), exp); - return result; - } - } - else if (value is string) { - var exp = (string)value; - if (type.Equals(typeof(Identifier))) { - return (Identifier)exp; - } - else if (type == typeof(ScoreOperation)) { - var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$"); - var name = new Identifier(m.Groups[1].Value); - if (!m.Groups[2].Success) return new ScoreOperation { name = name }; - var op = new Identifier(m.Groups[2].Value); - return new ScoreOperation { name = name, op = op }; - } - } - return base.ChangeType(value, type, culture); - } -#pragma warning disable IDE1006 - class pop_identstr : PropOp { - readonly Action _cb; - public pop_identstr(Action cb) { _cb = cb; } - protected override void Execute() { - var op = GetOperand(0); - if (op.Type == PdtInternalType.Undefined) _cb(new SIdentifier(op.AsIdentifier())); - else if (op.Type == PdtInternalType.String) _cb(new SIdentifier(op.AsString())); - else throw new InvalidCastException("Not an identifier or string"); - } - } - class pop_identstrarr : PdtOperator { - readonly Action _cb; - public pop_identstrarr(Action cb) : base(16) { _cb = cb; } - protected override void Execute() { - var result = new SIdentifier[LoadedOperandCount]; - for (int i = 0; i < LoadedOperandCount; i++) { - var op = GetOperand(i); - if (op.Type != PdtInternalType.Undefined) - throw new InvalidCastException("Not an identifier"); - result[i] = new SIdentifier(op.AsIdentifier()); - } - _cb(result); - } - } -#pragma warning restore IDE1006 - } public class RulesetViolationException : Exception { public RulesetViolationException() { } public RulesetViolationException(string message) : base(message) { } diff --git a/Assets/Cryville/Crtr/Skin.cs b/Assets/Cryville/Crtr/Skin.cs index a57414d..005bb19 100644 --- a/Assets/Cryville/Crtr/Skin.cs +++ b/Assets/Cryville/Crtr/Skin.cs @@ -1,3 +1,4 @@ +using Cryville.Common; using Cryville.Common.Pdt; using Cryville.Crtr.Browsing; using Newtonsoft.Json; @@ -30,6 +31,7 @@ namespace Cryville.Crtr { } } + [Binder(typeof(PdtBinder))] public class PdtSkin : SkinElement { } public class SkinElement {