Draft config definition.

This commit is contained in:
2023-07-27 15:59:56 +08:00
parent ba2f1d4858
commit 86da71f2cb
3 changed files with 31 additions and 1 deletions

View File

@@ -29,6 +29,11 @@ namespace Cryville.Crtr {
ChartPlayer.etor.Evaluate(new PropOp.String(r => result = r), exp);
return result;
}
else if (type.IsEnum) {
object result = null;
ChartPlayer.etor.Evaluate(new PropOp.Enum(type, 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);

View File

@@ -100,6 +100,26 @@ namespace Cryville.Crtr {
_cb(GetOperand(0).AsIdentifier());
}
}
public class Enum : PropOp {
readonly Type _type;
readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
readonly Action<object> _cb;
public Enum(Type type, Action<object> cb) {
if (!type.IsEnum)
throw new ArgumentException("Type is not enum");
_type = type;
var names = type.GetFields(BindingFlags.Public | BindingFlags.Static);
for (int i = 0; i < names.Length; i++)
_cache[IdentifierManager.Shared.Request(names[i].Name)] = Convert.ToInt32(names[i].GetValue(null));
_cb = cb;
}
protected override void Execute() {
int result = 0;
for (int i = 0; i < LoadedOperandCount; i++)
result |= _cache[GetOperand(i).AsIdentifier()];
_cb(System.Enum.ToObject(_type, result));
}
}
public class Enum<T> : PropOp {
static readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
readonly Action<T> _cb;

View File

@@ -69,7 +69,12 @@ namespace Cryville.Crtr {
}
}
public class ConfigDefinition {
// TODO
public ConfigType type;
public PdtExpression @default;
public PdtExpression value;
}
public enum ConfigType {
none, number,
}
public class MotionDefinition {
// TODO