From e1eac4cf85d7a6f272271663adcda3af7dec2cb7 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 6 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented creating Context for `sjplayer`. --- sjplayer/src/sjplayer/Context.d | 28 ++++++++++++++++++++++++++-- sjplayer/src/sjplayer/package.d | 3 +-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index 7e4620f..36ef82b 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -1,10 +1,15 @@ /// License: MIT module sjplayer.Context; -import std.algorithm; +import std.algorithm, + std.typecons; + +import sjscript; import sjplayer.ElementInterface, - sjplayer.ScheduledControllerInterface; + sjplayer.ElementProgramSet, + sjplayer.ScheduledControllerInterface, + sjplayer.VarStoreInterface; /// struct Context { @@ -12,6 +17,25 @@ struct Context { @disable this(); @disable this(this); + /// + this(ParametersBlock[] params, ElementProgramSet programs) { + auto varstore = new BlackHole!VarStoreInterface; + + import sjplayer.CircleElementScheduledController; + auto factories = tuple( + tuple( + "circle", + CircleElementScheduledControllerFactory(programs, varstore), + ), + ); + foreach (factory; factories) { + auto result = factory[1]. + Create(params.filter!(x => x.name == factory[0])); + elements_ ~= result.elements; + drawers_ ~= result.drawer; + controllers_ ~= result.controllers; + } + } /// ~this() { controllers_.each!destroy; diff --git a/sjplayer/src/sjplayer/package.d b/sjplayer/src/sjplayer/package.d index 5a2cbf1..285fc8e 100644 --- a/sjplayer/src/sjplayer/package.d +++ b/sjplayer/src/sjplayer/package.d @@ -15,6 +15,5 @@ Context CreateContextFromText(string src, ElementProgramSet programs) { /// Context CreateContextFromScriptAst( ParametersBlock[] params, ElementProgramSet programs) { - // TODO: - assert(false); + return Context(params, programs); }