made locked equipment selectable

This commit is contained in:
Frederik Palmø 2022-03-20 21:44:37 +01:00
parent ea32a1df60
commit 1f4894f946
4 changed files with 792 additions and 762 deletions

View File

@ -179,7 +179,7 @@
<hr>
<li>
<b>Locked Equipment</b>
<button id="clear-equipment" onclick="update()">Clear Locked Equipment</button>
<button id="clear-equipment" onclick="clearEquipment()">Clear Locked Equipment</button>
</li>
<li>
<table>
@ -193,28 +193,31 @@
</thead>
<tbody>
<tr>
<template id="locked-option">
<option value="">Placeholder</option>
</template>
<td>
<select type="text" id="select-head" name="locked-equipment"
<select type="text" id="select-helmet" name="locked-equipment"
onchange="update()">
<option>None</option>
<option value="none">None</option>
</select>
</td>
<td>
<select type="text" id="select-chest" name="locked-equipment"
<select type="text" id="select-chestpiece" name="locked-equipment"
onchange="update()">
<option>None</option>
<option value="none">None</option>
</select>
</td>
<td>
<select type=" text" id="select-hands" name="locked-equipment"
<select type=" text" id="select-gauntlets" name="locked-equipment"
onchange="update()">
<option>None</option>
<option value="none">None</option>
</select>
</td>
<td>
<select type="text" id="select-legs" name="locked-equipment"
<select type="text" id="select-leggings" name="locked-equipment"
onchange="update()">
<option>None</option>
<option value="none">None</option>
</select>
</td>
</tr>

View File

@ -1,6 +1,5 @@
{
"gauntlets": [
[
{
"id": "all-knowing-gauntlets",
"name": "All-Knowing Gauntlets",
@ -730,5 +729,4 @@
"weight": 2.3
}
]
]
}

View File

@ -1,16 +1,16 @@
const HELMETS = fetch("/data/armor.json")
const HELMETS = fetch("/data/helmets.json")
.then(response => response.json())
.then(data => data.helmets)
.catch(error => console.log(error));
const CHESTPIECES = fetch("/data/armor.json")
const CHESTPIECES = fetch("/data/chestpieces.json")
.then(response => response.json())
.then(data => data.chestpieces)
.catch(error => console.log(error));
const GAUNTLETS = fetch("/data/armor.json")
const GAUNTLETS = fetch("/data/gauntlets.json")
.then(response => response.json())
.then(data => data.gauntlets)
.catch(error => console.log(error));
const LEGGINGS = fetch("/data/armor.json")
const LEGGINGS = fetch("/data/leggings.json")
.then(response => response.json())
.then(data => data.leggings)
.catch(error => console.log(error));
@ -20,19 +20,27 @@ let sortedChestplates;
let sortedGauntlets;
let sortedLeggings;
const SortingMethod = {
AVERAGE,
PHYSICAL,
ELEMENTAL,
IMMUNITIES,
};
// const SortingMethod = {
// AVERAGE,
// POISE,
// PHYSICAL,
// ELEMENTAL,
// IMMUNITIES,
// };
async function init() {
// populate filter selects
populateSelect("locked-option", "select-helmet", await HELMETS);
populateSelect("locked-option", "select-chestpiece", await CHESTPIECES);
populateSelect("locked-option", "select-gauntlets", await GAUNTLETS);
populateSelect("locked-option", "select-leggings", await LEGGINGS);
// precompute and sort list of armor pieces
}
async function update() {
let sorted = sortedCombinations();
// let sorted = sortedCombinations();
}
function updateSortingMethod() {
@ -41,16 +49,34 @@ function updateSortingMethod() {
function fitness(item, order) {
// return fitness of item based on given order
switch (order) {
case SortingMethod.AVERAGE:
return item.defenses.reduce((total, value) => total + value, 0) / item.defenses.length;
case SortingMethod.PHYSICAL:
break;
case SortingMethod.ELEMENTAL:
break;
case SortingMethod.IMMUNITIES:
break;
default:
console.log("error pls fix");
}
// switch (order) {
// case SortingMethod.AVERAGE:
// return item.defenses.reduce((total, value) => total + value, 0) / item.defenses.length;
// case SortingMethod.PHYSICAL:
// break;
// case SortingMethod.ELEMENTAL:
// break;
// case SortingMethod.IMMUNITIES:
// break;
// default:
// console.log("error pls fix");
// }
}
function populateSelect(templateId, destinationId, items) {
let template = document.getElementById(templateId);
let destination = document.getElementById(destinationId);
items.forEach(item => {
let clone = template.content.cloneNode(true);
clone.value = item.id;
clone.innerHTML = item.name;
destination.options.add(new Option(item.name, item.id));
});
}
function clearEquipment() {
[...document.getElementsByName("locked-equipment")].forEach(select => select.selectedIndex = 0);
}

View File

@ -299,5 +299,8 @@ button {
}
.app select {
background-color: var(--secondary);
width: 100%;
color: var(--font-color);
border: 1px solid var(--border);
}