From 93a412aed2b11406399504c81d6d19ed1341908a Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 13 Jul 2026 15:07:28 -0400 Subject: feat(admin): hide irrelevant combat stats for task mobs, show relevant combat stats for hazards --- internal/admin/static/hazardeditor.js | 98 ++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 18 deletions(-) (limited to 'internal/admin/static/hazardeditor.js') diff --git a/internal/admin/static/hazardeditor.js b/internal/admin/static/hazardeditor.js index e849512..89586ac 100644 --- a/internal/admin/static/hazardeditor.js +++ b/internal/admin/static/hazardeditor.js @@ -14,17 +14,26 @@ var HAZARD_SECTIONS = [ ['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', 'search', 'e.g. gas_mask', '', null, 'items'], - ['speed', 'Speed', 'number', '10', 'narrow'], ] }, { - id: 'combat', label: 'Combat', - detect: function(d) { return d.attack_type || d.attack || d.attack_bonus || d.max_hit; }, + id: 'combat', label: 'Combat', path: 'combat', + detect: function(d) { return d.combat; }, fields: [ - ['attack_type', 'Attack Type', 'select', 'stab|slash|crush|ranged|science'], - ['attack', 'Attack', 'number', '5', 'narrow'], - ['attack_bonus', 'Attack Bonus', 'number', '0', 'narrow'], - ['max_hit', 'Max Hit', 'number', '3', 'narrow'], + ['stats.attack', 'Attack', 'number', '5', 'narrow'], + ['stats.strength', 'Strength', 'number', '5', 'narrow'], + ['stats.ranged', 'Ranged', 'number', '1', 'narrow'], + ['stats.science', 'Science', 'number', '1', 'narrow'], + ['stats.speed', 'Speed', 'number', '5', 'narrow'], + ['stats.max_melee_hit', 'Max Melee Hit', 'number', '2', 'narrow'], + ['stats.max_ranged_hit', 'Max Ranged Hit', 'number', '0', 'narrow'], + ['stats.max_science_hit', 'Max Science Hit', 'number', '0', 'narrow'], + ['stats.bonuses.attack_bonus', 'Atk Bonus', 'number', '0', 'narrow'], + ['stats.bonuses.strength_bonus', 'Str Bonus', 'number', '0', 'narrow'], + ['stats.bonuses.ranged_bonus', 'Rng Bonus', 'number', '0', 'narrow'], + ['stats.bonuses.ranged_strength_bonus', 'Rng Str Bonus', 'number', '0', 'narrow'], + ['stats.bonuses.science_bonus', 'Sci Bonus', 'number', '0', 'narrow'], + ['stats.bonuses.science_percent_bonus', 'Sci % Bonus', 'number', '0', 'narrow'], ] } ]; @@ -129,11 +138,15 @@ function renderCard(sec, data) { h += ''; if (!collapsed) { h += '
'; - h += '
'; - sec.fields.forEach(function(f) { - h += renderField(sec, f, data, -1); - }); - h += '
'; + if (sec.id === 'combat') { + h += renderHazardCombatCard(data); + } else { + h += '
'; + sec.fields.forEach(function(f) { + h += renderField(sec, f, data, -1); + }); + h += '
'; + } h += '
'; } h += ''; @@ -158,7 +171,9 @@ function removeSection(id) { var sec = HAZARD_SECTIONS.find(function(s) { return s.id === id; }); if (!sec) return; ced_syncDOMToData(hazardData); - if (sec.fields) sec.fields.forEach(function(f) { delete hazardData[f[0]]; }); + if (sec.path) { + delete hazardData[sec.path]; + } delete addedSections[id]; renderHazardEditor(hazardID, hazardData); } @@ -171,10 +186,15 @@ function addSection() { if (!sec) return; if (id === 'combat') { - hazardData.attack_type = ''; - hazardData.attack = 0; - hazardData.attack_bonus = 0; - hazardData.max_hit = 0; + hazardData.combat = { + attack_types: ['crush'], + stats: { + attack: 1, strength: 0, ranged: 0, science: 0, + speed: 5, + max_melee_hit: 0, max_ranged_hit: 0, max_science_hit: 0, + bonuses: {attack_bonus:0, strength_bonus:0, ranged_bonus:0, ranged_strength_bonus:0, science_bonus:0, science_percent_bonus:0} + } + }; } addedSections[id] = true; expandedCards[id] = true; @@ -200,9 +220,16 @@ function saveHazard() { }); } + if (sec.id === 'combat' && document.getElementById('hz_atktype')) { + sectionObj['attack_types'] = ced_collectAtkType('hz_atktype'); + hasValues = true; + } + if (sec.always) { Object.keys(sectionObj).forEach(function(k) { out[k] = sectionObj[k]; }); - } else if (hasValues) { + } else if (hasValues && sec.path) { + out[sec.path] = ced_unflattenObj(sectionObj); + } else if (hasValues && !sec.path) { Object.keys(sectionObj).forEach(function(k) { out[k] = sectionObj[k]; }); } }); @@ -271,3 +298,38 @@ function duplicateHazard() { loadHazardEditor(newID); }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); } + +function renderHazardCombatCard(data) { + var sec = HAZARD_SECTIONS.find(function(s) { return s.id === 'combat'; }); + if (!sec) return ''; + var byKey = {}; + sec.fields.forEach(function(f) { byKey[f[0]] = f; }); + + var h = ced_renderAtkTypeWidget(data, 'hz_atktype', 'ced_atkPillSelect'); + + h += '
'; + h += 'Stats'; + h += '
'; + var statKeys = ['stats.attack','stats.strength','stats.ranged','stats.science']; + statKeys.forEach(function(k) { h += renderField(sec, byKey[k], data, -1); }); + h += '
'; + h += '
'; + h += renderField(sec, byKey['stats.speed'], data, -1); + h += '
'; + h += '
'; + var maxKeys = ['stats.max_melee_hit','stats.max_ranged_hit','stats.max_science_hit']; + maxKeys.forEach(function(k) { h += renderField(sec, byKey[k], data, -1); }); + h += '
'; + h += '
'; + + h += '
'; + h += 'Bonuses'; + h += '
'; + var bonusKeys = ['stats.bonuses.attack_bonus','stats.bonuses.strength_bonus','stats.bonuses.ranged_bonus', + 'stats.bonuses.ranged_strength_bonus','stats.bonuses.science_bonus','stats.bonuses.science_percent_bonus']; + bonusKeys.forEach(function(k) { h += renderField(sec, byKey[k], data, -1); }); + h += '
'; + h += '
'; + + return h; +} -- cgit v1.2.3