From 0684fd293d038d9e3640f3f7b77439e649be7b14 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 6 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented calculating parameters for CircleElementScheduledController. --- .../sjplayer/CircleElementScheduledController.d | 14 +++++++++++--- .../src/sjplayer/ScheduledControllerInterface.d | 11 +++++------ sjplayer/src/sjplayer/util/Parameter.d | 12 ++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 sjplayer/src/sjplayer/util/Parameter.d diff --git a/sjplayer/src/sjplayer/CircleElementScheduledController.d b/sjplayer/src/sjplayer/CircleElementScheduledController.d index d6922e9..10af18e 100644 --- a/sjplayer/src/sjplayer/CircleElementScheduledController.d +++ b/sjplayer/src/sjplayer/CircleElementScheduledController.d @@ -10,7 +10,8 @@ import sjscript; import sjplayer.CircleElement, sjplayer.ScheduledControllerFactory, sjplayer.ScheduledControllerInterface, - sjplayer.VarStoreInterface; + sjplayer.VarStoreInterface, + sjplayer.util.Parameter; /// class CircleElementScheduledController : @@ -41,8 +42,15 @@ class CircleElementScheduledController : } override void SetParameter(Nullable!float time, ref in Parameter param) { - // TODO: - super.SetParameter(time, param); + auto vars = VarStore(this, time); + switch (param.name) { + case "damage": return element_.damage. CalculateParameter(param, vars); + case "nearness_coe": return element_.nearness_coe.CalculateParameter(param, vars); + case "weight": return element_.weight. CalculateParameter(param, vars); + case "smooth": return element_.smooth. CalculateParameter(param, vars); + + default: return super.SetParameter(time, param); + } } private: diff --git a/sjplayer/src/sjplayer/ScheduledControllerInterface.d b/sjplayer/src/sjplayer/ScheduledControllerInterface.d index 54c824e..aa875ad 100644 --- a/sjplayer/src/sjplayer/ScheduledControllerInterface.d +++ b/sjplayer/src/sjplayer/ScheduledControllerInterface.d @@ -10,6 +10,7 @@ import std.algorithm, import sjscript; import sjplayer.VarStoreInterface, + sjplayer.util.Parameter, sjplayer.util.Period; /// @@ -89,6 +90,7 @@ abstract class AbstractScheduledControllerWithOperationImpl : } override void PrepareOperation(ref in ParametersBlock params) { + user_vars_.clear(); params.parameters. filter!(x => x.type == ParameterType.OnceAssign). each !(x => SetParameter(Nullable!float.init, x)); @@ -106,12 +108,9 @@ abstract class AbstractScheduledControllerWithOperationImpl : void SetParameter(Nullable!float time, ref in Parameter param) { (param.name.length >= 2 && param.name[0..2] == "__"). enforce("user defined variables must be prefixed '__'"); - - auto value = param.rhs.CalculateExpression(VarStore(this, time)); - if (param.type == ParameterType.AddAssign) { - value += user_vars_[param.name]; - } - user_vars_[param.name] = value; + user_vars_[param.name] = 0; + user_vars_[param.name]. + CalculateParameter(param, VarStore(this, time)); } private: diff --git a/sjplayer/src/sjplayer/util/Parameter.d b/sjplayer/src/sjplayer/util/Parameter.d new file mode 100644 index 0000000..6c35eeb --- /dev/null +++ b/sjplayer/src/sjplayer/util/Parameter.d @@ -0,0 +1,12 @@ +/// License: MIT +module sjplayer.util.Parameter; + +import sjscript; + +/// +void CalculateParameter(T)( + ref float value, in Parameter param, T vars) { + auto result = param.rhs.CalculateExpression(vars); + if (param.type == ParameterType.AddAssign) result += value; + value = result; +}