[add] Added VarStoreScheduledController.

This commit is contained in:
2019-10-14 00:00:00 +00:00
parent ffcd02066e
commit ccb7d79b67
6 changed files with 90 additions and 12 deletions

View File

@@ -74,8 +74,7 @@ abstract class AbstractScheduledController : ScheduledControllerInterface {
}
auto temp = varstore_[name];
if (!temp.isNull) return temp;
// TODO: std constants
return Nullable!float.init;
return StandardVarStore.GetByName(name);
}
void SetParameter(ref in Parameter param, ref in VarStore vars) {
if (param.name.length < 2 || param.name[0..2] != "__") {

View File

@@ -21,7 +21,8 @@ import sjplayer.Actor,
sjplayer.PostEffectControllerInterface,
sjplayer.ProgramSet,
sjplayer.ScheduledControllerInterface,
sjplayer.VarStore;
sjplayer.VarStore,
sjplayer.VarStoreScheduledController;
///
class Context {
@@ -55,6 +56,10 @@ class Context {
"circle",
CircleElementScheduledControllerFactory(programs, varstore),
),
tuple(
"variable",
VarStoreScheduledControllerFactory(varstore),
),
);
foreach (ref factory; factories) {
factory[1].

View File

@@ -21,10 +21,19 @@ class VarStore : VarStoreInterface {
case "actor_x": return Nullable!float(actor_.pos.x);
case "actor_y": return Nullable!float(actor_.pos.y);
default: return Nullable!float.init;
default:
}
return name in user_vars_?
Nullable!float(user_vars_[name]): Nullable!float.init;
}
///
void opIndexAssign(float value, string name) {
user_vars_[name] = value;
}
private:
const Actor actor_;
float[string] user_vars_;
}

View File

@@ -0,0 +1,56 @@
/// License: MIT
module sjplayer.VarStoreScheduledController;
import std.range.primitives;
import sjscript;
import sjplayer.AbstractScheduledController,
sjplayer.ContextBuilderInterface,
sjplayer.VarStore,
sjplayer.util.Parameter;
///
class VarStoreScheduledController : AbstractScheduledController {
public:
///
alias VarStore = sjplayer.VarStore.VarStore;
///
this(VarStore varstore, in ParametersBlock[] operations) {
super(varstore, operations);
varstore_ = varstore;
}
override void SetParameter(
ref in Parameter param,
ref in AbstractScheduledController.VarStore vars) {
const x_nullable = varstore_[param.name];
auto x = x_nullable.isNull? 0f: x_nullable.get;
param.CalculateParameter(x, vars);
varstore_[param.name] = x;
}
private:
VarStore varstore_;
}
///
struct VarStoreScheduledControllerFactory {
public:
///
this(VarStore varstore) {
varstore_ = varstore;
}
///
void Create(R)(R params, ContextBuilderInterface builder)
if (isInputRange!R && is(ElementType!R == ParametersBlock)) {
auto product = new VarStoreScheduledController(
varstore_, SortParametersBlock(params));
builder.AddScheduledController(product);
}
private:
VarStore varstore_;
}