diff --git a/src/app.ts b/src/app.ts index 66bed57..1d12b48 100644 --- a/src/app.ts +++ b/src/app.ts @@ -18,7 +18,6 @@ declare global { } } - const app = express() app.set('view engine', 'ejs') diff --git a/src/app/views/home.ejs b/src/app/views/home.ejs index ac7e684..b5f7cbf 100644 --- a/src/app/views/home.ejs +++ b/src/app/views/home.ejs @@ -78,23 +78,29 @@

Geolosys Deposit Configurator

-
Made with 💙 by - oitsjustjose -

Ores

-
+
-

Stones

+

Stones - 🛠 WIP 😭

-
+ +
+ + +
+ Made with 💙 by + oitsjustjose +
Source Code Hosted on GitHub diff --git a/src/public/assets/css/base.css b/src/public/assets/css/base.css index 6b48e4c..679e7cc 100644 --- a/src/public/assets/css/base.css +++ b/src/public/assets/css/base.css @@ -1,4 +1,8 @@ img.header { width: 98vw; max-width: 128px; +} + +input.json-invalid { + border: 4px solid red; } \ No newline at end of file diff --git a/src/public/assets/js/modules/events.module.js b/src/public/assets/js/modules/events.module.js index 05357c2..3d5de34 100644 --- a/src/public/assets/js/modules/events.module.js +++ b/src/public/assets/js/modules/events.module.js @@ -2,7 +2,102 @@ export const preInit = () => { switch112Listener(); }; -export const init = () => { }; +export const init = () => { + generateJSONListener(); +}; + +const generateJSONListener = () => { + const btn = document.getElementById('generate-btn'); + const oreCfg = document.getElementById('oreconfig'); + const stoneCfg = document.getElementById('stoneconfig'); + + btn.addEventListener('click', () => { + btn.attributes.disabled = true; + + let ores = Array(); + + oreCfg.querySelectorAll('form').forEach((form) => { + const ore = parseForm(form); + + if (ore == -1) { + return; + } else { + ores.push(ore); + } + }); + + console.log(ores); + + // TODO: save this to the database!!!! If there's no name, name it some random ID maybe? /shrug + btn.attributes.disabled = false; + }); +}; + +const parseForm = (form) => { + let ore = { + 'blocks': Array(), + 'samples': Array() + }; + + const allInputs = Array.from(form.querySelectorAll('input, select[name="type"]')); + + for (let [idx, inp] of allInputs.entries()) { + let err = false; + if (inp.required && !inp.value) { + err = true; + inp.classList.add('json-invalid'); + } else { + if (inp.classList.contains('json-invalid')) { + inp.classList.remove('json-invalid'); + } + } + + if (err) { + alert("There were errors in your form (see outlined in red). Your JSON will not be generated until you correct this."); + return -1; + } + + if (!inp.value) { /* Skip over *optional*, empty attrs */ + continue; + } + + if (inp.name.includes('weight-')) { /* Skip weight items because they're parsed using idx+1 */ + continue; + } + + if (inp.name.includes('block-ore-')) { /* Parse out ores */ + ore.blocks.push(inp.value, parseInt(allInputs[idx + 1].value)); + } else if (inp.name.includes('block-sample-')) { /* Parse out samples*/ + ore.samples.push(inp.value, parseInt(allInputs[idx + 1].value)); + } else if (inp.name.includes('-')) { /* parse out any JSONArray() objs */ + const key = inp.name.substr(0, inp.name.indexOf('-')); + + if (Object.keys(ore).includes(key)) { + ore[key].push(parsed(inp.value)); + } else { + ore[key] = [parsed(inp.value)]; + } + } else { /* parse anything else */ + if (inp.type == 'checkbox') { + ore[inp.name] = inp.checked; + } else { + ore[inp.name] = parsed(inp.value); + } + } + } + + console.log(ore); +}; + +const parsed = (any) => { + if (typeof any == 'string') { + return String(any); + } else if (typeof any == 'number') { + return Number(any); + } + console.warn(`Value ${any} could not be parsed. 💩`); + return any; +}; const switch112Listener = () => { const switch112 = document.getElementById('switch-112-mode'); diff --git a/src/public/assets/js/modules/generators.module.js b/src/public/assets/js/modules/generators.module.js index 5393748..c129562 100644 --- a/src/public/assets/js/modules/generators.module.js +++ b/src/public/assets/js/modules/generators.module.js @@ -276,30 +276,67 @@ const makeOreForm = (formId, usingNewConfig) => { ); form.appendChild(dimBlWrapper); - form.appendChild(makeHeader('Biomes To Spawn / Not Spawn')); + /* Dynamically show biome white/blacklist if a biome-selective type has been chosen */ + const biomeHeader = makeHeader('Biomes To Spawn / Not Spawn'); + biomeHeader.style.display = 'none'; + form.appendChild(biomeHeader); + const biomeWrapper = document.createElement('div'); biomeWrapper.className = 'mb-3'; - biomeWrapper.appendChild( - makeExpandableSet( - 'biomes', - biomeWrapper, - 'text', - 'Format: <modid:biome> OR Biome Type' - ) - ); form.appendChild(biomeWrapper); + depositType.addEventListener('change', () => { + const type = depositType.value; + + biomeWrapper.innerHTML = ''; + /* Hide the label first */ + biomeHeader.style.display = 'none'; + + if (type == 'depositBiomeMulti' || type == 'depositBiome') { + /* Reveal the header if applicable */ + const biomeGroup = makeExpandableSet( + 'biomes', + biomeWrapper, + 'text', + 'Format: <modid:biome> OR Biome Type' + ); + const checkWrapper = document.createElement('div'); + checkWrapper.className = 'input-group-text'; + + const checkLbl = document.createElement('label'); + checkLbl.for = 'isWhitelist'; + checkLbl.className = 'mr-2'; + checkLbl.innerText = 'Whitelist?'; + + const checkInput = document.createElement('input'); + checkInput.className = 'form-check-input'; + checkInput.type = 'checkbox'; + checkInput.name = 'isWhitelist'; + checkInput.value = ''; + checkInput.setAttribute('aria-label', 'Checkbox for Text Input:'); + checkWrapper.appendChild(checkLbl); + checkWrapper.appendChild(checkInput); + + biomeGroup.insertBefore(checkWrapper, biomeGroup.childNodes[biomeGroup.childNodes.length - 1]); + + // biomeGroup.appendChild() + biomeHeader.style.display = 'block'; + biomeWrapper.appendChild(biomeGroup); + } + }); + form.appendChild(makeHeader('Blocks This Deposit May Replace')); const replWrapper = document.createElement('div'); replWrapper.className = 'mb-3'; replWrapper.appendChild( makeExpandableSet( - 'replacements', + 'blockStateMatchers', replWrapper, 'text', 'Format: <modid:block> or <modid:block:meta>' ) ); + replWrapper.querySelector('input').removeAttribute('required'); form.appendChild(replWrapper); return form; @@ -383,7 +420,7 @@ const makeExpandableSet = (prefix, container, type, tooltip) => { if (tooltip) { input.setAttribute('data-toggle', 'tooltip'); input.setAttribute('data-placement', 'top'); - input.setAttribute('data-html', 'true'); + input.setAttribute('data-html', 'true'); input.setAttribute('title', tooltip); input.setAttribute('required', 'required'); new bootstrap.Tooltip(input, {});