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', 'toxic gas'],
['description', 'Description', 'textarea', 'A cloud of toxic gas fills the room.', 'wide'],
['warn_message', 'Warn Message', 'text', 'The air grows thick with toxic fumes...', 'wide'],
['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', 'text', 'e.g. gas_mask'],
['speed', 'Speed', 'number', '10', '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', '5', 'narrow'],
['attack_bonus', 'Attack Bonus', 'number', '0', 'narrow'],
['max_hit', 'Max Hit', 'number', '3', '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 = renderRenameableHeader('Hazard', 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 += renderMoveBar();
html += '