Files
forma-engine/native/options.mjs
T

61 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const targets = ["linux", "windows", "android"];
export function normalizeOptions(value = {}) {
const o = {
target: value.target ?? "linux",
name: value.name ?? "Forma Game",
appId: value.appId ?? "games.forma.mygame",
version: value.version ?? "1.0.0",
versionCode: value.versionCode ?? 1,
mode: value.mode ?? "debug",
width: value.width ?? 1280,
height: value.height ?? 720,
fullscreen: value.fullscreen ?? false,
orientation: value.orientation ?? "landscape",
};
if (!targets.includes(o.target)) throw Error("Unknown build target");
if (
typeof o.name !== "string" ||
!o.name.trim() ||
o.name.length > 80 ||
/[\x00-\x1f<>:"/\\|?*]/.test(o.name)
)
throw Error(
"Game name must be 180 characters without file control characters",
);
o.name = o.name.trim();
if (
typeof o.appId !== "string" ||
o.appId.length > 150 ||
!/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*){2,}$/.test(o.appId)
)
throw Error(
"Application ID: games.studio.mygame (lowercase Latin letters)",
);
if (
typeof o.version !== "string" ||
!/^\d{1,4}\.\d{1,4}\.\d{1,4}$/.test(o.version)
)
throw Error("Version must have format 1.0.0");
if (
!Number.isInteger(o.versionCode) ||
o.versionCode < 1 ||
o.versionCode > 2100000000
)
throw Error("Android version code must be a positive integer");
if (!["debug", "release"].includes(o.mode))
throw Error("Mode must be debug or release");
if (!["landscape", "portrait", "sensor"].includes(o.orientation))
throw Error("Invalid orientation");
for (const key of ["width", "height"])
if (!Number.isInteger(o[key]) || o[key] < 320 || o[key] > 7680)
throw Error("Window size must be 3207680");
if (typeof o.fullscreen !== "boolean")
throw Error("Fullscreen must be boolean");
return o;
}
export function artifactStem(o) {
return o.appId.split(".").at(-1) + "-" + o.version;
}