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', 'search', 'gas_mask', '', null, 'items'],
]
},
{
id: 'combat', label: 'Combat', path: 'combat',
detect: function(d) { return d.combat; },
fields: [
['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'],
]
}
];
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 += '