diff --git a/sjplayer/src/sjplayer/AbstractScheduledController.d b/sjplayer/src/sjplayer/AbstractScheduledController.d index 7a3b300..9949565 100644 --- a/sjplayer/src/sjplayer/AbstractScheduledController.d +++ b/sjplayer/src/sjplayer/AbstractScheduledController.d @@ -2,7 +2,9 @@ module sjplayer.AbstractScheduledController; import std.algorithm, + std.array, std.exception, + std.range.primitives, std.typecons; import sjscript; @@ -103,3 +105,16 @@ abstract class AbstractScheduledController : ScheduledControllerInterface { float[string] user_vars_; } + +/// +ParametersBlock[] SortParametersBlock(R)(R params) + if (isInputRange!R && is(ElementType!R == ParametersBlock)) { + auto result = params.array; + result.sort!"a.period.start < b.period.start"; + + auto before = Period(-1, 0); + foreach (param; result) { + (!param.period.IsPeriodIntersectedToPeriod(before)).enforce(); + } + return result; +} diff --git a/sjplayer/src/sjplayer/BackgroundScheduledController.d b/sjplayer/src/sjplayer/BackgroundScheduledController.d index 900205f..284c1fe 100644 --- a/sjplayer/src/sjplayer/BackgroundScheduledController.d +++ b/sjplayer/src/sjplayer/BackgroundScheduledController.d @@ -8,7 +8,8 @@ import std.algorithm, import sjscript; -import sjplayer.Background, +import sjplayer.AbstractScheduledController, + sjplayer.Background, sjplayer.ContextBuilderInterface, sjplayer.ScheduledController, sjplayer.VarStoreInterface, @@ -45,16 +46,8 @@ struct BackgroundScheduledControllerFactory { /// void Create(R)(R params, ContextBuilderInterface builder) if (isInputRange!R && is(ElementType!R == ParametersBlock)) { - auto params_array = params.array; - params_array.sort!"a.period.start < b.period.start"; - - auto before = Period(-1, 0); - foreach (param; params_array) { - (!param.period.IsPeriodIntersectedToPeriod(before)).enforce(); - } - auto ctrl = new BackgroundScheduledController( - background_, varstore_, params_array); + background_, varstore_, SortParametersBlock(params)); builder.AddScheduledController(ctrl); }