1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
This commit is contained in:
DJ1TJOO 2021-03-02 14:13:02 +01:00
parent f789dcc80e
commit db215dc5b3
8 changed files with 115 additions and 108 deletions

View File

@ -11,14 +11,14 @@ const isLocal = process.argv.indexOf("--local") >= 0;
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");
if (!fs.existsSync(storePath)) if (!fs.existsSync(storePath))
// No try-catch by design // No try-catch by design
fs.mkdirSync(storePath, { recursive: true }); fs.mkdirSync(storePath, { recursive: true });
if (!fs.existsSync(modsPath)) fs.mkdirSync(modsPath); if (!fs.existsSync(modsPath)) fs.mkdirSync(modsPath);
@ -157,89 +157,84 @@ ipcMain.on("exit-app", (event, flag) => {
function performFsJob(job) { function performFsJob(job) {
let parent = storePath; let parent = storePath;
if (job.mods) if (job.mods) parent = modsPath;
let parent = modsPath;
const fname = path.join(parent, job.filename); const fname = path.join(parent, job.filename);
const relative = path.relative(parent, fname); const relative = path.relative(parent, fname);
//If not a child of parent //If not a child of parent
if(!relative && !relative.startsWith('..') && !path.isAbsolute(relative)) if (!relative && !relative.startsWith("..") && !path.isAbsolute(relative))
return { return {
error: "Cannot get above parent folder" error: "Cannot get above parent folder",
} };
switch (job.type) { switch (job.type) {
case "readDir": case "readDir": {
{ let contents = "";
let contents = ""; try {
try { contents = fs.readdirSync(fname, { encoding: "utf8" });
contents = fs.readdirSync(fname, { encoding: "utf8" }); } catch (ex) {
} catch (ex) {
return {
error: ex,
};
}
return { return {
success: true, error: ex,
data: contents,
}; };
} }
case "read": return {
{ success: true,
if (!fs.existsSync(fname)) { data: contents,
return { };
// Special FILE_NOT_FOUND error code }
error: "file_not_found", case "read": {
}; if (!fs.existsSync(fname)) {
}
let contents = "";
try {
contents = fs.readFileSync(fname, { encoding: "utf8" });
} catch (ex) {
return {
error: ex,
};
}
return { return {
success: true, // Special FILE_NOT_FOUND error code
data: contents, error: "file_not_found",
};
}
case "write":
{
try {
fs.writeFileSync(fname, job.contents);
} catch (ex) {
return {
error: ex,
};
}
return {
success: true,
data: job.contents,
}; };
} }
case "delete": let contents = "";
{ try {
try { contents = fs.readFileSync(fname, { encoding: "utf8" });
fs.unlinkSync(fname); } catch (ex) {
} catch (ex) {
return {
error: ex,
};
}
return { return {
success: true, error: ex,
data: null,
}; };
} }
return {
success: true,
data: contents,
};
}
case "write": {
try {
fs.writeFileSync(fname, job.contents);
} catch (ex) {
return {
error: ex,
};
}
return {
success: true,
data: job.contents,
};
}
case "delete": {
try {
fs.unlinkSync(fname);
} catch (ex) {
return {
error: ex,
};
}
return {
success: true,
data: null,
};
}
default: default:
throw new Error("Unkown fs job: " + job.type); throw new Error("Unkown fs job: " + job.type);
} }

View File

@ -4,7 +4,7 @@ const { readFileSync, readdirSync, writeFileSync } = require("fs");
const suffixToScale = { const suffixToScale = {
lq: "0.25", lq: "0.25",
mq: "0.5", mq: "0.5",
hq: "0.75" hq: "0.75",
}; };
function convert(srcDir) { function convert(srcDir) {
@ -65,7 +65,7 @@ function convert(srcDir) {
x: xy[0], x: xy[0],
y: xy[1], y: xy[1],
w: size[0], w: size[0],
h: size[1] h: size[1],
}, },
// Whether image was rotated // Whether image was rotated
@ -75,21 +75,21 @@ function convert(srcDir) {
// How is the image trimmed // How is the image trimmed
spriteSourceSize: { spriteSourceSize: {
x: offset[0], x: offset[0],
y: (orig[1] - size[1]) - offset[1], y: orig[1] - size[1] - offset[1],
w: size[0], w: size[0],
h: size[1] h: size[1],
}, },
sourceSize: { sourceSize: {
w: orig[0], w: orig[0],
h: orig[1] h: orig[1],
} },
} };
} }
// Simple object that will hold other metadata // Simple object that will hold other metadata
current = { current = {
name: line name: line,
}; };
} else { } else {
// Read and set current image metadata // Read and set current image metadata
@ -108,14 +108,14 @@ function convert(srcDir) {
format: srcMeta.format, format: srcMeta.format,
size: { size: {
w: atlasSize[0], w: atlasSize[0],
h: atlasSize[1] h: atlasSize[1],
}, },
scale: atlasScale.toString() scale: atlasScale.toString(),
} },
}); });
writeFileSync(atlas.replace(".atlas", ".json"), result, { writeFileSync(atlas.replace(".atlas", ".json"), result, {
encoding: "utf-8" encoding: "utf-8",
}); });
} }
} }

