Implement input name evaluation. Implement context state.

This commit is contained in:
2022-11-11 10:01:24 +08:00
parent 84e4e3514d
commit cf00bd8db0
7 changed files with 46 additions and 11 deletions

View File

@@ -397,14 +397,20 @@ namespace Cryville.Crtr {
} }
public class Judge : ChartEvent { public class Judge : ChartEvent {
public string name; [JsonIgnore]
public Identifier Id;
public string name {
get { return Id.ToString(); }
set { Id = new Identifier(value); }
}
public override int Priority { public override int Priority {
get { return 0; } get { return 0; }
} }
public Judge() { public Judge() {
SubmitPropSrc("name", new PropSrc.String(() => name)); SubmitPropSrc("name", new PropSrc.Identifier(() => Id.Key));
SubmitPropOp("name", new PropOp.String(v => name = v)); SubmitPropOp("name", new PropOp.Identifier(v => Id = new Identifier(v)));
} }
} }

View File

@@ -518,7 +518,7 @@ namespace Cryville.Crtr {
foreach (var ts in gs.Value.Children) { foreach (var ts in gs.Value.Children) {
ContainerHandler th; ContainerHandler th;
if (ts.Key is Chart.Note) { if (ts.Key is Chart.Note) {
th = new NoteHandler(gh, (Chart.Note)ts.Key, judge); th = new NoteHandler(gh, (Chart.Note)ts.Key, pruleset, judge);
} }
else { else {
th = new TrackHandler(gh, (Chart.Track)ts.Key); th = new TrackHandler(gh, (Chart.Track)ts.Key);

View File

@@ -214,27 +214,31 @@ namespace Cryville.Crtr.Event {
this.judge = judge; this.judge = judge;
} }
public T GetRawValue<T>(Identifier key) where T : Vector { public Vector GetRawValue(Identifier key) {
Vector tr; Vector tr;
if (!CachedValues.TryGetValue(key, out tr)) { if (!CachedValues.TryGetValue(key, out tr)) {
tr = (Vector)ReflectionHelper.InvokeEmptyConstructor(typeof(T)); tr = (Vector)ReflectionHelper.InvokeEmptyConstructor(ChartPlayer.motionRegistry[key].Type);
CachedValues.Add(key, tr); CachedValues.Add(key, tr);
CachedValueStates[key] = false; CachedValueStates[key] = false;
} }
T r = (T)tr; Vector r = tr;
#if !DISABLE_CACHE #if !DISABLE_CACHE
if (CachedValueStates[key]) return r; if (CachedValueStates[key]) return r;
#endif #endif
float reltime = 0; float reltime = 0;
if (rootPrototype != null) reltime = Time - rootPrototype.Time; if (rootPrototype != null) reltime = Time - rootPrototype.Time;
GetMotionValue(key).GetValue(reltime, ref r); GetMotionValue(key).GetValue(reltime, ref r);
if (Parent != null) r.ApplyFrom(Parent.GetRawValue<T>(key)); if (Parent != null) r.ApplyFrom(Parent.GetRawValue(key));
#if !DISABLE_CACHE #if !DISABLE_CACHE
CachedValueStates[key] = true; CachedValueStates[key] = true;
#endif #endif
return r; return r;
} }
public T GetRawValue<T>(Identifier key) where T : Vector {
return (T)GetRawValue(key);
}
static readonly Identifier n_pt = new Identifier("pt"); static readonly Identifier n_pt = new Identifier("pt");
public Vector2 ScreenPoint { public Vector2 ScreenPoint {
get { get {

View File

@@ -50,7 +50,6 @@ namespace Cryville.Crtr {
public class JudgeDefinition { public class JudgeDefinition {
public PdtExpression clip; public PdtExpression clip;
public PdtExpression input; public PdtExpression input;
public Identifier InputName;
public PdtExpression hit; public PdtExpression hit;
public Identifier[] pass; public Identifier[] pass;
public Identifier miss; public Identifier miss;

View File

@@ -1,3 +1,4 @@
using Cryville.Common;
using Cryville.Common.Math; using Cryville.Common.Math;
using Cryville.Crtr.Components; using Cryville.Crtr.Components;
using Cryville.Crtr.Event; using Cryville.Crtr.Event;
@@ -9,10 +10,12 @@ namespace Cryville.Crtr {
class NoteHandler : ContainerHandler { class NoteHandler : ContainerHandler {
readonly GroupHandler gh; readonly GroupHandler gh;
public readonly Chart.Note Event; public readonly Chart.Note Event;
readonly PdtRuleset ruleset;
readonly Judge judge; readonly Judge judge;
public NoteHandler(GroupHandler gh, Chart.Note ev, Judge j) : base() { public NoteHandler(GroupHandler gh, Chart.Note ev, PdtRuleset rs, Judge j) : base() {
this.gh = gh; this.gh = gh;
Event = ev; Event = ev;
ruleset = rs;
judge = j; judge = j;
} }
@@ -90,6 +93,15 @@ namespace Cryville.Crtr {
else if (s.CloneType == 16) { else if (s.CloneType == 16) {
if (ev == null) { } if (ev == null) { }
else if (ev.Unstamped == null) { } else if (ev.Unstamped == null) { }
else if (ev.Unstamped is Chart.Judge) {
var tev = (Chart.Judge)ev.Unstamped;
Identifier name;
ChartPlayer.etor.ContextEvent = tev;
ChartPlayer.etor.ContextState = s;
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => name = new Identifier(v)), ruleset.judges[tev.Id].input);
ChartPlayer.etor.ContextState = null;
ChartPlayer.etor.ContextEvent = null;
}
else if (ev.Unstamped is Chart.Motion) { else if (ev.Unstamped is Chart.Motion) {
/*var tev = (Chart.Motion)ev.Unstamped; /*var tev = (Chart.Motion)ev.Unstamped;
if (tev.Name != "judge") return; if (tev.Name != "judge") return;

View File

@@ -1,5 +1,6 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using Cryville.Crtr.Event;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@@ -20,11 +21,16 @@ namespace Cryville.Crtr {
else if (name == _var_true) { LoadNum(1); type = PdtInternalType.Number; value = _numbuf; } else if (name == _var_true) { LoadNum(1); type = PdtInternalType.Number; value = _numbuf; }
else if (name == _var_false) { LoadNum(0); type = PdtInternalType.Number; value = _numbuf; } else if (name == _var_false) { LoadNum(0); type = PdtInternalType.Number; value = _numbuf; }
else { else {
var id = new Identifier(name);
PropSrc prop; PropSrc prop;
string str; string str;
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) { if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) {
prop.Get(out type, out value); prop.Get(out type, out value);
} }
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(id)) {
var vec = ContextState.GetRawValue(id);
new VectorSrc(() => vec).Get(out type, out value);
}
else if (ContextJudge != null && ContextJudge.GetFormattedScoreStrings().TryGetValue(name, out str)) { else if (ContextJudge != null && ContextJudge.GetFormattedScoreStrings().TryGetValue(name, out str)) {
type = PdtInternalType.String; type = PdtInternalType.String;
value = GetBytes(str); value = GetBytes(str);
@@ -41,7 +47,6 @@ namespace Cryville.Crtr {
value = _numbuf; value = _numbuf;
} }
} }
return;
} }
} }
unsafe void LoadNum(int value) { unsafe void LoadNum(int value) {
@@ -93,6 +98,7 @@ namespace Cryville.Crtr {
} }
public ChartEvent ContextEvent { private get; set; } public ChartEvent ContextEvent { private get; set; }
public ContainerState ContextState { private get; set; }
public Transform ContextTransform { private get; set; } public Transform ContextTransform { private get; set; }
public Judge ContextJudge { private get; set; } public Judge ContextJudge { private get; set; }
public PropSrc ContextSelfValue { private get; set; } public PropSrc ContextSelfValue { private get; set; }

View File

@@ -56,6 +56,14 @@ namespace Cryville.Crtr {
} }
} }
} }
public class Identifier : PropSrc {
readonly Func<int> _cb;
public Identifier(Func<int> cb) { _cb = cb; }
protected override void InternalGet(out int type, out byte[] value) {
type = PdtInternalType.Undefined;
value = BitConverter.GetBytes(_cb());
}
}
public class BeatTime : PropSrc { public class BeatTime : PropSrc {
readonly Func<RBeatTime> _cb; readonly Func<RBeatTime> _cb;
public BeatTime(Func<RBeatTime> cb) { _cb = cb; } public BeatTime(Func<RBeatTime> cb) { _cb = cb; }