1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 18:21:51 +00:00

Minor adjustments, closes #1333

This commit is contained in:
tobspr 2022-01-14 16:53:20 +01:00
parent de8afcedc9
commit 81da328f5a
4 changed files with 53 additions and 49 deletions

View File

@ -7,15 +7,17 @@ const fs = require("fs");
const steam = require("./steam");
const asyncLock = require("async-lock");
const isDev = process.argv.indexOf("--dev") >= 0;
const isLocal = process.argv.indexOf("--local") >= 0;
const safeMode = process.argv.indexOf("--safe-mode") >= 0;
const isDev = app.commandLine.hasSwitch("dev");
const isLocal = app.commandLine.hasSwitch("local");
const safeMode = app.commandLine.hasSwitch("safe-mode");
const externalMod = app.commandLine.getSwitchValue("load-mod");
const roamingFolder =
process.env.APPDATA ||
(process.platform == "darwin"
? process.env.HOME + "/Library/Preferences"
: process.env.HOME + "/.local/share");
let storePath = path.join(roamingFolder, "shapez.io", "saves");
let modsPath = path.join(roamingFolder, "shapez.io", "mods");
@ -122,7 +124,7 @@ function createWindow() {
if (!app.requestSingleInstanceLock()) {
app.exit(0);
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
app.on("second-instance", () => {
// Someone tried to run a second instance, we should focus
if (win) {
if (win.isMinimized()) {
@ -144,7 +146,7 @@ ipcMain.on("set-fullscreen", (event, flag) => {
win.setFullScreen(flag);
});
ipcMain.on("exit-app", (event, flag) => {
ipcMain.on("exit-app", () => {
win.close();
app.quit();
});
@ -175,14 +177,14 @@ async function writeFileSafe(filename, contents) {
if (!fs.existsSync(filename)) {
// this one is easy
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;
}
// first, write a temporary file (.tmp-XXX)
const tempName = filename + ".tmp-" + transactionId;
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)
const oldTemporaryName = filename + ".backup-" + transactionId;
@ -237,7 +239,7 @@ async function performFsJob(job) {
}
try {
const data = await fs.promises.readFile(fname, { encoding: "utf8" });
const data = await fs.promises.readFile(fname, "utf8");
return {
success: true,
data,
@ -278,7 +280,7 @@ async function performFsJob(job) {
}
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);
});
ipcMain.handle("get-mods", async (event, arg) => {
ipcMain.handle("get-mods", async () => {
if (safeMode) {
console.warn("Not loading mods due to safe mode");
return [];
}
if (!fs.existsSync(modsPath)) {
console.warn("Mods folder not found:", modsPath);
return [];
console.log("Safe Mode enabled for mods, skipping mod search");
}
try {
console.log("Loading mods from", modsPath);
let entries = fs.readdirSync(modsPath);
entries = entries.filter(entry => entry.endsWith(".js"));
return entries.map(filename => fs.readFileSync(path.join(modsPath, filename), { encoding: "utf8" }));
let modFiles = safeMode
? []
: 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) {
throw new Error(ex);
}

View File

@ -304,6 +304,7 @@
position: relative;
text-align: left;
align-items: flex-start;
@include S(width, 250px);
@include S(padding, 15px);
@include S(padding-bottom, 10px);
@include S(border-radius, $globalBorderRadius);
@ -337,7 +338,7 @@
.dlcHint {
@include SuperSmallText;
@include S(margin-top, 10px);
@include S(width, 300px);
width: 100%;
display: grid;
grid-template-columns: 1fr auto;

View File

@ -395,7 +395,7 @@ export function clamp(v, minimum = 0, maximum = 1) {
* @param {Array<string>=} classes
* @param {string=} innerHTML
*/
function makeDivElement(id = null, classes = [], innerHTML = "") {
export function makeDivElement(id = null, classes = [], innerHTML = "") {
const div = document.createElement("div");
if (id) {
div.id = id;

View File

@ -8,11 +8,10 @@ import { ReadWriteProxy } from "../core/read_write_proxy";
import {
formatSecondsToTimeAgo,
generateFileDownload,
getIPCRenderer,
isSupportedBrowser,
makeButton,
makeButtonElement,
makeDiv,
makeDivElement,
removeAllChildren,
startFileChoose,
waitNextFrame,
@ -386,44 +385,41 @@ export class MainMenuState extends GameState {
const buttonContainer = this.htmlElement.querySelector(".mainContainer .buttons");
removeAllChildren(buttonContainer);
const outerDiv = makeDivElement(null, ["outer"], null);
// Import button
const importButtonElement = makeButtonElement(
["importButton", "styledButton"],
T.mainMenu.importSavegame
this.trackClicks(
makeButton(outerDiv, ["importButton", "styledButton"], T.mainMenu.importSavegame),
this.requestImportSavegame
);
this.trackClicks(importButtonElement, this.requestImportSavegame);
if (this.savedGames.length > 0) {
// Continue game
const continueButton = makeButton(
buttonContainer,
["continueButton", "styledButton"],
T.mainMenu.continue
this.trackClicks(
makeButton(buttonContainer, ["continueButton", "styledButton"], T.mainMenu.continue),
this.onContinueButtonClicked
);
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
// New game
this.trackClicks(
makeButton(outerDiv, ["newGameButton", "styledButton"], T.mainMenu.newGame),
this.onPlayButtonClicked
);
// Mods
this.trackClicks(
makeButton(outerDiv, ["modsButton", "styledButton"], "&nbsp;"),
this.onModsClicked
);
this.trackClicks(newGameButton, this.onPlayButtonClicked);
} else {
// New game
const playBtn = makeButton(buttonContainer, ["playButton", "styledButton"], T.mainMenu.play);
this.trackClicks(playBtn, this.onPlayButtonClicked);
buttonContainer.appendChild(importButtonElement);
this.trackClicks(
makeButton(buttonContainer, ["playButton", "styledButton"], T.mainMenu.play),
this.onPlayButtonClicked
);
}
// Mods
const modsBtn = makeButton(
this.htmlElement.querySelector(".mainContainer .outer"),
["modsButton", "styledButton"],
"&nbsp;"
);
this.trackClicks(modsBtn, this.onModsClicked);
buttonContainer.appendChild(outerDiv);
}
onPuzzleModeButtonClicked(force = false) {