');
}
var ph = hint ? ' placeholder="' + esc(hint) + '"' : '';
return wrap('obj-field', '' + esc(label) + '');
@@ -405,17 +419,92 @@ function renderCoreCard(data) {
function renderArraySection(sec, data) {
var arr = data[cardPath(sec)] || [];
var h = '';
+ var isUseInter = sec.id === 'use_interactions';
+ if (isUseInter) {
+ window._useInterVis = window._useInterVis || {};
+ }
arr.forEach(function(item, idx) {
- h += '
';
- h += '
';
- sec.fields.forEach(function(f) {
- h += renderField(sec, f, data, idx);
- });
- h += '
';
- h += '';
- h += '
';
+ if (isUseInter) {
+ var vis = window._useInterVis[idx] || {};
+ window._useInterVis[idx] = vis;
+ var showCond = vis.condition || (item.condition && item.condition !== '');
+ var showAct = vis.action || (item.action && item.action !== '');
+ var showMsg = vis.message || (item.message && item.message !== '');
+
+ h += '
';
+
+ h += '
';
+ h += renderField(sec, sec.fields[0], data, idx, null, 'max-width:260px');
+ h += '';
+ if (!showCond) {
+ h += '';
+ }
+ if (!showAct) {
+ h += '';
+ }
+ if (!showMsg) {
+ h += '';
+ }
+ h += '';
+ h += '
';
+
+ h += '
';
+ h += renderField(sec, sec.fields[1], data, idx, null, 'flex:1;min-width:0');
+ h += '';
+ h += '
';
+
+ h += '
';
+ h += renderField(sec, sec.fields[2], data, idx, null, 'flex:1;min-width:0');
+ h += '';
+ h += '
';
+
+ h += '
';
+ h += renderField(sec, sec.fields[3], data, idx, null, 'flex:1;min-width:0');
+ h += '';
+ h += '
';
+
+ h += '
';
+ } else {
+ h += '
';
+ h += '
';
+ sec.fields.forEach(function(f) {
+ h += renderField(sec, f, data, idx);
+ });
+ h += '
';
+ h += '';
+ h += '
';
+ }
});
h += '';
+ if (isUseInter) {
+ var helpCollapsed = window._useInterHelpCollapsed === undefined ? true : window._useInterHelpCollapsed;
+ h += '
';
+ h += '
';
+ h += '' + (helpCollapsed ? '▶' : '▼') + '';
+ h += 'How Conditions & Actions Work';
+ h += '
';
+ if (!helpCollapsed) {
+ h += '
';
+ h += 'Entries checked top-to-bottom, first match wins.
Item ID: required for use <item> on <object>; omit for plain use <object>. ';
+ h += 'Condition: JSON. When this interaction is available: ';
+ h += ' {"flag":"gate_open","not":true} — world flag is NOT set ';
+ h += ' {"player_flag":"has_key","value":1} — player flag matches value ';
+ h += ' {"has_item":"silver_bar"} — player carries item ';
+ h += ' {"all_of":[{"flag":"a"},{"has_item":"b"}]} — ALL sub-conditions ';
+ h += ' {"any_of":[...]} — ANY sub-condition ';
+ h += ' Omit for an unconditional interaction. ';
+ h += 'Action: JSON. What happens when the interaction fires: ';
+ h += ' {"set_flags":{"gate_open":true}} — set world flags ';
+ h += ' {"set_player_flags":{"spoke":true}} — set player flags ';
+ h += ' {"give_item":"keycard","teleport":5} — give item + teleport ';
+ h += ' {"take_item":"bomb","heal":10} — take item + heal ';
+ h += ' {"credits":-50} — deduct credits ';
+ h += ' {"reputation_cost":1,"aps_node":true} — rep cost + mark APS ';
+ h += 'Message: Sent to the player when the interaction fires (1-tick action).';
+ h += '
';
+ }
+ h += '
';
+ }
return h;
}
@@ -431,8 +520,11 @@ function renderSubtable(sec, st, data) {
var h = '
';
h += '
' + esc(st.label) + '
';
arr.forEach(function(item, idx) {
- h += '
';
+ h += '
';
if (isDrops) {
+ if (!st.single) {
+ h += '';
+ }
var isItemDrop = item._type !== undefined ? item._type !== 't' : !item.table;
var showField = isItemDrop ? 'item_id' : 'table';
var hideField = isItemDrop ? 'table' : 'item_id';
@@ -448,16 +540,14 @@ function renderSubtable(sec, st, data) {
if (f[2] === 'search') {
var entity = f[5] || 'items';
var ph = f[3] ? ' placeholder="' + escAttr(f[3]) + '"' : ' placeholder="Search ' + entity + '..."';
- h += '';
+ var dp = cardPath(sec) + '.' + st.key + '[' + idx + '].' + f[0];
+ h += '';
} else if (f[2] === 'checkbox') {
h += '';
} else {
h += '';
}
});
- if (!st.single) {
- h += '';
- }
h += '
';
h += '
';
var fidMsg = fieldIDSub(sec, st.key, idx, 'message');
@@ -476,7 +566,8 @@ function renderSubtable(sec, st, data) {
if (f[2] === 'search') {
var entity = f[5] || 'items';
var ph = f[3] ? ' placeholder="' + escAttr(f[3]) + '"' : ' placeholder="Search ' + entity + '..."';
- h += '';
+ var dp = cardPath(sec) + '.' + st.key + '[' + idx + '].' + f[0];
+ h += '';
} else if (f[2] === 'checkbox') {
h += '';
} else {
@@ -530,21 +621,52 @@ function renderToolsCheckbox(sec, il, data) {
var sectionRoot = data[cardPath(sec)] || {};
var arr = sectionRoot[il.key] || [];
var choices = toolTypes || [];
+ if (choices.length === 0) {
+ return 'Loading tool types...';
+ }
+ if (arr.length === 0) {
+ return '';
+ }
var h = '
';
h += '' + esc(il.label) + '';
- h += '
';
- choices.forEach(function(t) {
- var checked = arr.indexOf(t) >= 0 ? ' checked' : '';
- h += '';
+ h += '
';
+ arr.forEach(function(t, idx) {
+ h += '
';
+ h += '';
+ h += '';
+ h += '
';
});
h += '
';
- if (choices.length === 0) {
- h += 'Loading tool types...';
- }
+ h += '';
h += '
';
return h;
}
+function addToolRow(secID, key) {
+ var sec = SECTIONS.find(function(s) { return s.id === secID; });
+ if (!sec) return;
+ var p = cardPath(sec);
+ if (!objectData[p]) objectData[p] = {};
+ objectData[p][key] = (objectData[p][key] || []).concat(['']);
+ renderCurrent();
+}
+
+function removeToolRow(secID, key, idx) {
+ var sec = SECTIONS.find(function(s) { return s.id === secID; });
+ if (!sec) return;
+ var p = cardPath(sec);
+ var arr = objectData[p] && objectData[p][key];
+ if (!arr) return;
+ arr.splice(idx, 1);
+ if (arr.length === 0) delete objectData[p][key];
+ renderCurrent();
+}
+
function fetchToolTypes() {
API.get('/api/tools').then(function(tools) {
toolTypes = tools || [];
@@ -688,6 +810,32 @@ function renderCurrent() {
renderObjectEditor(objectID, objectData);
}
+function showUseInterField(idx, key) {
+ window._useInterVis = window._useInterVis || {};
+ if (!window._useInterVis[idx]) window._useInterVis[idx] = {};
+ window._useInterVis[idx][key] = true;
+ renderCurrent();
+}
+
+function hideUseInterField(idx, key) {
+ window._useInterVis = window._useInterVis || {};
+ if (!window._useInterVis[idx]) window._useInterVis[idx] = {};
+ window._useInterVis[idx][key] = false;
+ if (objectData.use_interactions && objectData.use_interactions[idx]) {
+ objectData.use_interactions[idx][key] = '';
+ }
+ renderCurrent();
+}
+
+function toggleUseInterHelp() {
+ if (window._useInterHelpCollapsed === undefined) {
+ window._useInterHelpCollapsed = false;
+ } else {
+ window._useInterHelpCollapsed = !window._useInterHelpCollapsed;
+ }
+ renderCurrent();
+}
+
function toggleGatherConditionals() {
var skillEl = document.getElementById('f_gather_skill');
var skill = skillEl ? skillEl.value : '';
@@ -780,9 +928,9 @@ function saveObject() {
hasValues = true;
}
} else if (il.type === 'tools_checkbox') {
- var chks = document.querySelectorAll('.obj-tool-chk:checked');
+ var selects = document.querySelectorAll('.obj-tool-select');
var tools = [];
- chks.forEach(function(c) { tools.push(c.getAttribute('data-tool')); });
+ selects.forEach(function(s) { if (s.value) tools.push(s.value); });
if (tools.length > 0) { sectionObj[il.key] = tools; hasValues = true; }
} else if (il.type === 'kv') {
var kvEl = document.querySelector('.obj-kv-list[data-sec="' + sec.id + '"][data-key="' + il.key + '"]');
--
cgit v1.2.3