2020-06-24 21:47:54 +02:00
|
|
|
/* eslint-disable no-undef */
|
|
|
|
var button = {};
|
|
|
|
$("button").each((i, e) => {
|
|
|
|
button[e.id] = e;
|
|
|
|
});
|
2020-06-18 19:23:07 +02:00
|
|
|
|
|
|
|
var view = {
|
2020-06-24 21:47:54 +02:00
|
|
|
flat: document.querySelectorAll("div.column > img.skin#flat")[0],
|
|
|
|
mesh: document.querySelectorAll("div.column > div#mesh")[0]
|
2020-06-18 19:23:07 +02:00
|
|
|
};
|
|
|
|
|
2020-06-20 19:21:51 +02:00
|
|
|
var skin = new skinview3d.SkinViewer({
|
2020-06-24 21:47:54 +02:00
|
|
|
domElement: view.mesh,
|
|
|
|
width: 300,
|
|
|
|
height: 300
|
2020-06-20 19:21:51 +02:00
|
|
|
});
|
2020-06-18 19:23:07 +02:00
|
|
|
|
2020-06-20 19:21:51 +02:00
|
|
|
var control = skinview3d.createOrbitControls(skin);
|
|
|
|
control.enableRotate = true;
|
|
|
|
control.enableZoom = false;
|
|
|
|
control.enablePan = false;
|
2020-06-18 19:23:07 +02:00
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
function setView(src, controls = true) {
|
|
|
|
button.switch.style.display = "initial";
|
2020-06-18 19:23:07 +02:00
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
view.flat.src = src;
|
|
|
|
skin.skinUrl = src;
|
|
|
|
control.enableRotate = controls;
|
2020-06-18 19:23:07 +02:00
|
|
|
}
|
2020-05-12 09:48:51 +02:00
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
button.switch.addEventListener("click", () => {
|
|
|
|
if (view.flat.style.display == "inline") {
|
|
|
|
view.flat.style.display = "none";
|
|
|
|
view.mesh.style.display = "inline";
|
|
|
|
button.switch.innerHTML = "Switch to 2D";
|
|
|
|
} else {
|
|
|
|
view.flat.style.display = "inline";
|
|
|
|
view.mesh.style.display = "none";
|
|
|
|
button.switch.innerHTML = "Switch to 3D";
|
|
|
|
}
|
2020-06-20 19:21:51 +02:00
|
|
|
});
|
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
if (button.download && button.save) {
|
|
|
|
button.download.addEventListener("click", () => {
|
|
|
|
ipcRenderer.send("download", {
|
|
|
|
url: view.flat.src,
|
|
|
|
properties: {
|
|
|
|
saveAs: true
|
|
|
|
}
|
2020-06-20 19:21:51 +02:00
|
|
|
});
|
2020-05-12 19:02:20 +02:00
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
ipcRenderer.on("downloadResult", () => {
|
|
|
|
notify("success", "Download successful.");
|
|
|
|
});
|
2020-06-20 19:21:51 +02:00
|
|
|
});
|
2020-06-24 21:47:54 +02:00
|
|
|
button.save.addEventListener("click", () => {
|
|
|
|
const src = view.flat.src;
|
|
|
|
const r = new RegExp(/^data:image\/png;base64,/);
|
|
|
|
|
|
|
|
if (r.test(src)) {
|
|
|
|
notify("primary", "Decoding Base64...");
|
|
|
|
var data = src.replace(/^data:image\/png;base64,/, "");
|
|
|
|
fs.writeFile(path.join(__dirname + `/../assets/skins/download/${Date.now()}.png`), data, "base64", function(err) {
|
|
|
|
if (err) {
|
|
|
|
notify("danger", "Skin has not been saved: " + err);
|
|
|
|
} else {
|
|
|
|
notify("success", "Skin has been saved");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
notify("primary", "Getting skin...");
|
|
|
|
axios({
|
|
|
|
method: "get",
|
|
|
|
url: src,
|
|
|
|
responseType: "stream",
|
|
|
|
adapter: require("axios/lib/adapters/http")
|
|
|
|
}).then((res) => {
|
|
|
|
var p = res.request.path.split("/")[2];
|
|
|
|
if (p.split(".").length < 2) {
|
|
|
|
p = p + ".png";
|
|
|
|
}
|
|
|
|
res.data.pipe(fs.createWriteStream(path.join(__dirname + `/../assets/skins/download/${p}`)));
|
|
|
|
notify("success", "Save successful");
|
|
|
|
});
|
|
|
|
}
|
2020-06-20 19:21:51 +02:00
|
|
|
});
|
|
|
|
}
|
2020-06-18 19:23:07 +02:00
|
|
|
|
2020-06-24 21:47:54 +02:00
|
|
|
fs.readFile(path.join(__dirname + "/../assets/skins/dummy.png"), "base64", (err, data) => {
|
|
|
|
if (err) throw err;
|
|
|
|
setView("data:image/png;base64," + data);
|
2020-06-18 19:23:07 +02:00
|
|
|
});
|