diff options
| author | RblSb <msrblsb@gmail.com> | 2024-01-05 04:14:13 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2024-01-05 04:14:13 +0300 |
| commit | bd072e03fc14aeda0eae623ee9353a7c74645081 (patch) | |
| tree | d7107fd62854dbd04f2b76af8d59205622c71ff4 /src | |
| parent | f6a89cb793ff5272f0d259b0e296b3862f0c4798 (diff) | |
Keep flashbacks in state
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/Main.hx | 37 | ||||
| -rw-r--r-- | src/server/ServerState.hx | 4 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/server/Main.hx b/src/server/Main.hx index 0da88e7..c5eb36f 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -33,6 +33,7 @@ private typedef MainOptions = { class Main { static inline var VIDEO_START_MAX_DELAY = 3000; static inline var VIDEO_SKIP_DELAY = 1000; + static inline var FLASHBACKS_COUNT = 50; static inline var FLASHBACK_DIST = 30; final rootDir = '$__dirname/..'; @@ -55,6 +56,7 @@ class Main { final videoList = new VideoList(); final videoTimer = new VideoTimer(); final messages:Array<Message> = []; + final flashbacks:Array<FlashbackItem> = []; final logger:Logger; static function main():Void { @@ -262,7 +264,8 @@ class Main { timer: { time: videoTimer.getTime(), paused: videoTimer.isPaused() - } + }, + flashbacks: flashbacks } } @@ -270,16 +273,19 @@ class Main { if (isNoState) return; if (!FileSystem.exists(statePath)) return; trace("Loading state..."); - final data:ServerState = Json.parse(File.getContent(statePath)); - videoList.setItems(data.videoList); + final state:ServerState = Json.parse(File.getContent(statePath)); + videoList.setItems(state.videoList); + videoList.isOpen = state.isPlaylistOpen; + videoList.setPos(state.itemPos); + messages.resize(0); - videoList.isOpen = data.isPlaylistOpen; - videoList.setPos(data.itemPos); - for (message in data.messages) { - messages.push(message); - } + for (message in state.messages) messages.push(message); + + flashbacks.resize(0); + for (flashback in state.flashbacks ?? []) flashbacks.push(flashback); + videoTimer.start(); - videoTimer.setTime(data.timer.time); + videoTimer.setTime(state.timer.time); videoTimer.pause(); } @@ -1016,26 +1022,23 @@ class Main { return findFlashbackItem(url, duration)?.time ?? 0.0; } - final flashbackTimes:Array<FlashbackItem> = []; - function findFlashbackItem(url:String, ?duration:Float):Null<FlashbackItem> { - var item = flashbackTimes.find(item -> item.url == url); + var item = flashbacks.find(item -> item.url == url); // if there is no url match, find recent flashback item with same duration if (duration != null && item == null) { - item = flashbackTimes.find(item -> item.duration == duration); + item = flashbacks.find(item -> item.duration == duration); } return item; } function addRecentFlashback(url:String, duration:Float, time:Float):Void { - flashbackTimes.remove(findFlashbackItem(url)); - flashbackTimes.unshift({ + flashbacks.remove(findFlashbackItem(url)); + flashbacks.unshift({ url: url, duration: duration, time: time }); - final length = flashbackTimes.count(); - if (length > 10) flashbackTimes.pop(); + while (flashbacks.length > FLASHBACKS_COUNT) flashbacks.pop(); } function isPlaylistLockedFor(client:Client):Bool { diff --git a/src/server/ServerState.hx b/src/server/ServerState.hx index 4ccdd44..0369353 100644 --- a/src/server/ServerState.hx +++ b/src/server/ServerState.hx @@ -1,5 +1,6 @@ package server; +import Types.FlashbackItem; import Types.Message; import Types.VideoItem; @@ -10,5 +11,6 @@ typedef ServerState = { messages:Array<Message>, timer:{ time:Float, paused:Bool - } + }, + ?flashbacks:Array<FlashbackItem> } |
