Add judge action fields on_hit and on_miss.

This commit is contained in:
2023-05-20 16:23:59 +08:00
parent d1b9b9607b
commit 25b4f3ccb7
5 changed files with 151 additions and 42 deletions

View File

@@ -6,7 +6,9 @@ using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Cryville.Crtr {
public class Ruleset : MetaInfo {
@@ -44,13 +46,8 @@ namespace Cryville.Crtr {
foreach (var j in judges.Judges) {
var judge = j.Value;
if (judge.hit != null) etor.Optimize(judge.hit);
if (judge.scores != null) {
foreach (var s in judge.scores) {
if (s.Key.op != default(Identifier))
PdtExpression.PatchCompound(s.Key.name.Key, s.Key.op.Key, s.Value);
etor.Optimize(s.Value);
}
}
if (judge.on_hit != null) OptimizeJudgeActions(judge.on_hit, etor);
if (judge.on_miss != null) OptimizeJudgeActions(judge.on_miss, etor);
}
foreach (var a in judges.Areas) {
etor.Optimize(a.Value);
@@ -61,6 +58,9 @@ namespace Cryville.Crtr {
}
constraints.Optimize(etor);
}
void OptimizeJudgeActions(PairList<JudgeAction, PdtExpression> actions, PdtEvaluatorBase etor) {
foreach (var a in actions) a.Key.Optimize(etor, a.Value);
}
public void PrePatch(Chart chart) {
constraints.PrePatch(chart);
}
@@ -83,10 +83,32 @@ namespace Cryville.Crtr {
public PdtExpression clip;
public PdtExpression input;
public PdtExpression hit;
public PdtExpression persist; // TODO Compat
public Identifier[] pass; // TODO Compat
public Identifier[] miss; // TODO Compat
public PairList<ScoreOperation, PdtExpression> scores; // TODO Compat
public PdtExpression persist;
public PairList<JudgeAction, PdtExpression> on_hit;
public PairList<JudgeAction, PdtExpression> on_miss;
#pragma warning disable IDE1006
public PairList<ScoreOperation, PdtExpression> scores {
set {
if (on_hit == null) on_hit = new PairList<JudgeAction, PdtExpression>();
int i = 0;
foreach (var s in value) {
on_hit.Insert(i++, new JudgeAction.Score(s.Key), s.Value);
}
}
}
public Identifier[] pass {
set {
if (on_hit == null) on_hit = new PairList<JudgeAction, PdtExpression>();
on_hit.Add(new JudgeAction.Pass(Enumerable.Empty<string>(), value), PdtExpression.Empty);
}
}
public Identifier[] miss {
set {
if (on_miss == null) on_miss = new PairList<JudgeAction, PdtExpression>();
on_miss.Add(new JudgeAction.Pass(Enumerable.Empty<string>(), value), PdtExpression.Empty);
}
}
#pragma warning restore IDE1006
}
public class ScoreOperation {
public Identifier name;