Simplified weapon creation function in filterWeapons.js
This commit is contained in:
+1
-12
@@ -564,7 +564,6 @@ form.addEventListener('submit', e => {
|
|||||||
const newId = weapons.length
|
const newId = weapons.length
|
||||||
? Math.max(...weapons.map(w => w.id)) + 1
|
? Math.max(...weapons.map(w => w.id)) + 1
|
||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
const weapon = {
|
const weapon = {
|
||||||
id: newId,
|
id: newId,
|
||||||
name: data.get('name'),
|
name: data.get('name'),
|
||||||
@@ -575,22 +574,12 @@ form.addEventListener('submit', e => {
|
|||||||
damage_multiplier: parseFloat(data.get('multiplier')),
|
damage_multiplier: parseFloat(data.get('multiplier')),
|
||||||
guntype: data.getAll('gun-type')
|
guntype: data.getAll('gun-type')
|
||||||
};
|
};
|
||||||
|
|
||||||
// 2) Add it local
|
|
||||||
weapons.push(weapon);
|
weapons.push(weapon);
|
||||||
|
populateWeapons();
|
||||||
// 3) Refresh UI
|
|
||||||
populateWeapons(); // repopulate <select id="weapon-select">
|
|
||||||
|
|
||||||
// **Here you can pass `weapon` to your game logic**
|
|
||||||
console.log('Created weapon:', weapon);
|
|
||||||
|
|
||||||
// Close & reset
|
|
||||||
modal.style.display = 'none';
|
modal.style.display = 'none';
|
||||||
form.reset();
|
form.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Optional: click outside form to close
|
|
||||||
modal.addEventListener('click', e => {
|
modal.addEventListener('click', e => {
|
||||||
if (e.target === modal) {
|
if (e.target === modal) {
|
||||||
modal.style.display = 'none';
|
modal.style.display = 'none';
|
||||||
|
|||||||
Reference in New Issue
Block a user