From 47b1314033a99139058b689e62af554859b3191e Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 28 Oct 2022 12:00:12 +0800 Subject: [PATCH] Add BeatTime properties. --- Assets/Cryville/Crtr/Chart.cs | 6 +++++- Assets/Cryville/Crtr/PropOp.cs | 9 +++++++++ Assets/Cryville/Crtr/PropSrc.cs | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Assets/Cryville/Crtr/Chart.cs b/Assets/Cryville/Crtr/Chart.cs index e0812ee..d24beae 100644 --- a/Assets/Cryville/Crtr/Chart.cs +++ b/Assets/Cryville/Crtr/Chart.cs @@ -124,8 +124,12 @@ namespace Cryville.Crtr { protected ChartEvent() { PropSrcs = new Dictionary(); - SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong)); PropOps = new Dictionary(); + SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong)); + SubmitPropSrc("time", new PropSrc.BeatTime(() => time.Value)); + SubmitPropSrc("endtime", new PropSrc.BeatTime(() => endtime.Value)); + SubmitPropOp("time", new PropOp.BeatTime(v => time = v)); + SubmitPropOp("endtime", new PropOp.BeatTime(v => endtime = v)); } } diff --git a/Assets/Cryville/Crtr/PropOp.cs b/Assets/Cryville/Crtr/PropOp.cs index c8be61d..071208a 100644 --- a/Assets/Cryville/Crtr/PropOp.cs +++ b/Assets/Cryville/Crtr/PropOp.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using RBeatTime = Cryville.Crtr.BeatTime; namespace Cryville.Crtr { public abstract class PropOp : PdtOperator { @@ -52,6 +53,14 @@ namespace Cryville.Crtr { _cb((T)(object)result); } } + public class BeatTime : PropOp { + readonly Action _cb; + public BeatTime(Action cb) { _cb = cb; } + protected override unsafe void Execute() { + var o = GetOperand(0); + _cb(*(RBeatTime*)o.TrustedAsOfLength(sizeof(RBeatTime))); + } + } public class Vector2 : PropOp { readonly Action _cb; public Vector2(Action cb) { _cb = cb; } diff --git a/Assets/Cryville/Crtr/PropSrc.cs b/Assets/Cryville/Crtr/PropSrc.cs index b8d4195..5424cd0 100644 --- a/Assets/Cryville/Crtr/PropSrc.cs +++ b/Assets/Cryville/Crtr/PropSrc.cs @@ -1,5 +1,6 @@ using Cryville.Common.Pdt; using System; +using RBeatTime = Cryville.Crtr.BeatTime; namespace Cryville.Crtr { public abstract class PropSrc { @@ -55,5 +56,21 @@ namespace Cryville.Crtr { } } } + public class BeatTime : PropSrc { + readonly Func _cb; + public BeatTime(Func cb) { _cb = cb; } + protected override unsafe void InternalGet(out int type, out byte[] value) { + var bt = _cb(); + type = PdtInternalType.Vector; + value = new byte[4 * sizeof(int)]; + fixed (byte* _ptr = value) { + int* ptr = (int*)_ptr; + *ptr++ = bt.b; + *ptr++ = bt.n; + *ptr++ = bt.d; + *ptr++ = PdtInternalType.Number; + } + } + } } }