From 3ac1293e06c7115532d36325025e6d9ee86d5921 Mon Sep 17 00:00:00 2001 From: falsycat Date: Tue, 8 Oct 2019 00:00:00 +0000 Subject: [PATCH] [add] Added VarStore. --- sjplayer/src/sjplayer/Context.d | 8 ++++---- sjplayer/src/sjplayer/VarStore.d | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 sjplayer/src/sjplayer/VarStore.d 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_; +}