diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index 93999c5..20535d0 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -17,19 +17,19 @@ import sjplayer.Actor, sjplayer.ElementInterface, sjplayer.ProgramSet, sjplayer.ScheduledControllerInterface, - sjplayer.VarStoreInterface; + sjplayer.VarStore; /// class Context { public: /// this(ParametersBlock[] params, ProgramSet programs) { - auto builder = new Builder; - auto varstore = new BlackHole!VarStoreInterface; - actor_ = new Actor(programs.Get!ActorProgram); background_ = new Background(programs.Get!BackgroundProgram); + auto builder = new Builder; + auto varstore = new VarStore(actor_); + import sjplayer.BackgroundScheduledController, sjplayer.CircleElementScheduledController; auto factories = tuple( diff --git a/sjplayer/src/sjplayer/VarStore.d b/sjplayer/src/sjplayer/VarStore.d new file mode 100644 index 0000000..e583132 --- /dev/null +++ b/sjplayer/src/sjplayer/VarStore.d @@ -0,0 +1,29 @@ +/// License: MIT +module sjplayer.VarStore; + +import std.exception, + std.format; + +import sjplayer.Actor, + sjplayer.VarStoreInterface; + +/// +class VarStore : VarStoreInterface { + public: + /// + this(in Actor actor) { + actor_ = actor; + } + + override float opIndex(string name) const { + switch (name) { + case "actor_x": return actor_.pos.x; + case "actor_y": return actor_.pos.y; + + default: throw new Exception("unknown variable %s".format(name)); + } + } + + private: + const Actor actor_; +}