[update] Implemented calculating parameters for CircleElementScheduledController.

This commit is contained in:
falsycat 2019-10-06 00:00:00 +00:00
parent 5f2317c6eb
commit 0684fd293d
3 changed files with 28 additions and 9 deletions

View File

@ -10,7 +10,8 @@ import sjscript;
import sjplayer.CircleElement, import sjplayer.CircleElement,
sjplayer.ScheduledControllerFactory, sjplayer.ScheduledControllerFactory,
sjplayer.ScheduledControllerInterface, sjplayer.ScheduledControllerInterface,
sjplayer.VarStoreInterface; sjplayer.VarStoreInterface,
sjplayer.util.Parameter;
/// ///
class CircleElementScheduledController : class CircleElementScheduledController :
@ -41,8 +42,15 @@ class CircleElementScheduledController :
} }
override void SetParameter(Nullable!float time, ref in Parameter param) { override void SetParameter(Nullable!float time, ref in Parameter param) {
// TODO: auto vars = VarStore(this, time);
super.SetParameter(time, param); 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: private:

View File

@ -10,6 +10,7 @@ import std.algorithm,
import sjscript; import sjscript;
import sjplayer.VarStoreInterface, import sjplayer.VarStoreInterface,
sjplayer.util.Parameter,
sjplayer.util.Period; sjplayer.util.Period;
/// ///
@ -89,6 +90,7 @@ abstract class AbstractScheduledControllerWithOperationImpl :
} }
override void PrepareOperation(ref in ParametersBlock params) { override void PrepareOperation(ref in ParametersBlock params) {
user_vars_.clear();
params.parameters. params.parameters.
filter!(x => x.type == ParameterType.OnceAssign). filter!(x => x.type == ParameterType.OnceAssign).
each !(x => SetParameter(Nullable!float.init, x)); each !(x => SetParameter(Nullable!float.init, x));
@ -106,12 +108,9 @@ abstract class AbstractScheduledControllerWithOperationImpl :
void SetParameter(Nullable!float time, ref in Parameter param) { void SetParameter(Nullable!float time, ref in Parameter param) {
(param.name.length >= 2 && param.name[0..2] == "__"). (param.name.length >= 2 && param.name[0..2] == "__").
enforce("user defined variables must be prefixed '__'"); enforce("user defined variables must be prefixed '__'");
user_vars_[param.name] = 0;
auto value = param.rhs.CalculateExpression(VarStore(this, time)); user_vars_[param.name].
if (param.type == ParameterType.AddAssign) { CalculateParameter(param, VarStore(this, time));
value += user_vars_[param.name];
}
user_vars_[param.name] = value;
} }
private: private:

View File

@ -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;
}