diff options
| author | historia <[not public]> | 2026-07-05 19:18:50 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-05 19:18:50 -0400 |
| commit | 7b5ed92e003d8a4bf9bdc69d43b7354eb2260dfa (patch) | |
| tree | 04310b22c25e2d9fe86b2c06e78e12d8f4caa61b /internal/admin/static/hazardeditor.js | |
| parent | 6bd5365cc22f84c047c1585e3f54571af46f53e5 (diff) | |
| download | thehouseoficarus-7b5ed92e003d8a4bf9bdc69d43b7354eb2260dfa.tar.gz | |
feat: duplicate items/obj/mobs from sidebar. item inputs fields changed to search fields
Diffstat (limited to 'internal/admin/static/hazardeditor.js')
| -rw-r--r-- | internal/admin/static/hazardeditor.js | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/internal/admin/static/hazardeditor.js b/internal/admin/static/hazardeditor.js index ff2857d..c4eb0b5 100644 --- a/internal/admin/static/hazardeditor.js +++ b/internal/admin/static/hazardeditor.js @@ -8,13 +8,13 @@ var HAZARD_SECTIONS = [ { id: 'core', label: 'Core', always: true, fields: [ - ['name', 'Name', 'text'], - ['description', 'Description', 'textarea', '', 'wide'], - ['warn_message', 'Warn Message', 'text', '', 'wide'], - ['hit_message', 'Hit Message', 'text'], - ['miss_message', 'Miss Message', 'text'], - ['required_item', 'Required Item', 'text'], - ['speed', 'Speed', 'number', '', 'narrow'], + ['name', 'Name', 'text', 'toxic gas'], + ['description', 'Description', 'textarea', 'A cloud of toxic gas fills the room.', 'wide'], + ['warn_message', 'Warn Message', 'text', 'The air grows thick with toxic fumes...', 'wide'], + ['hit_message', 'Hit Message', 'text', 'You cough and choke on the toxic gas!'], + ['miss_message', 'Miss Message', 'text', 'You hold your breath and avoid the fumes.'], + ['required_item', 'Required Item', 'text', 'e.g. gas_mask'], + ['speed', 'Speed', 'number', '10', 'narrow'], ] }, { @@ -22,9 +22,9 @@ var HAZARD_SECTIONS = [ detect: function(d) { return d.attack_type || d.attack || d.attack_bonus || d.max_hit; }, fields: [ ['attack_type', 'Attack Type', 'select', 'stab|slash|crush|ranged|science'], - ['attack', 'Attack', 'number', '', 'narrow'], - ['attack_bonus', 'Attack Bonus', 'number', '', 'narrow'], - ['max_hit', 'Max Hit', 'number', '', 'narrow'], + ['attack', 'Attack', 'number', '5', 'narrow'], + ['attack_bonus', 'Attack Bonus', 'number', '0', 'narrow'], + ['max_hit', 'Max Hit', 'number', '3', 'narrow'], ] } ]; @@ -99,6 +99,7 @@ function renderHazardEditor(id, data) { html += '<div class="btn-row">'; html += '<button class="btn btn-primary" onclick="saveHazard()">Save</button>'; + html += '<button class="btn" onclick="duplicateHazard()">Duplicate</button>'; html += '<button class="btn btn-danger" onclick="deleteHazard()">Delete</button>'; html += '<button class="btn btn-sm" style="margin-left:auto" onclick="createNewDir()">New Directory</button>'; html += '</div>'; @@ -228,3 +229,45 @@ function deleteHazard() { loadList(); }).catch(function(e) { notify('Delete failed: ' + e.message, 'error'); }); } + +function duplicateHazard() { + var baseID = hazardID + '_copy'; + var newID = baseID; + var counter = 2; + while (true) { + var exists = false; + for (var i = 0; i < allIDs.length; i++) { + if (allIDs[i] === newID) { exists = true; break; } + } + if (!exists) break; + newID = baseID + '_' + counter; + counter++; + } + + var copy = JSON.parse(JSON.stringify(hazardData)); + delete copy._raw; + delete copy._path; + copy.id = newID; + + var dir = ''; + if (hazardData._path) { + var parts = hazardData._path.split('/'); + var parentDir = parts[parts.length - 2]; + if (parentDir !== 'hazards') dir = parentDir; + } + + API.post('/api/hazards', {id: newID}).then(function() { + var putOp = API.put('/api/hazards/' + encodeURIComponent(newID), copy); + if (dir) { + return putOp.then(function() { + return API.post('/api/hazards/move', {id: newID, dir: dir}); + }); + } + return putOp; + }).then(function() { + notify('Duplicated as ' + newID, 'success'); + updateUndoBar(); + loadList(); + loadHazardEditor(newID); + }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); +} |
