[add] Added VarStore.

This commit is contained in:
falsycat 2019-10-08 00:00:00 +00:00
parent 37a1a122e5
commit 3ac1293e06
2 changed files with 33 additions and 4 deletions

View File

@ -17,19 +17,19 @@ import sjplayer.Actor,
sjplayer.ElementInterface, sjplayer.ElementInterface,
sjplayer.ProgramSet, sjplayer.ProgramSet,
sjplayer.ScheduledControllerInterface, sjplayer.ScheduledControllerInterface,
sjplayer.VarStoreInterface; sjplayer.VarStore;
/// ///
class Context { class Context {
public: public:
/// ///
this(ParametersBlock[] params, ProgramSet programs) { this(ParametersBlock[] params, ProgramSet programs) {
auto builder = new Builder;
auto varstore = new BlackHole!VarStoreInterface;
actor_ = new Actor(programs.Get!ActorProgram); actor_ = new Actor(programs.Get!ActorProgram);
background_ = new Background(programs.Get!BackgroundProgram); background_ = new Background(programs.Get!BackgroundProgram);
auto builder = new Builder;
auto varstore = new VarStore(actor_);
import sjplayer.BackgroundScheduledController, import sjplayer.BackgroundScheduledController,
sjplayer.CircleElementScheduledController; sjplayer.CircleElementScheduledController;
auto factories = tuple( auto factories = tuple(

View File

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