Pull up PdtBinder.
This commit is contained in:
91
Assets/Cryville/Crtr/PdtBinder.cs
Normal file
91
Assets/Cryville/Crtr/PdtBinder.cs
Normal file
@@ -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<SIdentifier> _cb;
|
||||||
|
public pop_identstr(Action<SIdentifier> 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<SIdentifier[]> _cb;
|
||||||
|
public pop_identstrarr(Action<SIdentifier[]> 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
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/PdtBinder.cs.meta
Normal file
11
Assets/Cryville/Crtr/PdtBinder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7ba16fc9fce48644b9c7bd49f2c9121d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -4,11 +4,8 @@ using Cryville.Crtr.Browsing;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using SIdentifier = Cryville.Common.Identifier;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Ruleset : MetaInfo {
|
public class Ruleset : MetaInfo {
|
||||||
@@ -30,7 +27,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Binder(typeof(PdtRulesetBinder))]
|
[Binder(typeof(PdtBinder))]
|
||||||
public class PdtRuleset {
|
public class PdtRuleset {
|
||||||
public Dictionary<Identifier, InputDefinition> inputs;
|
public Dictionary<Identifier, InputDefinition> inputs;
|
||||||
public Dictionary<Identifier, JudgeDefinition> judges;
|
public Dictionary<Identifier, JudgeDefinition> judges;
|
||||||
@@ -126,88 +123,6 @@ namespace Cryville.Crtr {
|
|||||||
Property,
|
Property,
|
||||||
Variable,
|
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<SIdentifier> _cb;
|
|
||||||
public pop_identstr(Action<SIdentifier> 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<SIdentifier[]> _cb;
|
|
||||||
public pop_identstrarr(Action<SIdentifier[]> 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 class RulesetViolationException : Exception {
|
||||||
public RulesetViolationException() { }
|
public RulesetViolationException() { }
|
||||||
public RulesetViolationException(string message) : base(message) { }
|
public RulesetViolationException(string message) : base(message) { }
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Crtr.Browsing;
|
using Cryville.Crtr.Browsing;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -30,6 +31,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Binder(typeof(PdtBinder))]
|
||||||
public class PdtSkin : SkinElement { }
|
public class PdtSkin : SkinElement { }
|
||||||
|
|
||||||
public class SkinElement {
|
public class SkinElement {
|
||||||
|
Reference in New Issue
Block a user