Skip to content

Commit

Permalink
autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
fohristiwhirl committed Nov 4, 2018
1 parent 182a0e7 commit d20eb2d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
45 changes: 45 additions & 0 deletions fluorine_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
Expand Down
7 changes: 7 additions & 0 deletions fluorine_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions fluorine_turn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"],
Expand All @@ -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"]
Expand All @@ -273,6 +276,7 @@ function make_main_menu() {
{
label: "What is an f-log?",
click: () => {
windows.send("renderer", "stop_autoplay", null);
about_flogging();
}
},
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -341,13 +350,15 @@ function make_main_menu() {
label: "Forward",
accelerator: "Right",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.send("renderer", "forward", 1);
}
},
{
label: "Back",
accelerator: "Left",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.send("renderer", "forward", -1);
}
},
Expand All @@ -358,23 +369,33 @@ function make_main_menu() {
label: "Move to start",
accelerator: "Home",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.send("renderer", "forward", -99999);
}
},
{
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"
},
{
label: "Go to turn...",
accelerator: "CommandOrControl+T",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.show("turn");
windows.send("turn", "focus_input", null);
}
Expand All @@ -386,13 +407,15 @@ function make_main_menu() {
label: "Previous collision",
accelerator: "C",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.send("renderer", "previous_collision", null);
}
},
{
label: "Next collision",
accelerator: "V",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.send("renderer", "next_collision", null);
}
},
Expand All @@ -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);
}
},
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -574,6 +599,7 @@ function make_main_menu() {
{
label: "Extra stats",
click: () => {
windows.send("renderer", "stop_autoplay", null);
windows.show("extra_stats");
}
},
Expand All @@ -583,6 +609,7 @@ function make_main_menu() {
{
label: "About Fluorine",
click: () => {
windows.send("renderer", "stop_autoplay", null);
alert(about_message);
}
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d20eb2d

Please sign in to comment.