diff options
Diffstat (limited to 'modding')
-rw-r--r-- | modding/compiler.js | 17 | ||||
-rw-r--r-- | modding/hooks.js | 76 | ||||
-rw-r--r-- | modding/parser.js | 39 |
3 files changed, 105 insertions, 27 deletions
diff --git a/modding/compiler.js b/modding/compiler.js new file mode 100644 index 0000000..693a1e3 --- /dev/null +++ b/modding/compiler.js @@ -0,0 +1,17 @@ +class BuildError extends Error {
+ constructor(orig, ...params) {
+ super(...params);
+ this.name = "BuildError";
+ this.stack = this.stack + "\n" + orig.stack;
+ }
+}
+
+const tsbuild = require('../typescript/builder');
+
+for (file of importedTypeScriptFiles) {
+ try {
+ tsbuild(file.file, homedir + "/.kartik/build/" + file.output);
+ } catch (e) {
+ throw new BuildError(e, "Error while building " + file.file + " from package " + file.pkg)
+ }
+}
\ No newline at end of file diff --git a/modding/hooks.js b/modding/hooks.js index d0ee779..8e189d2 100644 --- a/modding/hooks.js +++ b/modding/hooks.js @@ -1,14 +1,17 @@ +const { dialog } = require('electron'); +const fs = require('fs'); + function hook_Music(mod, type, hname) { hook = mod["Hook"][hname]; names = Object.keys(hook); for (i in names) { name = names[i]; - if (name !== "Music.Start" && name !== "Music.Prepare" && name !== "Music.Title" && name !== "Music.Credits" && name !== "Music.Win" && name !== "Music.Game1" && name !== "Music.Game2" && name !== "Music.Game3" && name !== "Music.Game4" && name !== "Music.Game5" && name !== "Music.Game6" && name !== "Music.Game7" && name !== "Music.Game8" && name !== "Music.Game9") { + if (name !== "Music.Start" && name !== "Music.Prepare" && name !== "Music.Title" && name !== "Music.Credits" && name !== "Music.Win" && name !== "Music.Game1" && name !== "Music.Game2" && name !== "Music.Game3" && name !== "Music.Game4" && name !== "Music.Game5" && name !== "Music.Game6" && name !== "Music.Game7" && name !== "Music.Game8" && name !== "Music.Game9" && name !== "Music.Menu") { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -23,6 +26,10 @@ function hook_Music(mod, type, hname) { resources.music['title'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; resources.music['title'].original = false; break; + case "Music.Menu": + resources.music['title'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; + resources.music['title'].original = false; + break; case "Music.Credits": resources.music['credits'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; resources.music['credits'].original = false; @@ -86,7 +93,7 @@ function hook_SoundFX(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -138,7 +145,7 @@ function hook_Car(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -160,7 +167,58 @@ function hook_Circuit(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", + message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" + } + ) + process.exit(2); + } + } +} + +function hook_API(mod, type, hname) { + console.log(" * KMP-API TypeScript engine: " + item + "$" + hname) + hook = mod["Hook"][hname]; + names = Object.keys(hook); + + for (i in names) { + name = names[i]; + + if (name === "API.Includes") { + if (fs.existsSync(mod["_Path"] + "/" + mod["Hook"][hname][name])) { + if (fs.statSync(mod["_Path"] + "/" + mod["Hook"][hname][name]).isDirectory()) { + flist = fs.readdirSync(mod["_Path"] + "/" + mod["Hook"][hname][name]); + for (file of flist) { + if (file.endsWith(".ts")) { + importedTypeScriptFiles.push({ + file: mod["_Path"] + "/" + mod["Hook"][hname][name] + "/" + file, + pkg: item, + output: item + "--" + file + ".js" + }); + } + } + } else { + importedTypeScriptFiles.push({ + file: mod["_Path"] + "/" + mod["Hook"][hname][name], + pkg: item, + output: item + "--" + mod["Hook"][hname][name] + ".js" + }); + } + } else { + dialog.showMessageBoxSync( + { + type: "error", + title: "KMP Mod Loader", + message: "On package " + item + ": KMP-API includes " + mod["Hook"][hname][name] + " (" + mod["_Path"] + "/" + mod["Hook"][hname][name] + "): no such file or directory, EXITING" + } + ) + process.exit(2); + } + } else { + dialog.showMessageBoxSync( + { + type: "error", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -172,11 +230,11 @@ function hook_Circuit(mod, type, hname) { module.exports = (mod, type, name) => { hook = mod["Hook"][name]; - if (type !== "Kartik.Music" && type !== "Kartik.SoundFX" && type !== "Kartik.Circuit" && type !== "Kartik.Car") { + if (type !== "Kartik.Music" && type !== "Kartik.SoundFX" && type !== "Kartik.Circuit" && type !== "Kartik.Car" && type !== "Kartik.API") { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid hook type, EXITING" } ) @@ -193,9 +251,11 @@ module.exports = (mod, type, name) => { case "Kartik.Car": hook_Car(mod, type, name); break; - break; case "Kartik.Circuit": hook_Circuit(mod, type, name); break; + case "Kartik.API": + hook_API(mod, type, name); + break; } } diff --git a/modding/parser.js b/modding/parser.js index 26f5320..2c39055 100644 --- a/modding/parser.js +++ b/modding/parser.js @@ -26,7 +26,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": no kartik.ini or kartik.yml file found" } ) @@ -37,13 +37,13 @@ for (index in list) { item = list[index]; parts = item.split("."); - if (parts.length < 2 || parts[0].length > 5 || item.length > 49 || parts.length > 5 || !/^[a-zA-Z0-9.]*$/gm.test(item)) { + if (parts.length < 2 || parts[0].length > 5 || item.length > 49 || parts.length > 7 || !/^[a-zA-Z0-9.]*$/gm.test(item)) { unload(list, item); if (parts.length < 2) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid package name: not enough parts" } ) @@ -52,7 +52,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid package name: tld too long" } ) @@ -61,16 +61,16 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid package name: too long" } ) } - if (parts.length > 5) { + if (parts.length > 7) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid package name: too many parts" } ) @@ -79,7 +79,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid package name: invalid format" } ) @@ -95,7 +95,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": both kartik.ini and kartik.yml found" } ) @@ -114,7 +114,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": ini parser error" } ) @@ -128,7 +128,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": yaml parser error" } ) @@ -149,7 +149,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid root section: " + r } ) @@ -163,7 +163,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid meta section: " + r } ) @@ -175,7 +175,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": meta sections incomplete" } ) @@ -190,7 +190,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid property: " + r } ) @@ -202,7 +202,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": properties incomplete" } ) @@ -218,7 +218,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": mod made for another version of Kartik" } ) @@ -229,7 +229,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid game version" } ) @@ -248,7 +248,7 @@ for (index in list) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": block " + hook + " required by hook " + hookn + " not found" } ) @@ -270,6 +270,7 @@ for (index in list) { mod["_Path"] = homedir + "/.kartik/mods/" + item; + console.log(" * KMP hook: " + item + "$" + hookn) require('./hooks')(mod, hookn, hook); } } |