View File

@ -29,7 +29,7 @@ module.exports = {
try { try {
return execSync("git describe --tag --exact-match").toString("ascii"); return execSync("git describe --tag --exact-match").toString("ascii");
} catch (e) { } catch (e) {
throw new Error('Current git HEAD is not a version tag'); throw new Error("Current git HEAD is not a version tag");
} }
}, },

View File

@ -6,7 +6,6 @@ function requireUncached(module) {
} }
function gulptasksJS($, gulp, buildFolder, browserSync) { function gulptasksJS($, gulp, buildFolder, browserSync) {
//// DEV //// DEV
gulp.task("js.dev.watch", () => { gulp.task("js.dev.watch", () => {

View File

@ -24,7 +24,7 @@ function gulptasksReleaseUploader($, gulp, buildFolder) {
const currentTag = buildutils.getTag(); const currentTag = buildutils.getTag();
const octokit = new Octokit({ const octokit = new Octokit({
auth: process.env.SHAPEZ_CLI_GITHUB_TOKEN auth: process.env.SHAPEZ_CLI_GITHUB_TOKEN,
}); });
const createdRelease = await octokit.request("POST /repos/{owner}/{repo}/releases", { const createdRelease = await octokit.request("POST /repos/{owner}/{repo}/releases", {
@ -32,10 +32,12 @@ function gulptasksReleaseUploader($, gulp, buildFolder) {
repo: "shapez.io", repo: "shapez.io",
tag_name: currentTag, tag_name: currentTag,
name: currentTag, name: currentTag,
draft: true draft: true,
}); });
const { data: { id, upload_url } } = createdRelease; const {
data: { id, upload_url },
} = createdRelease;
console.log(`Created release ${id} for tag ${currentTag}`); console.log(`Created release ${id} for tag ${currentTag}`);
const dmgContents = fs.readFileSync(dmgPath); const dmgContents = fs.readFileSync(dmgPath);
@ -46,21 +48,23 @@ function gulptasksReleaseUploader($, gulp, buildFolder) {
method: "POST", method: "POST",
url: upload_url, url: upload_url,
headers: { headers: {
"content-type": "application/x-apple-diskimage" "content-type": "application/x-apple-diskimage",
}, },
name: dmgName, name: dmgName,
data: dmgContents data: dmgContents,
}); });
cb(); cb();
}); });
gulp.task("standalone.uploadRelease.darwin64", gulp.task(
"standalone.uploadRelease.darwin64",
gulp.series( gulp.series(
"standalone.uploadRelease.darwin64.cleanup", "standalone.uploadRelease.darwin64.cleanup",
"standalone.uploadRelease.darwin64.compress", "standalone.uploadRelease.darwin64.compress",
"standalone.uploadRelease.darwin64.upload" "standalone.uploadRelease.darwin64.upload"
)); )
);
} }
module.exports = { gulptasksReleaseUploader }; module.exports = { gulptasksReleaseUploader };

View File

