aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/admin/static/itemeditor.js67
1 files changed, 58 insertions, 9 deletions
diff --git a/internal/admin/static/itemeditor.js b/internal/admin/static/itemeditor.js
index 6375c16..c28f273 100644
--- a/internal/admin/static/itemeditor.js
+++ b/internal/admin/static/itemeditor.js
@@ -218,6 +218,7 @@ function renderItemEditor(id, data) {
$('#editorMain').innerHTML = html;
setupSearchFields();
setupCraftTypeChange();
+ setupEquipTypeChange();
updateOutputQtyVisibility();
setTimeout(function() {
document.querySelectorAll('.color-field').forEach(function(el) { bindColorField(el); });
@@ -442,14 +443,18 @@ function renderEquipmentCard(data) {
var eq = data.equipment || {};
var h = '';
var isAmmo = eq.type === 'ammo';
+ var isWeapon = ['melee_weapon', 'ranged_weapon', 'tech_weapon'].indexOf(eq.type) >= 0;
+ var isMelee = eq.type === 'melee_weapon';
// Row 1: type, slot
h += '<div class="obj-core-row">';
h += renderEquipField('type', 'Type', 'select', 'melee_weapon|ranged_weapon|tech_weapon|armor|tool|ammo', eq.type);
- if (!isAmmo) {
+ if (!isAmmo && !isWeapon) {
h += renderEquipField('slot', 'Slot', 'select', 'head|neck|torso|legs|hands|feet|back|ammo|main_hand|off_hand|ring', eq.slot);
- } else {
+ } else if (isAmmo) {
h += '<input type="hidden" id="' + equipFieldID('slot') + '" value="ammo">';
+ } else {
+ h += '<input type="hidden" id="' + equipFieldID('slot') + '" value="main_hand">';
}
h += '</div>';
@@ -459,16 +464,32 @@ function renderEquipmentCard(data) {
}
// Row 2: attack_type, speed, junk
- var isMelee = eq.type === 'melee_weapon';
- var isWeapon = ['melee_weapon', 'ranged_weapon', 'tech_weapon'].indexOf(eq.type) >= 0;
h += '<div class="obj-core-row"' + (!isMelee && !isWeapon ? ' style="display:none"' : '') + '>';
if (isMelee) {
- h += renderEquipField('attack_type', 'Attack Type', 'select', 'stab|slash|crush', eq.attack_type);
+ var atkVal = eq.attack_type || 'stab';
+ var atkOpts = ['stab', 'slash', 'crush'];
+ var atkIdx = atkOpts.indexOf(atkVal);
+ if (atkIdx < 0) atkIdx = 0;
+ h += '<div class="obj-inline-group eq-atktype">';
+ h += '<span class="obj-inline-label">Atk Type</span>';
+ h += '<div class="seg-pill seg-pill-3 seg-idx-' + atkIdx + ' eq-atktype-pill" style="margin-top:4px">';
+ atkOpts.forEach(function(t, i) {
+ h += '<button type="button" class="seg-opt' + (i === atkIdx ? ' seg-active' : '') + '" data-v="' + t + '" onclick="eq_atkPillSelect(\'' + t + '\',this)">' + t + '</button>';
+ });
+ h += '</div>';
+ h += '<input type="hidden" id="' + equipFieldID('attack_type') + '" value="' + escAttr(atkVal) + '" data-field-path="equipment.attack_type">';
+ h += '</div>';
}
if (isWeapon) {
- h += renderEquipField('speed', 'Speed', 'number', '', eq.speed, 'narrow');
+ h += renderEquipField('speed', 'Speed', 'number', '5', eq.speed, 'narrow');
}
- h += renderEquipField('junk', 'Junk', 'search', '', eq.junk, '', 'items');
+ var junkItems = ['solarjunk','hydrojunk','cosmicjunk','chaosjunk','ecojunk','biojunk','naturejunk','lawjunk','deathjunk','bloodjunk'];
+ h += '<label class="obj-field"><span>Provides Junk</span><select id="' + equipFieldID('junk') + '" data-field-path="equipment.junk">';
+ h += '<option value="">(none)</option>';
+ junkItems.forEach(function(j) {
+ h += '<option value="' + escAttr(j) + '"' + (eq.junk === j ? ' selected' : '') + '>' + esc(j) + '</option>';
+ });
+ h += '</select></label>';
h += '</div>';
// 3 buttons row
@@ -526,6 +547,25 @@ function removeEquipBlock(blockKey) {
renderItemEditor(itemID, itemData);
}
+function eq_atkPillSelect(val, btn) {
+ var pill = btn.closest('.eq-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);
+ var hidden = document.getElementById('f_equipment_attack_type');
+ if (hidden) hidden.value = val;
+ renderCurrent();
+}
+
// =========================================================================
// Generic field render (unchanged)
// =========================================================================
@@ -989,7 +1029,7 @@ function addSection() {
if (sec.path) {
if (sec.id === 'equipment') {
- itemData.equipment = {type:'', slot:'', attack_type:'', speed:0, junk:''};
+ itemData.equipment = {type:'', slot:'', attack_type:'stab', speed:0, junk:''};
} else if (sec.isArray && sec.interactionStyle) {
itemData[sec.path] = [];
} else {
@@ -1228,6 +1268,14 @@ function setupCraftTypeChange() {
});
}
+function setupEquipTypeChange() {
+ var el = document.getElementById('f_equipment_type');
+ if (!el) return;
+ var newEl = el.cloneNode(true);
+ el.parentNode.replaceChild(newEl, el);
+ newEl.addEventListener('change', renderCurrent);
+}
+
function updateOutputQtyVisibility() {
var isStackable = false;
var stackableEl = document.getElementById('f_core_stackable');
@@ -1415,12 +1463,13 @@ function saveItem() {
['type', 'slot', 'attack_type', 'junk'].forEach(function(k) {
var el = document.getElementById('f_equipment_' + k);
if (!el) return;
- var val = collectFieldValue(el, k === 'type' || k === 'slot' ? 'select' : (k === 'junk' ? 'search' : 'text'));
+ var val = collectFieldValue(el, k === 'type' || k === 'slot' ? 'select' : (k === 'junk' ? 'select' : 'text'));
if (val !== '' && val !== false && val !== 0 && val !== null) hasEq = true;
eq[k] = val;
});
if (eq.type === 'ammo') eq.slot = 'ammo';
+ if (eq.type === 'melee_weapon' || eq.type === 'ranged_weapon' || eq.type === 'tech_weapon') eq.slot = 'main_hand';
var speedEl = document.getElementById('f_equipment_speed');
if (speedEl) {