From d20eb2dafed68f1b620047bdf5d7522a6f95104f Mon Sep 17 00:00:00 2001 From: fohristiwhirl Date: Sun, 4 Nov 2018 00:35:13 +0000 Subject: [PATCH] autoplay --- fluorine_renderer.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ fluorine_select.js | 7 +++++++ fluorine_turn.js | 7 +++++++ main.js | 27 ++++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/fluorine_renderer.js b/fluorine_renderer.js index 4e4d2d6..bd91d14 100644 --- a/fluorine_renderer.js +++ b/fluorine_renderer.js @@ -44,6 +44,8 @@ function make_renderer() { renderer.flog = null; renderer.flog_colours = null; + renderer.autoplay_iid = null; + renderer.production_list = null; renderer.dropoff_list = null; renderer.sid_pid_map = null; @@ -97,6 +99,8 @@ function make_renderer() { renderer.open = (filename, fail_silently) => { + renderer.stop_autoplay(); + // FIXME: loading zstd is done async so this test isn't sound... if (renderer.filename === filename && (new Date()).getTime() - renderer.loadtime < 5000) { @@ -832,6 +836,39 @@ function make_renderer() { renderer.go_to_turn(renderer.turn + n); }; + renderer.stop_autoplay = () => { + if (renderer.autoplay_iid !== null) { + clearInterval(renderer.autoplay_iid); + } + renderer.autoplay_iid = null; + }; + + renderer.toggle_autoplay = () => { + + // Toggle off... + + if (renderer.autoplay_iid !== null) { + clearInterval(renderer.autoplay_iid); + renderer.autoplay_iid = null; + return; + } + + // Toggle on... + + renderer.autoplay_iid = setInterval(() => { + if (!renderer.game) { + renderer.stop_autoplay(); + return; + } + renderer.turn += 1; + if (renderer.turn >= renderer.game_length()) { + renderer.turn = renderer.game_length() - 1; + renderer.stop_autoplay(); + } + renderer.draw(); + }, 50); + }; + renderer.right = (n) => { renderer.offset_x += n; renderer.draw(); @@ -1996,6 +2033,14 @@ ipcRenderer.on("go_to_turn", (event, n) => { renderer.go_to_turn(n); }); +ipcRenderer.on("toggle_autoplay", () => { + renderer.toggle_autoplay(); +}); + +ipcRenderer.on("stop_autoplay", () => { + renderer.stop_autoplay(); +}); + ipcRenderer.on("right", (event, n) => { renderer.right(n); }); diff --git a/fluorine_select.js b/fluorine_select.js index 049e56b..15b76bc 100644 --- a/fluorine_select.js +++ b/fluorine_select.js @@ -18,6 +18,13 @@ document.getElementById("sid").onkeydown = function(event) { input_sid.value = ""; if (!Number.isNaN(sid)) { + + ipcRenderer.send("relay", { + receiver: "renderer", + channel: "stop_autoplay", + content: null, + }); + ipcRenderer.send("relay", { receiver: "renderer", channel: "select_sid", diff --git a/fluorine_turn.js b/fluorine_turn.js index 52e61ac..52447d8 100644 --- a/fluorine_turn.js +++ b/fluorine_turn.js @@ -18,6 +18,13 @@ document.getElementById("turn").onkeydown = function(event) { input_turn.value = ""; if (!Number.isNaN(turn)) { + + ipcRenderer.send("relay", { + receiver: "renderer", + channel: "stop_autoplay", + content: null, + }); + ipcRenderer.send("relay", { receiver: "renderer", channel: "go_to_turn", diff --git a/main.js b/main.js index a5f4308..2d188bf 100644 --- a/main.js +++ b/main.js @@ -221,6 +221,7 @@ function make_main_menu() { label: "Open...", accelerator: "CommandOrControl+O", click: () => { + windows.send("renderer", "stop_autoplay", null); let files = electron.dialog.showOpenDialog({ defaultPath: prefs.last_replay_directory, properties: ["openFile"] @@ -241,6 +242,7 @@ function make_main_menu() { checked: false, // Updated by monitor_dirs() accelerator: "CommandOrControl+Shift+O", click: () => { + windows.send("renderer", "stop_autoplay", null); monitor_dirs(electron.dialog.showOpenDialog({ defaultPath: prefs.last_replay_directory, properties: ["openDirectory", "multiSelections"], @@ -260,6 +262,7 @@ function make_main_menu() { { label: "Open f-log...", click: () => { + windows.send("renderer", "stop_autoplay", null); let files = electron.dialog.showOpenDialog({ defaultPath: prefs.last_flog_directory, properties: ["openFile"] @@ -273,6 +276,7 @@ function make_main_menu() { { label: "What is an f-log?", click: () => { + windows.send("renderer", "stop_autoplay", null); about_flogging(); } }, @@ -283,6 +287,7 @@ function make_main_menu() { label: "Save decompressed JSON", accelerator: "CommandOrControl+S", click: () => { + windows.send("renderer", "stop_autoplay", null); let outfilename = electron.dialog.showSaveDialog(); if (outfilename) { windows.send("renderer", "save", outfilename); @@ -292,6 +297,7 @@ function make_main_menu() { { label: "Save current frame", click: () => { + windows.send("renderer", "stop_autoplay", null); let outfilename = electron.dialog.showSaveDialog(); if (outfilename) { windows.send("renderer", "save_frame", outfilename); @@ -301,6 +307,7 @@ function make_main_menu() { { label: "Save current entities", click: () => { + windows.send("renderer", "stop_autoplay", null); let outfilename = electron.dialog.showSaveDialog(); if (outfilename) { windows.send("renderer", "save_entities", outfilename); @@ -310,6 +317,7 @@ function make_main_menu() { { label: "Save upcoming moves", click: () => { + windows.send("renderer", "stop_autoplay", null); let outfilename = electron.dialog.showSaveDialog(); if (outfilename) { windows.send("renderer", "save_moves", outfilename); @@ -319,6 +327,7 @@ function make_main_menu() { { label: "Save upcoming events", click: () => { + windows.send("renderer", "stop_autoplay", null); let outfilename = electron.dialog.showSaveDialog(); if (outfilename) { windows.send("renderer", "save_events", outfilename); @@ -341,6 +350,7 @@ function make_main_menu() { label: "Forward", accelerator: "Right", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "forward", 1); } }, @@ -348,6 +358,7 @@ function make_main_menu() { label: "Back", accelerator: "Left", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "forward", -1); } }, @@ -358,6 +369,7 @@ function make_main_menu() { label: "Move to start", accelerator: "Home", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "forward", -99999); } }, @@ -365,9 +377,17 @@ function make_main_menu() { label: "Move to end", accelerator: "End", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "forward", 99999); } }, + { + label: "Autoplay", + accelerator: "Space", + click: () => { + windows.send("renderer", "toggle_autoplay", null); + } + }, { type: "separator" }, @@ -375,6 +395,7 @@ function make_main_menu() { label: "Go to turn...", accelerator: "CommandOrControl+T", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.show("turn"); windows.send("turn", "focus_input", null); } @@ -386,6 +407,7 @@ function make_main_menu() { label: "Previous collision", accelerator: "C", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "previous_collision", null); } }, @@ -393,6 +415,7 @@ function make_main_menu() { label: "Next collision", accelerator: "V", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "next_collision", null); } }, @@ -403,6 +426,7 @@ function make_main_menu() { label: "Selected ship's fate", accelerator: "X", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.send("renderer", "ship_fate", null); } }, @@ -545,6 +569,7 @@ function make_main_menu() { label: "Select ship by ID...", accelerator: "CommandOrControl+F", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.show("selector"); windows.send("selector", "focus_input", null); } @@ -574,6 +599,7 @@ function make_main_menu() { { label: "Extra stats", click: () => { + windows.send("renderer", "stop_autoplay", null); windows.show("extra_stats"); } }, @@ -583,6 +609,7 @@ function make_main_menu() { { label: "About Fluorine", click: () => { + windows.send("renderer", "stop_autoplay", null); alert(about_message); } }, diff --git a/package-lock.json b/package-lock.json index baa02c3..eac93bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Fluorine", - "version": "1.2.2", + "version": "1.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e73f12b..763da5a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Fluorine", "description": "Replay viewer for Halite 3", - "version": "1.2.2", + "version": "1.2.3", "author": "Fohristiwhirl", "repository": { "type": "git",