@ -27,7 +27,8 @@ module.exports = ({ watch = false, standalone = false }) => {
new webpack.DefinePlugin({ new webpack.DefinePlugin({
assert: "window.assert", assert: "window.assert",
assertAlways: "window.assert", assertAlways: "window.assert",
abstract: "window.assert(false, 'abstract method called of: ' + (this.name || (this.constructor && this.constructor.name)));", abstract:
"window.assert(false, 'abstract method called of: ' + (this.name || (this.constructor && this.constructor.name)));",
G_HAVE_ASSERT: "true", G_HAVE_ASSERT: "true",
G_APP_ENVIRONMENT: JSON.stringify("dev"), G_APP_ENVIRONMENT: JSON.stringify("dev"),
G_TRACKING_ENDPOINT: JSON.stringify( G_TRACKING_ENDPOINT: JSON.stringify(
@ -60,7 +61,8 @@ module.exports = ({ watch = false, standalone = false }) => {
}), }),
], ],
module: { module: {
rules: [{ rules: [
{
test: /\.json$/, test: /\.json$/,
enforce: "pre", enforce: "pre",
use: ["./gulp/loader.compressjson"], use: ["./gulp/loader.compressjson"],
@ -69,7 +71,8 @@ module.exports = ({ watch = false, standalone = false }) => {
{ test: /\.(png|jpe?g|svg)$/, loader: "ignore-loader" }, { test: /\.(png|jpe?g|svg)$/, loader: "ignore-loader" },
{ {
test: /\.md$/, test: /\.md$/,
use: [{ use: [
{
loader: "html-loader", loader: "html-loader",
}, },
"markdown-loader", "markdown-loader",
@ -79,13 +82,15 @@ module.exports = ({ watch = false, standalone = false }) => {
test: /\.js$/, test: /\.js$/,
enforce: "pre", enforce: "pre",
exclude: /node_modules/, exclude: /node_modules/,
use: [{ use: [
loader: "webpack-strip-block", {
options: { loader: "webpack-strip-block",
start: "typehints:start", options: {
end: "typehints:end", start: "typehints:start",
end: "typehints:end",
},
}, },
}, ], ],
}, },
{ {
test: /\.worker\.js$/, test: /\.worker\.js$/,

View File

@ -139,7 +139,8 @@ module.exports = ({
beautify: false, beautify: false,
braces: false, braces: false,
ecma: es6 ? 6 : 5, ecma: es6 ? 6 : 5,
preamble: "/* shapez.io Codebase - Copyright 2020 Tobias Springer - " + preamble:
"/* shapez.io Codebase - Copyright 2020 Tobias Springer - " +
getVersion() + getVersion() +
" @ " + " @ " +
getRevision() + getRevision() +
@ -163,7 +164,8 @@ module.exports = ({
}), }),
], ],
module: { module: {
rules: [{ rules: [
{
test: /\.json$/, test: /\.json$/,
enforce: "pre", enforce: "pre",
use: ["./gulp/loader.compressjson"], use: ["./gulp/loader.compressjson"],
@ -174,7 +176,8 @@ module.exports = ({
test: /\.js$/, test: /\.js$/,
enforce: "pre", enforce: "pre",
exclude: /node_modules/, exclude: /node_modules/,
use: [{ use: [
{
loader: "webpack-strip-block", loader: "webpack-strip-block",
options: { options: {
start: "typehints:start", start: "typehints:start",
@ -225,7 +228,8 @@ module.exports = ({
}, },
{ {
test: /\.worker\.js$/, test: /\.worker\.js$/,
use: [{ use: [
{
loader: "worker-loader", loader: "worker-loader",
options: { options: {
fallback: false, fallback: false,

View File

@ -10,7 +10,7 @@
"dev": "cd gulp && yarn gulp main.serveDev", "dev": "cd gulp && yarn gulp main.serveDev",
"tslint": "cd src/js && tsc", "tslint": "cd src/js && tsc",
"lint": "eslint src/js", "lint": "eslint src/js",
"prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.*", "prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.* && prettier --write electron/**/*.*",
"publishOnItchWindows": "butler push tmp_standalone_files/shapez.io-standalone-win32-x64 tobspr/shapezio:windows --userversion-file version", "publishOnItchWindows": "butler push tmp_standalone_files/shapez.io-standalone-win32-x64 tobspr/shapezio:windows --userversion-file version",
"publishOnItchLinux": "butler push tmp_standalone_files/shapez.io-standalone-linux-x64 tobspr/shapezio:linux --userversion-file version", "publishOnItchLinux": "butler push tmp_standalone_files/shapez.io-standalone-linux-x64 tobspr/shapezio:linux --userversion-file version",
"publishOnItch": "yarn publishOnItchWindows && yarn publishOnItchLinux", "publishOnItch": "yarn publishOnItchWindows && yarn publishOnItchLinux",