Tokenize ruleset keys. Remove MotionName.

This commit is contained in:
2022-11-09 14:01:27 +08:00
parent 55efc7a428
commit c33186086c
13 changed files with 153 additions and 112 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using SIdentifier = Cryville.Common.Identifier;
namespace Cryville.Crtr {
public class Ruleset {
@@ -31,9 +32,9 @@ namespace Cryville.Crtr {
[Binder(typeof(PdtRulesetBinder))]
public class PdtRuleset {
public Dictionary<string, InputDefinition> inputs;
public Dictionary<string, JudgeDefinition> judges;
public Dictionary<string, ScoreDefinition> scores;
public Dictionary<Identifier, InputDefinition> inputs;
public Dictionary<Identifier, JudgeDefinition> judges;
public Dictionary<Identifier, ScoreDefinition> scores;
public Constraint constraints;
public void Optimize(PdtEvaluatorBase etor) {
foreach (var i in inputs.Values) {
@@ -142,39 +143,50 @@ namespace Cryville.Crtr {
return result;
}
else if (type.Equals(typeof(string))) {
string result = null;
string result = default(string);
ChartPlayer.etor.Evaluate(new PropOp.String(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(string[]))) {
string[] result = null;
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;
}
}
return base.ChangeType(value, type, culture);
}
#pragma warning disable IDE1006
class pop_identstr : PropOp {
readonly Action<string> _cb;
public pop_identstr(Action<string> cb) { _cb = cb; }
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((string)IdentifierManager.SharedInstance.Retrieve(op.AsIdentifier()));
else if (op.Type == PdtInternalType.String) _cb(op.AsString());
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<string[]> _cb;
public pop_identstrarr(Action<string[]> cb) : base(16) { _cb = cb; }
readonly Action<SIdentifier[]> _cb;
public pop_identstrarr(Action<SIdentifier[]> cb) : base(16) { _cb = cb; }
protected override void Execute() {
var result = new string[LoadedOperandCount];
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] = (string)IdentifierManager.SharedInstance.Retrieve(op.AsIdentifier());
result[i] = new SIdentifier(op.AsIdentifier());
}
_cb(result);
}