Skip to content

Commit

Permalink
finish prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
fohristiwhirl committed Oct 10, 2018
1 parent 4348207 commit 63384f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
5 changes: 3 additions & 2 deletions fluorine_renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@
renderer.scrap_counts = null;
renderer.absorbed_counts = null;

renderer.offset_x = 0;
renderer.offset_y = 0;

renderer.integer_box_sizes = false;
renderer.triangles_show_next = true;
renderer.grid_aesthetic = 1;
renderer.offset_x = 0;
renderer.offset_y = 0;

// --------------------------------------------------------------

Expand Down
37 changes: 31 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";

const alert = require("./modules/alert");
const app = require('electron').app;
const electron = require("electron");
const fs = require("fs");
const ipcMain = require("electron").ipcMain;
const path = require("path");
const windows = require("./modules/windows");
Expand All @@ -12,6 +14,28 @@ let about_message = `Fluorine: Replay viewer for Halite 3\n` +
`Node ${process.versions.node}\n` +
`V8 ${process.versions.v8}`

// -------------------------------------------------------
// Read prefs.

let prefs = Object.create(null); // First, set defaults for everything in case load fails.
prefs.integer_box_sizes = false;
prefs.triangles_show_next = true;
prefs.grid_aesthetic = 1;

let userdata_path = app.getPath("userData");

try {
let filename = path.join(userdata_path, "prefs.json");
let s = fs.readFileSync(filename, "utf8");
let o = JSON.parse(s);

for (let [varname, value] of Object.entries(o)) {
prefs[varname] = value;
}
} catch (err) {
// pass
}

// -------------------------------------------------------

process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; // FIXME: this is lame. What's the correct way to prevent the console warning?
Expand Down Expand Up @@ -221,6 +245,7 @@ function make_main_menu() {
{
label: "Integer box sizes",
type: "checkbox",
checked: prefs.integer_box_sizes,
click: (menuItem) => {
if (menuItem.checked) {
windows.send("renderer", "set", ["integer_box_sizes", true]);
Expand All @@ -235,31 +260,31 @@ function make_main_menu() {
{
label: "0",
type: "radio",
checked: false,
checked: prefs.grid_aesthetic === 0,
click: () => {
windows.send("renderer", "set", ["grid_aesthetic", 0]);
}
},
{
label: "halite / 4",
type: "radio",
checked: true,
checked: prefs.grid_aesthetic === 1,
click: () => {
windows.send("renderer", "set", ["grid_aesthetic", 1]);
}
},
{
label: "255 * sqrt(halite / 2048)",
type: "radio",
checked: false,
checked: prefs.grid_aesthetic === 2,
click: () => {
windows.send("renderer", "set", ["grid_aesthetic", 2]);
}
},
{
label: "255 * sqrt(halite / 1024)",
type: "radio",
checked: false,
checked: prefs.grid_aesthetic === 3,
click: () => {
windows.send("renderer", "set", ["grid_aesthetic", 3]);
}
Expand All @@ -272,15 +297,15 @@ function make_main_menu() {
{
label: "Show next move",
type: "radio",
checked: true,
checked: prefs.triangles_show_next,
click: () => {
windows.send("renderer", "set", ["triangles_show_next", true]);
}
},
{
label: "Show previous move",
type: "radio",
checked: false,
checked: prefs.triangles_show_next === false,
click: () => {
windows.send("renderer", "set", ["triangles_show_next", false]);
}
Expand Down

0 comments on commit 63384f5

Please sign in to comment.