Progress!!
This commit is contained in:
parent
9348cb1926
commit
6a8fc1685a
5 changed files with 160 additions and 19 deletions
|
|
@ -18,7 +18,6 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const app = express()
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
|
|
|
|||
|
|
@ -78,23 +78,29 @@
|
|||
<div class="text-center d-block">
|
||||
<img class="header" src="/assets/img/logo.png">
|
||||
<h4>Geolosys Deposit Configurator</h4>
|
||||
<h5>Made with 💙 by
|
||||
<a href="https://oitsjustjose.com/">oitsjustjose</a>
|
||||
</h5>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<h4>Ores</h4>
|
||||
|
||||
<div class="accordion" id="oreconfig">
|
||||
<div class="accordion mb-4" id="oreconfig">
|
||||
</div>
|
||||
|
||||
<h4>Stones</h4>
|
||||
<h4>Stones - 🛠 WIP 😭</h4>
|
||||
|
||||
<div class="accordion" id="stoneconfig">
|
||||
|
||||
<div class="accordion mb-4" id="stoneconfig">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary m-auto mb-3 d-block" id="generate-btn">
|
||||
Generate
|
||||
</button>
|
||||
|
||||
<h5 class="text-center">
|
||||
Made with 💙 by
|
||||
<a href="https://oitsjustjose.com/">oitsjustjose</a>
|
||||
</h5>
|
||||
<h6 class="text-center">
|
||||
Source Code Hosted on
|
||||
<a href="https://github.com/oitsjustjose/geolosys-config-generator" target="_blank">GitHub</a>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
img.header {
|
||||
width: 98vw;
|
||||
max-width: 128px;
|
||||
}
|
||||
|
||||
input.json-invalid {
|
||||
border: 4px solid red;
|
||||
}
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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 <a href="https://oitsjustjo.se/GelX-uC1s" target="_blank">Biome Type</a>'
|
||||
)
|
||||
);
|
||||
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 <a href="https://oitsjustjo.se/GelX-uC1s" target="_blank">Biome Type</a>'
|
||||
);
|
||||
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, {});
|
||||
|
|
|
|||
Loading…
Reference in a new issue