diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8c9cc19 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/minecraft-data"] + path = external/minecraft-data + url = https://github.com/PrismarineJS/minecraft-data.git diff --git a/README.md b/README.md index b8326c9..32a8a94 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # minecraft-artifier-js JavaScript/Node.js Web Converter from image to Minecraft blocks.
-Can open and save 1.12 and lower .schematics of Minecraft. +Can open and save 1.20 and lower .schematics of Minecraft. Public part of minecraftart.netlify.com diff --git a/app/index.html b/app/index.html index 094564c..3ede317 100644 --- a/app/index.html +++ b/app/index.html @@ -1,399 +1,534 @@ - - Minecraft Art To Block - - - - + + Minecraft Art To Block + + + + + <%=require('./modal.html')%> - <%=require('./modal.html')%> + - - - -
Convert to commands..
-
Help -
-
- FAQ -
-
- Keyboard/mouse controls -
-
-
+ + +
+ +
+
+ +
+
+
+ History: +
+
+ Open +
+
+
+
+ +
+
...
+
+
+ - + + diff --git a/app/index.js b/app/index.js index ed95128..f624bcb 100644 --- a/app/index.js +++ b/app/index.js @@ -1,273 +1,314 @@ -'use strict' +"use strict"; -import './style.css' -import 'bulma/css/bulma.css' +import "./style.css"; +import "bulma/css/bulma.css"; -import ConvertWorker from 'worker-loader!./models/convert.js' -import MineartCanvas from './models/canvas.js' +import ConvertWorker from "worker-loader!./models/convert.js"; +import MineartCanvas from "./models/canvas.js"; -const blocks = require('../static/baked_blocks.json') +const blocks = require("../static/baked_blocks.json"); blocks.forEach((item) => { - item.src = require('../static/textures/' + item.texture_image) - delete item.texture_image -}) + item.src = require("../static/textures/" + item.texture_image); + delete item.texture_image; +}); const store = { - blocksDefault: blocks, - convertWorker: new ConvertWorker(), - mineartCanvas: new MineartCanvas(), - canvasTemp: document.createElement('canvas'), - localStorage: window.localStorage, - uploadedType: null, - uploadedImage: new Image(), - uploadedImageName: null, - minecraftVersion: 12, - waitForLoaded: { - arr: null, - width: null, - height: null - }, - isSaved: true, - leftClick: false, - findBlockById(id) { - return this.blocksDefault.find((item) => { - if (item.id === id) { - return true - } - }) + blocksDefault: blocks, + convertWorker: new ConvertWorker(), + mineartCanvas: new MineartCanvas(), + canvasTemp: document.createElement("canvas"), + localStorage: window.localStorage, + uploadedType: null, + uploadedImage: new Image(), + uploadedImageName: null, + minecraftVersion: 20, + waitForLoaded: { + arr: null, + width: null, + height: null, + }, + isSaved: true, + leftClick: false, + findBlockById(id) { + return this.blocksDefault.find((item) => { + if (item.id === id) { + return true; + } + }); + }, + findBlockByGameId(blockId, dataId) { + const dataIrrelevant = [ + 18, 99, 100, 202, 216, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, + ]; + const dataAxis = [17, 162]; + return this.blocksDefault.find((item) => { + if (dataAxis.indexOf(blockId) >= 0 && dataId >= 4) { + let tempDataId = dataId % 4; + if ( + item.block_id === blockId && + item.data_id === tempDataId && + item.axis + ) { + return true; + } + } else if (dataIrrelevant.indexOf(blockId) >= 0) { + if (item.block_id === blockId) { + return true; + } + } else if ( + item.block_id === blockId && + item.data_id === dataId && + !item.axis + ) { + return true; + } + }); + }, + showLoading() { + document.querySelector(".loading-overlay").classList.add("is-active"); + }, + hideLoading() { + document.querySelector(".loading-overlay").classList.remove("is-active"); + }, + startScreen: require("./screens/start.js").output, + settingsScreen: require("./screens/settings.js").output, + editorScreen: require("./screens/editor.js").output, + convertScreen: require("./screens/convert.js").output, + modals: { + items: {}, + $root: document.querySelector(".modal"), + $closeBtn: document.querySelector(".modal-close"), + init() { + const modalList = document.querySelectorAll('div[id^="modal-"]'); + modalList.forEach((item) => { + const id = item.id.match(/(modal\-)(.*)/)[2]; + this.items[id] = item; + }); }, - findBlockByGameId(blockId, dataId) { - const dataIrrelevant = [18, 99, 100, 202, 216, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250] - const dataAxis = [17, 162] - return this.blocksDefault.find((item) => { - if (dataAxis.indexOf(blockId) >= 0 && dataId >= 4) { - let tempDataId = dataId % 4 - if (item.block_id === blockId && item.data_id === tempDataId && item.axis) { - return true - } - } else if (dataIrrelevant.indexOf(blockId) >= 0) { - if (item.block_id === blockId) { - return true - } - } else if (item.block_id === blockId && item.data_id === dataId && !item.axis) { - return true - } - }) + openModal(name) { + this.$root.classList.add("is-active"); + for (let key in this.items) { + this.items[key].classList.add("hidden"); + } + this.items[name].classList.remove("hidden"); + store.editorScreen.closeTopbarMenus(); }, - showLoading() { - document.querySelector('.loading-overlay').classList.add('is-active') + closeModal() { + this.$root.classList.remove("is-active"); + for (let key in this.items) { + const video = this.items[key].querySelector("iframe"); + if (video) { + video.src = video.src; + } + this.items[key].classList.add("hidden"); + } }, - hideLoading() { - document.querySelector('.loading-overlay').classList.remove('is-active') + }, + errors: { + items: {}, + init() { + const errorList = document.querySelectorAll('div[id^="error-"]'); + errorList.forEach((item) => { + const id = item.id.match(/(error\-)(.*)/)[2]; + this.items[id] = item; + item.classList.add("hidden"); + }); }, - startScreen: require('./screens/start.js').output, - settingsScreen: require('./screens/settings.js').output, - editorScreen: require('./screens/editor.js').output, - convertScreen: require('./screens/convert.js').output, - modals: { - items: {}, - $root: document.querySelector('.modal'), - $closeBtn: document.querySelector('.modal-close'), - init() { - const modalList = document.querySelectorAll('div[id^="modal-"]') - modalList.forEach((item) => { - const id = item.id.match(/(modal\-)(.*)/)[2] - this.items[id] = item - }) - }, - openModal(name) { - this.$root.classList.add('is-active') - for (let key in this.items) { - this.items[key].classList.add('hidden') - } - this.items[name].classList.remove('hidden') - store.editorScreen.closeTopbarMenus() - }, - closeModal() { - this.$root.classList.remove('is-active') - for (let key in this.items) { - const video = this.items[key].querySelector('iframe') - if (video) { - video.src = video.src - } - this.items[key].classList.add('hidden') - } + triggerError(id, text, timeout) { + if (this.items[id]) { + if (!this.items[id].classList.contains("hidden")) { + clearTimeout(this.items[id].timeout); + this.items[id].timeout = null; } + this.items[id].querySelector(".warning-body").innerHTML = text; + this.items[id].classList.remove("hidden"); + this.items[id].timeout = setTimeout(() => { + this.items[id].classList.add("hidden"); + this.items[id].timeout = null; + }, timeout); + } else { + console.error("No error id!"); + } }, - errors: { - items: {}, - init() { - const errorList = document.querySelectorAll('div[id^="error-"]') - errorList.forEach((item) => { - const id = item.id.match(/(error\-)(.*)/)[2] - this.items[id] = item - item.classList.add('hidden') - }) - }, - triggerError(id, text, timeout) { - if (this.items[id]) { - if (!this.items[id].classList.contains('hidden')) { - clearTimeout(this.items[id].timeout) - this.items[id].timeout = null - } - this.items[id].querySelector('.warning-body').innerHTML = text - this.items[id].classList.remove('hidden') - this.items[id].timeout = setTimeout(() => { - this.items[id].classList.add('hidden') - this.items[id].timeout = null - }, timeout) - } else { - console.error('No error id!') - } - }, - closeError(id) { - if (this.items[id]) { - if (this.items[id].classList.contains('hidden')) { return } - this.items[id].classList.add('hidden') - if (this.items[id].timeout) { - clearTimeout(this.items[id].timeout) - this.items[id].timeout = null - } - } else { - console.error('No error id!') - } + closeError(id) { + if (this.items[id]) { + if (this.items[id].classList.contains("hidden")) { + return; } - }, - setEventListeners() { - this.convertWorker.onmessage = (e) => { - if (document.readyState !== 'complete') { - store.waitForLoaded.arr = e.data - store.waitForLoaded.width = store.canvasTemp.width - store.waitForLoaded.height = store.canvasTemp.height - return - } - store.hideLoading() - this.settingsScreen.changeToEditorScreen() - this.mineartCanvas.init(store.editorScreen.$canvas) - this.mineartCanvas.setImageSizes(store.canvasTemp.width, store.canvasTemp.height) - this.mineartCanvas.open(e.data) - store.editorScreen.setEyedrop(1) - store.editorScreen.setBrushSize(3) - store.editorScreen.resetScreen() + this.items[id].classList.add("hidden"); + if (this.items[id].timeout) { + clearTimeout(this.items[id].timeout); + this.items[id].timeout = null; } + } else { + console.error("No error id!"); + } + }, + }, + setEventListeners() { + this.convertWorker.onmessage = (e) => { + if (document.readyState !== "complete") { + store.waitForLoaded.arr = e.data; + store.waitForLoaded.width = store.canvasTemp.width; + store.waitForLoaded.height = store.canvasTemp.height; + return; + } + store.hideLoading(); + this.settingsScreen.changeToEditorScreen(); + this.mineartCanvas.init(store.editorScreen.$canvas); + this.mineartCanvas.setImageSizes( + store.canvasTemp.width, + store.canvasTemp.height + ); + this.mineartCanvas.open(e.data); + store.editorScreen.setEyedrop(1); + store.editorScreen.setBrushSize(3); + store.editorScreen.resetScreen(); + }; - this.modals.$closeBtn.onclick = () => { - this.modals.closeModal() - } + this.modals.$closeBtn.onclick = () => { + this.modals.closeModal(); + }; - window.addEventListener("load", function(event) { - if (store.waitForLoaded.arr !== null) { - store.settingsScreen.changeToEditorScreen() - store.mineartCanvas.init(store.editorScreen.$canvas) - store.mineartCanvas.setImageSizes(store.waitForLoaded.width, store.waitForLoaded.height) - store.mineartCanvas.open(store.waitForLoaded.arr) - store.waitForLoaded = null - store.hideLoading() - } - }); + window.addEventListener("load", function (event) { + if (store.waitForLoaded.arr !== null) { + store.settingsScreen.changeToEditorScreen(); + store.mineartCanvas.init(store.editorScreen.$canvas); + store.mineartCanvas.setImageSizes( + store.waitForLoaded.width, + store.waitForLoaded.height + ); + store.mineartCanvas.open(store.waitForLoaded.arr); + store.waitForLoaded = null; + store.hideLoading(); + } + }); - document.addEventListener("DOMContentLoaded", function(event) { - document.body.style.display = 'block' - }); + document.addEventListener("DOMContentLoaded", function (event) { + document.body.style.display = "block"; + }); - document.addEventListener('keydown', (e) => { - if (document.activeElement.tagName === 'INPUT' || document.querySelector('section.editor-screen').classList.contains('hidden')) { - return - } - if (store.leftClick) { return } - store.editorScreen.closeTopbarMenus() - switch (e.which) { - case 17: - store.mineartCanvas.setTool('clicker') - store.mineartCanvas.render() - break - case 80: - document.querySelector('.editor-tools input[value="pencil"]').click() - break - case 66: - document.querySelector('.editor-tools input[value="brush"]').click() - break - case 85: - document.querySelector('.editor-tools input[value="bucket"]').click() - break - case 69: - document.querySelector('.editor-tools input[value="eyedropper"]').click() - break - case 90: - if (e.ctrlKey) { - store.editorScreen.undoOnce() - } else { - document.querySelector('.editor-tools input[value="zoom"]').click() - } - break - case 89: - if (e.ctrlKey) { - store.editorScreen.redoOnce() - } - break - case 71: - document.querySelector('.editor-tools input[value="grab"]').click() - break - case 79: - store.editorScreen.$settingsOriginal.click() - break - case 37: - store.mineartCanvas.moveOffset(1, 0) - break - case 38: - store.mineartCanvas.moveOffset(0, 1) - break - case 39: - store.mineartCanvas.moveOffset(-1, 0) - break - case 40: - store.mineartCanvas.moveOffset(0, -1) - break - case 219: - if (store.editorScreen.currentTool === 'pencil' || store.editorScreen.currentTool === 'brush') { - store.editorScreen.$brushMinus.click() - } - break - case 221: - if (store.editorScreen.currentTool === 'pencil' || store.editorScreen.currentTool === 'brush') { - store.editorScreen.$brushPlus.click() - } - break - } - }) + document.addEventListener("keydown", (e) => { + if ( + document.activeElement.tagName === "INPUT" || + document + .querySelector("section.editor-screen") + .classList.contains("hidden") + ) { + return; + } + if (store.leftClick) { + return; + } + store.editorScreen.closeTopbarMenus(); + switch (e.which) { + case 17: + store.mineartCanvas.setTool("clicker"); + store.mineartCanvas.render(); + break; + case 80: + document.querySelector('.editor-tools input[value="pencil"]').click(); + break; + case 66: + document.querySelector('.editor-tools input[value="brush"]').click(); + break; + case 85: + document.querySelector('.editor-tools input[value="bucket"]').click(); + break; + case 69: + document + .querySelector('.editor-tools input[value="eyedropper"]') + .click(); + break; + case 90: + if (e.ctrlKey) { + store.editorScreen.undoOnce(); + } else { + document.querySelector('.editor-tools input[value="zoom"]').click(); + } + break; + case 89: + if (e.ctrlKey) { + store.editorScreen.redoOnce(); + } + break; + case 71: + document.querySelector('.editor-tools input[value="grab"]').click(); + break; + case 79: + store.editorScreen.$settingsOriginal.click(); + break; + case 37: + store.mineartCanvas.moveOffset(1, 0); + break; + case 38: + store.mineartCanvas.moveOffset(0, 1); + break; + case 39: + store.mineartCanvas.moveOffset(-1, 0); + break; + case 40: + store.mineartCanvas.moveOffset(0, -1); + break; + case 219: + if ( + store.editorScreen.currentTool === "pencil" || + store.editorScreen.currentTool === "brush" + ) { + store.editorScreen.$brushMinus.click(); + } + break; + case 221: + if ( + store.editorScreen.currentTool === "pencil" || + store.editorScreen.currentTool === "brush" + ) { + store.editorScreen.$brushPlus.click(); + } + break; + } + }); - document.addEventListener('keyup', (e) => { - if (document.activeElement.tagName === 'INPUT' || document.querySelector('section.editor-screen').classList.contains('hidden')) { - return - } - if (store.leftClick) { return } - switch (e.which) { - case 17: - store.mineartCanvas.setTool(store.editorScreen.currentTool) - break - } - }) + document.addEventListener("keyup", (e) => { + if ( + document.activeElement.tagName === "INPUT" || + document + .querySelector("section.editor-screen") + .classList.contains("hidden") + ) { + return; + } + if (store.leftClick) { + return; + } + switch (e.which) { + case 17: + store.mineartCanvas.setTool(store.editorScreen.currentTool); + break; + } + }); - document.addEventListener('mousedown', (e) => { - store.leftClick = true - }) + document.addEventListener("mousedown", (e) => { + store.leftClick = true; + }); - document.addEventListener('mouseup', (e) => { - store.leftClick = false - }) - } -} + document.addEventListener("mouseup", (e) => { + store.leftClick = false; + }); + }, +}; -store.mineartCanvas.setBlocks(blocks) +store.mineartCanvas.setBlocks(blocks); blocks.sort((a, b) => { - return a.h - b.h + a.s - b.s + b.l - a.l; -}) + return a.h - b.h + a.s - b.s + b.l - a.l; +}); -store.startScreen.init(store) -store.settingsScreen.init(store) -store.editorScreen.init(store) -store.convertScreen.init(store) -store.errors.init() -store.modals.init() -store.setEventListeners() -store.editorScreen.fillBlockList() +store.startScreen.init(store); +store.settingsScreen.init(store); +store.editorScreen.init(store); +store.convertScreen.init(store); +store.errors.init(); +store.modals.init(); +store.setEventListeners(); +store.editorScreen.fillBlockList(); diff --git a/app/modal.html b/app/modal.html index c71c19f..a98a18b 100644 --- a/app/modal.html +++ b/app/modal.html @@ -1,50 +1,62 @@