[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,
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:

View File

@ -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:

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