aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/cardeditor.js
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-13 15:07:28 -0400
committerhistoria <[not public]>2026-07-13 15:07:28 -0400
commit93a412aed2b11406399504c81d6d19ed1341908a (patch)
treed99f0c283e6684d266676438fbec4e550bf9c774 /internal/admin/static/cardeditor.js
parentfcc9c0a83df82093efd3a85e8e0dc0768653ea87 (diff)
downloadthehouseoficarus-93a412aed2b11406399504c81d6d19ed1341908a.tar.gz
feat(admin): hide irrelevant combat stats for task mobs, show relevant combat stats for hazards
Diffstat (limited to 'internal/admin/static/cardeditor.js')
-rw-r--r--internal/admin/static/cardeditor.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/internal/admin/static/cardeditor.js b/internal/admin/static/cardeditor.js
index 1b2b76b..f32ea7e 100644
--- a/internal/admin/static/cardeditor.js
+++ b/internal/admin/static/cardeditor.js
@@ -584,3 +584,77 @@ function ced_cleanOutput(obj) {
}
}
}
+
+function ced_unflattenObj(obj) {
+ var result = {};
+ Object.keys(obj).forEach(function(key) {
+ var parts = key.split('.');
+ var current = result;
+ for (var i = 0; i < parts.length - 1; i++) {
+ if (!current[parts[i]]) current[parts[i]] = {};
+ current = current[parts[i]];
+ }
+ current[parts[parts.length - 1]] = obj[key];
+ });
+ return result;
+}
+
+function ced_normalizeAtkTypes(v) {
+ if (Array.isArray(v)) return v.slice();
+ if (typeof v === 'string' && v) return [v];
+ return [];
+}
+
+function ced_renderAtkTypeWidget(data, widgetID, selectFnName) {
+ var combat = data.combat || {};
+ var types = ced_normalizeAtkTypes(combat.attack_types);
+ var melee = types.filter(function(t) { return t === 'stab' || t === 'slash' || t === 'crush'; })[0] || 'crush';
+ var hasRanged = types.indexOf('ranged') >= 0;
+ var hasScience = types.indexOf('science') >= 0;
+ var meleeOpts = ['stab','slash','crush'];
+ var activeIdx = meleeOpts.indexOf(melee);
+ if (activeIdx < 0) activeIdx = 2;
+
+ var h = '<div class="obj-inline-group ced-atktype" id="' + widgetID + '">';
+ h += '<span class="obj-inline-label">Atk Type</span>';
+ h += '<div class="seg-pill seg-pill-3 seg-idx-' + activeIdx + ' ced-atktype-pill" style="margin-top:4px">';
+ meleeOpts.forEach(function(t, i) {
+ h += '<button type="button" class="seg-opt' + (i === activeIdx ? ' seg-active' : '') + '" data-v="' + t + '" onclick="' + selectFnName + '(\'' + t + '\',this)">' + t + '</button>';
+ });
+ h += '</div>';
+ h += '<div class="obj-card-grid" style="margin-top:4px">';
+ h += '<label class="obj-field obj-check obj-narrow"><input type="checkbox" class="ced-atktype-ranged"' + (hasRanged ? ' checked' : '') + '> <span>ranged</span></label>';
+ h += '<label class="obj-field obj-check obj-narrow"><input type="checkbox" class="ced-atktype-science"' + (hasScience ? ' checked' : '') + '> <span>science</span></label>';
+ h += '</div>';
+ h += '</div>';
+ return h;
+}
+
+function ced_atkPillSelect(val, btn) {
+ var pill = btn.closest('.ced-atktype-pill');
+ if (!pill) return;
+ var opts = pill.querySelectorAll('.seg-opt');
+ var idx = -1;
+ opts.forEach(function(o, i) {
+ if (o.getAttribute('data-v') === val) {
+ o.classList.add('seg-active');
+ idx = i;
+ } else {
+ o.classList.remove('seg-active');
+ }
+ });
+ pill.className = pill.className.replace(/seg-idx-\d/g, 'seg-idx-' + idx);
+}
+
+function ced_collectAtkType(widgetID) {
+ var widget = document.getElementById(widgetID);
+ if (!widget) return ['crush'];
+ var active = widget.querySelector('.ced-atktype-pill .seg-opt.seg-active');
+ var melee = active ? active.getAttribute('data-v') : 'crush';
+ var out = [melee];
+ var rng = widget.querySelector('.ced-atktype-ranged');
+ var sci = widget.querySelector('.ced-atktype-science');
+ if (rng && rng.checked) out.push('ranged');
+ if (sci && sci.checked) out.push('science');
+ return out;
+}