diff --git a/main.js b/main.js
index 9e87425..88c581d 100644
--- a/main.js
+++ b/main.js
@@ -26,6 +26,10 @@ function createWindow () {
fs.mkdirSync(thePath);
}
+ if (!fs.existsSync(path.join(thePath, "xmls"))) {
+ fs.mkdirSync(path.join(thePath, "xmls"));
+ }
+
if (!fs.existsSync(path.join(thePath, "config.json"))) {
fs.writeFileSync(path.join(thePath, "config.json"), JSON.stringify({
"binds": {
@@ -51,11 +55,62 @@ function createWindow () {
}, null, 2));
}
+ if (!fs.existsSync(path.join(thePath, "presets.json"))) {
+ fs.writeFileSync(path.join(thePath, "presets.json"), JSON.stringify({
+ "jimarrows": {
+ name: "Jim Arrows",
+ binds: {
+ "A": "left",
+ "S": "down",
+ "W": "up",
+ "D": "right",
+ "ArrowLeft": "left",
+ "ArrowDown": "down",
+ "ArrowUp": "up",
+ "ArrowRight": "right",
+ "idle": "idle"
+ }
+ },
+ "jimaskl": {
+ name: "Jim ASKL",
+ binds: {
+ "A": "left",
+ "S": "down",
+ "K": "up",
+ "L": "right"
+ }
+ },
+ "jimdfjk": {
+ name: "Jim DFJK",
+ binds: {
+ "D": "left",
+ "F": "down",
+ "J": "up",
+ "K": "right"
+ }
+ },
+ "jimqwop": {
+ name: "Jim QWOP",
+ binds: {
+ "Q": "left",
+ "W": "down",
+ "O": "up",
+ "P": "right"
+ }
+ }
+ }, null, 2));
+ }
+
if (!fs.existsSync(path.join(thePath, "char.png")) || !fs.existsSync(path.join(thePath, "char.xml"))) {
fs.copyFileSync(path.join(app.getAppPath(), 'web', 'assets', 'jim.png'), path.join(thePath, "char.png"));
fs.copyFileSync(path.join(app.getAppPath(), 'web', 'assets', 'jim.xml'), path.join(thePath, "char.xml"));
}
+ if (!fs.existsSync(path.join(thePath, "xmls", "jim.png")) || !fs.existsSync(path.join(thePath, "xmls", "jim.xml"))) {
+ fs.copyFileSync(path.join(app.getAppPath(), 'web', 'assets', 'jim.png'), path.join(thePath, "xmls", "jim.png"));
+ fs.copyFileSync(path.join(app.getAppPath(), 'web', 'assets', 'jim.xml'), path.join(thePath, "xmls", "jim.xml"));
+ }
+
ipcMain.handle('resizeToSprite', (e, w, h) => {
mainWindow.setResizable(true);
mainWindow.setSize(w, h);
@@ -101,8 +156,9 @@ function createWindow () {
if (err) alert("File error, stat " + fileval);
});
});
- ipcMain.handle('writeConfig', (e, obj) => {
+ ipcMain.handle('writeConfig', (e, obj, binds) => {
fs.writeFileSync(path.join(thePath, "config.json"), obj);
+ fs.writeFileSync(path.join(thePath, "presets.json"), binds);
});
ipcMain.handle('navApp', (e, obj) => {
diff --git a/web/config.css b/web/config.css
index 3e35ebd..2efa949 100644
--- a/web/config.css
+++ b/web/config.css
@@ -62,4 +62,8 @@ button.inset {
button.inset:hover {
color: #aaa;
+}
+
+div.bind {
+ display: inline-block;
}
\ No newline at end of file
diff --git a/web/config.html b/web/config.html
index b3318e6..c74f39b 100644
--- a/web/config.html
+++ b/web/config.html
@@ -20,12 +20,16 @@
+
+
+
+
Character Look
diff --git a/web/config.js b/web/config.js
index eca35bc..7d856f4 100644
--- a/web/config.js
+++ b/web/config.js
@@ -2,18 +2,24 @@ var fs = require("fs");
var json;
var nameGetter = /(.*?)(?=[0-9]+$)/gm;
var parser = new DOMParser();
+var jsonbinds;
+var xmllist;
+var dirpath;
const { ipcRenderer } = require('electron');
const pathjs = require('path');
function loadForm(path) {
json = JSON.parse(fs.readFileSync(pathjs.join(path, "config.json")));
console.log(json);
+
seeValidBinds(pathjs.join(path, "char.xml"));
ipcRenderer.invoke('resizeToSprite', 600, 400);
document.querySelector("input#idle").value = json.binds.idle;
document.querySelector("input#zoom").value = json.charZoom;
document.querySelector("input#opacity").value = json.opacity;
document.querySelector("input#fps").value = json.fps;
+ document.querySelector("div#presets").innerHTML = getPresets(path);
+ document.querySelector("div#xmlPres").innerHTML = getImages(path);
if (json.align) {
document.querySelector("#alignRadioLeft").checked = isTrue(json.align[0]);
document.querySelector("#alignRadioRight").checked = isTrue(json.align[1]);
@@ -25,7 +31,84 @@ function loadForm(path) {
document.querySelector("textarea#binds").value = JSON.stringify(json.binds, null, 2);
}
+function getImages(path) {
+ xmllist = fs.readdirSync(pathjs.join(path, "xmls")).filter((v) => {
+ return v.endsWith(".xml");
+ });
+ return reloadImages();
+}
+
+function reloadImages() {
+ var html = [];
+ Object.entries(xmllist).forEach((xml) => {
+ console.log(xml);
+ html.push(`${xml[1]}
`);
+ });
+ return html.join("\n");
+}
+
+function loadImage(xmlName) {
+ var xmlTemp = fs.readFileSync(pathjs.join(dirpath, "xmls", xmlName), {encoding: "utf-8"});
+ var pngName = parser.parseFromString(xmlTemp.replace(/[^ \S]/gm, ""), "text/xml").getElementsByTagName("TextureAtlas")[0].getAttribute("imagePath");
+ document.querySelector("input#xmlPath").value = pathjs.join(dirpath, "xmls", xmlName);
+ document.querySelector("input#filePath").value = pathjs.join(dirpath, "xmls", pngName);
+}
+
+function addImage() {
+ var filepath = document.querySelector("input#filePath").value;
+ var xmlpath = document.querySelector("input#xmlPath").value
+ fs.copyFile(filepath, pathjs.join(dirpath, "xmls", pathjs.basename(filepath)), (err) => {
+ if (err) console.log("File error, stat " + fileval);
+ });
+ fs.copyFile(xmlpath, pathjs.join(dirpath, "xmls", pathjs.basename(xmlpath)), (err) => {
+ if (err) console.log("File error, stat " + fileval);
+ });
+ getImages(dirpath);
+}
+
+function getPresets(path) {
+ jsonbinds = JSON.parse(fs.readFileSync(pathjs.join(path, "presets.json")));
+ return reloadPresets();
+}
+
+function reloadPresets() {
+ var html = [];
+ Object.entries(jsonbinds).forEach((binds) => {
+ html.push(`${binds[1].name}
`);
+ });
+ console.log(html);
+ return html.join("\n");
+}
+
+function loadPreset(bind) {
+ document.querySelector("textarea#binds").value = JSON.stringify(jsonbinds[bind].binds, null, 2);
+ document.querySelector("input#idle").value = jsonbinds[bind].idle;
+ document.querySelector("input#fps").value = jsonbinds[bind].fps;
+ document.querySelector("input#zoom").value = jsonbinds[bind].zoom;
+ document.querySelector("#presetname").value = bind;
+}
+
+function addPreset(name) {
+ var theName = document.querySelector(name);
+ var id = theName.value.replace(/[\W\d]/gm, "").toLowerCase();
+ jsonbinds[id] = {
+ name: theName.value,
+ binds: JSON.parse(document.querySelector("textarea#binds").value),
+ idle: document.querySelector("input#idle").value,
+ fps: document.querySelector("input#fps").value,
+ zoom: document.querySelector("input#zoom").value
+ };
+ theName.value = "";
+ document.querySelector("div#presets").innerHTML = reloadPresets();
+}
+
+function removePreset(bind) {
+ delete jsonbinds[bind];
+ document.querySelector("div#presets").innerHTML = reloadPresets();
+}
+
ipcRenderer.on('configPath', function (evt, path) {
+ dirpath = path;
loadForm(path);
});
@@ -55,7 +138,7 @@ function saveForm() {
console.log(json);
if (fileval)
ipcRenderer.invoke('copyFiles', fileval, xmlval);
- ipcRenderer.invoke('writeConfig', JSON.stringify(json, null, 2));
+ ipcRenderer.invoke('writeConfig', JSON.stringify(json, null, 2), JSON.stringify(jsonbinds, null, 2));
return true;
}
diff --git a/web/script.js b/web/script.js
index bc791c1..39ea83f 100644
--- a/web/script.js
+++ b/web/script.js
@@ -220,6 +220,7 @@ function doanimate(st) {
}
function theThing() {
+ if (anim == null || anim == undefined) ipcRenderer.invoke('navApp', 'web/config.html');
char.style.objectPosition = `-${anim[fn].x}px -${anim[fn].y}px`;
char.style.width = `${anim[fn].w}px`;
char.style.height = `${anim[fn].h}px`;