[add] Added VarStore.
This commit is contained in:
parent
37a1a122e5
commit
3ac1293e06
@ -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(
|
||||
|
29
sjplayer/src/sjplayer/VarStore.d
Normal file
29
sjplayer/src/sjplayer/VarStore.d
Normal 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_;
|
||||
}
|
Reference in New Issue
Block a user