From 034187d1c434b6bee32aeb539ea543f6ec537376 Mon Sep 17 00:00:00 2001
From: historia <[not public]>
Date: Fri, 3 Jul 2026 16:55:23 -0400
Subject: feat: card ui added to drops, hazards, techs, and mods in admin gui
---
internal/admin/static/hazardeditor.js | 226 ++++++++++++++++++++++++++++++++++
1 file changed, 226 insertions(+)
create mode 100644 internal/admin/static/hazardeditor.js
(limited to 'internal/admin/static/hazardeditor.js')
diff --git a/internal/admin/static/hazardeditor.js b/internal/admin/static/hazardeditor.js
new file mode 100644
index 0000000..b07456e
--- /dev/null
+++ b/internal/admin/static/hazardeditor.js
@@ -0,0 +1,226 @@
+var hazardData = null;
+var hazardID = null;
+var expandedCards = {};
+var addedSections = {};
+var cardWidths = {};
+
+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'],
+ ]
+ },
+ {
+ id: 'combat', label: 'Combat',
+ 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'],
+ ]
+ }
+];
+
+function initHazardEditor() {
+ editorType = 'hazards';
+ editorFields = [];
+ loadList();
+ if (window.location.hash) loadHazardEditor(window.location.hash.substring(1));
+}
+
+function cardPath(sec) { return sec.path || ''; }
+
+function getVal(data, sec, key) {
+ return ced_getVal(data, sec, key);
+}
+
+function fieldID(sec, key, idx) {
+ return ced_fieldID(sec, key, idx);
+}
+
+function setupSearchFields() { ced_setupSearchFields(); }
+
+function collectFieldValue(el, type) { return ced_collectFieldValue(el, type); }
+
+function loadHazardEditor(id) {
+ hazardID = id;
+ currentID = id;
+ renderList('');
+ window.location.hash = id;
+ API.get('/api/hazards/' + encodeURIComponent(id)).then(function(data) {
+ hazardData = data;
+ renderHazardEditor(id, data);
+ }).catch(function(e) {
+ $('#editorMain').innerHTML = '
Failed to load: ' + esc(e.message) + '
';
+ });
+}
+
+function loadItem(id) { loadHazardEditor(id); }
+
+function renderHazardEditor(id, data) {
+ var html = 'Hazard: ' + esc(id) + '
';
+ html += '';
+ html += '
';
+
+ html += '';
+ html += '
';
+ HAZARD_SECTIONS.forEach(function(sec) {
+ if (!sec.always && sec.detect && !sec.detect(data) && !addedSections[sec.id]) return;
+ html += renderCard(sec, data);
+ });
+ html += '
';
+
+ html += '
';
+ html += '';
+ html += '';
+ html += '
';
+ html += '
';
+
+ html += '';
+ html += '
' + esc(data._raw || JSON.stringify(data, null, 2)) + '
';
+ html += '
';
+
+ html += '';
+ html += '';
+ html += '';
+ html += '
';
+
+ $('#editorMain').innerHTML = html;
+ setupSearchFields();
+}
+
+function renderCurrent() {
+ if (!hazardData || !hazardID) return;
+ renderHazardEditor(hazardID, hazardData);
+}
+
+function renderCard(sec, data) {
+ var collapsed = expandedCards[sec.id] === false;
+ var isFull = cardWidths[sec.id] !== undefined ? cardWidths[sec.id] : (sec.fullWidth || false);
+ var fullClass = isFull ? ' obj-card-full' : '';
+ var h = '';
+ h += '';
+ if (!collapsed) {
+ h += '
';
+ h += '
';
+ sec.fields.forEach(function(f) {
+ h += renderField(sec, f, data, -1);
+ });
+ h += '
';
+ h += '
';
+ }
+ h += '
';
+ return h;
+}
+
+function renderField(sec, f, data, idx) {
+ return ced_renderField(sec, f, data, idx, null, null, cardPath, fieldID, getVal);
+}
+
+function toggleCard(id) {
+ expandedCards[id] = expandedCards[id] === false ? true : false;
+ renderCurrent();
+}
+
+function toggleCardWidth(id) {
+ cardWidths[id] = !cardWidths[id];
+ renderCurrent();
+}
+
+function removeSection(id) {
+ var sec = HAZARD_SECTIONS.find(function(s) { return s.id === id; });
+ if (!sec) return;
+ if (sec.fields) sec.fields.forEach(function(f) { delete hazardData[f[0]]; });
+ delete addedSections[id];
+ renderCurrent();
+}
+
+function addSection() {
+ var sel = $('#addSectionSelect');
+ var id = sel.value;
+ if (!id) return;
+ var sec = HAZARD_SECTIONS.find(function(s) { return s.id === id; });
+ if (!sec) return;
+
+ if (id === 'combat') {
+ hazardData.attack_type = '';
+ hazardData.attack = 0;
+ hazardData.attack_bonus = 0;
+ hazardData.max_hit = 0;
+ }
+ addedSections[id] = true;
+ expandedCards[id] = true;
+ renderCurrent();
+}
+
+function saveHazard() {
+ if (!ced_validateFields(HAZARD_SECTIONS, fieldID, null)) return;
+
+ var out = {};
+ HAZARD_SECTIONS.forEach(function(sec) {
+ var sectionObj = {};
+ var hasValues = sec.always;
+
+ if (sec.fields) {
+ sec.fields.forEach(function(f) {
+ var fid = fieldID(sec, f[0]);
+ var el = document.getElementById(fid);
+ if (!el) return;
+ var val = collectFieldValue(el, f[2]);
+ if (val !== '' && val !== false && val !== 0 && val !== null) hasValues = true;
+ sectionObj[f[0]] = val;
+ });
+ }
+
+ if (sec.always) {
+ Object.keys(sectionObj).forEach(function(k) { out[k] = sectionObj[k]; });
+ } else if (hasValues) {
+ Object.keys(sectionObj).forEach(function(k) { out[k] = sectionObj[k]; });
+ }
+ });
+
+ ced_cleanOutput(out);
+ out.id = hazardID;
+
+ API.put('/api/hazards/' + encodeURIComponent(hazardID), out).then(function(resp) {
+ notify('Hazard ' + hazardID + ' saved', 'success');
+ updateUndoBar();
+ if (resp && resp._raw) hazardData._raw = resp._raw;
+ }).catch(function(e) { notify('Save failed: ' + e.message, 'error'); });
+}
+
+function deleteHazard() {
+ if (!confirm('Delete hazard "' + hazardID + '"?')) return;
+ API.del('/api/hazards/' + encodeURIComponent(hazardID)).then(function() {
+ notify('Hazard ' + hazardID + ' deleted', 'success');
+ updateUndoBar();
+ hazardID = null;
+ currentID = null;
+ hazardData = null;
+ $('#editorMain').innerHTML = 'Deleted
';
+ loadList();
+ }).catch(function(e) { notify('Delete failed: ' + e.message, 'error'); });
+}
--
cgit v1.2.3