mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Minor adjustments, closes #1333
This commit is contained in:
parent
de8afcedc9
commit
81da328f5a
@ -7,15 +7,17 @@ const fs = require("fs");
|
|||||||
const steam = require("./steam");
|
const steam = require("./steam");
|
||||||
const asyncLock = require("async-lock");
|
const asyncLock = require("async-lock");
|
||||||
|
|
||||||
const isDev = process.argv.indexOf("--dev") >= 0;
|
const isDev = app.commandLine.hasSwitch("dev");
|
||||||
const isLocal = process.argv.indexOf("--local") >= 0;
|
const isLocal = app.commandLine.hasSwitch("local");
|
||||||
const safeMode = process.argv.indexOf("--safe-mode") >= 0;
|
const safeMode = app.commandLine.hasSwitch("safe-mode");
|
||||||
|
const externalMod = app.commandLine.getSwitchValue("load-mod");
|
||||||
|
|
||||||
const roamingFolder =
|
const roamingFolder =
|
||||||
process.env.APPDATA ||
|
process.env.APPDATA ||
|
||||||
(process.platform == "darwin"
|
(process.platform == "darwin"
|
||||||
? process.env.HOME + "/Library/Preferences"
|
? process.env.HOME + "/Library/Preferences"
|
||||||
: process.env.HOME + "/.local/share");
|
: process.env.HOME + "/.local/share");
|
||||||
|
|
||||||
let storePath = path.join(roamingFolder, "shapez.io", "saves");
|
let storePath = path.join(roamingFolder, "shapez.io", "saves");
|
||||||
let modsPath = path.join(roamingFolder, "shapez.io", "mods");
|
let modsPath = path.join(roamingFolder, "shapez.io", "mods");
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ function createWindow() {
|
|||||||
if (!app.requestSingleInstanceLock()) {
|
if (!app.requestSingleInstanceLock()) {
|
||||||
app.exit(0);
|
app.exit(0);
|
||||||
} else {
|
} else {
|
||||||
app.on("second-instance", (event, commandLine, workingDirectory) => {
|
app.on("second-instance", () => {
|
||||||
// Someone tried to run a second instance, we should focus
|
// Someone tried to run a second instance, we should focus
|
||||||
if (win) {
|
if (win) {
|
||||||
if (win.isMinimized()) {
|
if (win.isMinimized()) {
|
||||||
@ -144,7 +146,7 @@ ipcMain.on("set-fullscreen", (event, flag) => {
|
|||||||
win.setFullScreen(flag);
|
win.setFullScreen(flag);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("exit-app", (event, flag) => {
|
ipcMain.on("exit-app", () => {
|
||||||
win.close();
|
win.close();
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
@ -175,14 +177,14 @@ async function writeFileSafe(filename, contents) {
|
|||||||
if (!fs.existsSync(filename)) {
|
if (!fs.existsSync(filename)) {
|
||||||
// this one is easy
|
// this one is easy
|
||||||
console.log(prefix, "Writing file instantly because it does not exist:", niceFileName(filename));
|
console.log(prefix, "Writing file instantly because it does not exist:", niceFileName(filename));
|
||||||
await fs.promises.writeFile(filename, contents, { encoding: "utf8" });
|
await fs.promises.writeFile(filename, contents, "utf8");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first, write a temporary file (.tmp-XXX)
|
// first, write a temporary file (.tmp-XXX)
|
||||||
const tempName = filename + ".tmp-" + transactionId;
|
const tempName = filename + ".tmp-" + transactionId;
|
||||||
console.log(prefix, "Writing temporary file", niceFileName(tempName));
|
console.log(prefix, "Writing temporary file", niceFileName(tempName));
|
||||||
await fs.promises.writeFile(tempName, contents, { encoding: "utf8" });
|
await fs.promises.writeFile(tempName, contents, "utf8");
|
||||||
|
|
||||||
// now, rename the original file to (.backup-XXX)
|
// now, rename the original file to (.backup-XXX)
|
||||||
const oldTemporaryName = filename + ".backup-" + transactionId;
|
const oldTemporaryName = filename + ".backup-" + transactionId;
|
||||||
@ -237,7 +239,7 @@ async function performFsJob(job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await fs.promises.readFile(fname, { encoding: "utf8" });
|
const data = await fs.promises.readFile(fname, "utf8");
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data,
|
data,
|
||||||
@ -278,7 +280,7 @@ async function performFsJob(job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Unkown fs job: " + job.type);
|
throw new Error("Unknown fs job: " + job.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,20 +293,25 @@ ipcMain.on("open-mods-folder", async () => {
|
|||||||
shell.openPath(modsPath);
|
shell.openPath(modsPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("get-mods", async (event, arg) => {
|
ipcMain.handle("get-mods", async () => {
|
||||||
if (safeMode) {
|
if (safeMode) {
|
||||||
console.warn("Not loading mods due to safe mode");
|
console.log("Safe Mode enabled for mods, skipping mod search");
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(modsPath)) {
|
|
||||||
console.warn("Mods folder not found:", modsPath);
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Loading mods from", modsPath);
|
console.log("Loading mods from", modsPath);
|
||||||
let entries = fs.readdirSync(modsPath);
|
let modFiles = safeMode
|
||||||
entries = entries.filter(entry => entry.endsWith(".js"));
|
? []
|
||||||
return entries.map(filename => fs.readFileSync(path.join(modsPath, filename), { encoding: "utf8" }));
|
: fs
|
||||||
|
.readdirSync(modsPath)
|
||||||
|
.filter(filename => filename.endsWith(".js"))
|
||||||
|
.map(filename => path.join(modsPath, filename));
|
||||||
|
if (externalMod) {
|
||||||
|
console.log("Adding external mod source:", externalMod);
|
||||||
|
modFiles.push(externalMod);
|
||||||
|
}
|
||||||
|
|
||||||
|
return modFiles.map(filename => fs.readFileSync(filename, "utf8"));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
throw new Error(ex);
|
throw new Error(ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -304,6 +304,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
|
@include S(width, 250px);
|
||||||
@include S(padding, 15px);
|
@include S(padding, 15px);
|
||||||
@include S(padding-bottom, 10px);
|
@include S(padding-bottom, 10px);
|
||||||
@include S(border-radius, $globalBorderRadius);
|
@include S(border-radius, $globalBorderRadius);
|
||||||
@ -337,7 +338,7 @@
|
|||||||
.dlcHint {
|
.dlcHint {
|
||||||
@include SuperSmallText;
|
@include SuperSmallText;
|
||||||
@include S(margin-top, 10px);
|
@include S(margin-top, 10px);
|
||||||
@include S(width, 300px);
|
width: 100%;
|
||||||
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
|
|||||||
@ -395,7 +395,7 @@ export function clamp(v, minimum = 0, maximum = 1) {
|
|||||||
* @param {Array<string>=} classes
|
* @param {Array<string>=} classes
|
||||||
* @param {string=} innerHTML
|
* @param {string=} innerHTML
|
||||||
*/
|
*/
|
||||||
function makeDivElement(id = null, classes = [], innerHTML = "") {
|
export function makeDivElement(id = null, classes = [], innerHTML = "") {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
if (id) {
|
if (id) {
|
||||||
div.id = id;
|
div.id = id;
|
||||||
|
|||||||
@ -8,11 +8,10 @@ import { ReadWriteProxy } from "../core/read_write_proxy";
|
|||||||
import {
|
import {
|
||||||
formatSecondsToTimeAgo,
|
formatSecondsToTimeAgo,
|
||||||
generateFileDownload,
|
generateFileDownload,
|
||||||
getIPCRenderer,
|
|
||||||
isSupportedBrowser,
|
isSupportedBrowser,
|
||||||
makeButton,
|
makeButton,
|
||||||
makeButtonElement,
|
|
||||||
makeDiv,
|
makeDiv,
|
||||||
|
makeDivElement,
|
||||||
removeAllChildren,
|
removeAllChildren,
|
||||||
startFileChoose,
|
startFileChoose,
|
||||||
waitNextFrame,
|
waitNextFrame,
|
||||||
@ -386,44 +385,41 @@ export class MainMenuState extends GameState {
|
|||||||
const buttonContainer = this.htmlElement.querySelector(".mainContainer .buttons");
|
const buttonContainer = this.htmlElement.querySelector(".mainContainer .buttons");
|
||||||
removeAllChildren(buttonContainer);
|
removeAllChildren(buttonContainer);
|
||||||
|
|
||||||
|
const outerDiv = makeDivElement(null, ["outer"], null);
|
||||||
|
|
||||||
// Import button
|
// Import button
|
||||||
const importButtonElement = makeButtonElement(
|
this.trackClicks(
|
||||||
["importButton", "styledButton"],
|
makeButton(outerDiv, ["importButton", "styledButton"], T.mainMenu.importSavegame),
|
||||||
T.mainMenu.importSavegame
|
this.requestImportSavegame
|
||||||
);
|
);
|
||||||
this.trackClicks(importButtonElement, this.requestImportSavegame);
|
|
||||||
|
|
||||||
if (this.savedGames.length > 0) {
|
if (this.savedGames.length > 0) {
|
||||||
// Continue game
|
// Continue game
|
||||||
const continueButton = makeButton(
|
this.trackClicks(
|
||||||
buttonContainer,
|
makeButton(buttonContainer, ["continueButton", "styledButton"], T.mainMenu.continue),
|
||||||
["continueButton", "styledButton"],
|
this.onContinueButtonClicked
|
||||||
T.mainMenu.continue
|
|
||||||
);
|
);
|
||||||
this.trackClicks(continueButton, this.onContinueButtonClicked);
|
|
||||||
|
|
||||||
const outerDiv = makeDiv(buttonContainer, null, ["outer"], null);
|
|
||||||
outerDiv.appendChild(importButtonElement);
|
|
||||||
const newGameButton = makeButton(
|
|
||||||
this.htmlElement.querySelector(".mainContainer .outer"),
|
|
||||||
["newGameButton", "styledButton"],
|
|
||||||
T.mainMenu.newGame
|
|
||||||
);
|
|
||||||
this.trackClicks(newGameButton, this.onPlayButtonClicked);
|
|
||||||
} else {
|
|
||||||
// New game
|
// New game
|
||||||
const playBtn = makeButton(buttonContainer, ["playButton", "styledButton"], T.mainMenu.play);
|
this.trackClicks(
|
||||||
this.trackClicks(playBtn, this.onPlayButtonClicked);
|
makeButton(outerDiv, ["newGameButton", "styledButton"], T.mainMenu.newGame),
|
||||||
buttonContainer.appendChild(importButtonElement);
|
this.onPlayButtonClicked
|
||||||
}
|
);
|
||||||
|
|
||||||
// Mods
|
// Mods
|
||||||
const modsBtn = makeButton(
|
this.trackClicks(
|
||||||
this.htmlElement.querySelector(".mainContainer .outer"),
|
makeButton(outerDiv, ["modsButton", "styledButton"], " "),
|
||||||
["modsButton", "styledButton"],
|
this.onModsClicked
|
||||||
" "
|
|
||||||
);
|
);
|
||||||
this.trackClicks(modsBtn, this.onModsClicked);
|
} else {
|
||||||
|
// New game
|
||||||
|
this.trackClicks(
|
||||||
|
makeButton(buttonContainer, ["playButton", "styledButton"], T.mainMenu.play),
|
||||||
|
this.onPlayButtonClicked
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonContainer.appendChild(outerDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
onPuzzleModeButtonClicked(force = false) {
|
onPuzzleModeButtonClicked(force = false) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user