Data (cards, enchant points, skill pools, sets, pets, genus insight, daevanion boards, pantheon decorations, closet skins, stat names and units) is read from the build planner's JS chunks and recognised by content; one admin import "Planer-Daten übernehmen" (also brings the specializations) plus "Bilder laden". Plans are stored per set and page (gear_set_plans, schema v40), saved instantly, shown in the compare view, copied with the set and transferable from another own set. The skills page shows the skill bonuses from Daevanion and Arcana. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
432 lines
22 KiB
JavaScript
432 lines
22 KiB
JavaScript
/**
|
|
* Gear-Planer: die Seiten Arcana, Pets, Daevanion, Pantheon und Closet eines Sets (includes/gear_planner_view.php).
|
|
* Jede Aenderung speichert sofort (gear_action.php, save_plan); der Server prueft den Plan und schickt ihn samt
|
|
* neu berechneter Kaesten (data-plan-fragment) zurueck. Dazu Filter und Suche in den Listen, die Regeln der
|
|
* Daevanion-Bretter (vom Start aus angrenzend, Kristalle) und die Plaetze im Pantheon.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
if (!window.fetch || !window.FormData) return;
|
|
|
|
var statusEl = document.querySelector('[data-plan-status]');
|
|
var setStatus = function (text, kind) {
|
|
if (!statusEl) return;
|
|
statusEl.textContent = text;
|
|
statusEl.className = 'gear-save-status' + (kind ? ' is-' + kind : '');
|
|
};
|
|
|
|
// Hinweis vom Speichern vor dem Neuladen (z.B. "Dekoration nur fuer die andere Seite") nach dem Laden zeigen
|
|
var noteKey = 'gear-plan-note';
|
|
try {
|
|
var note = window.sessionStorage.getItem(noteKey);
|
|
if (note) {
|
|
window.sessionStorage.removeItem(noteKey);
|
|
setStatus(note, 'error');
|
|
}
|
|
} catch (e) { /* ohne Speicher kein Hinweis */ }
|
|
|
|
var applyFragments = function (fragments) {
|
|
Object.keys(fragments || {}).forEach(function (key) {
|
|
document.querySelectorAll('[data-plan-fragment="' + key + '"]').forEach(function (el) { el.innerHTML = fragments[key]; });
|
|
});
|
|
};
|
|
|
|
// ---- Speichern: ein Formular, eine Anfrage nach der anderen ----
|
|
var setupForm = function (form, onState) {
|
|
var saving = false;
|
|
var again = null;
|
|
var timer = null;
|
|
form.querySelectorAll('[data-autosave-fallback]').forEach(function (button) { button.hidden = true; });
|
|
|
|
var save = function (extra, reload) {
|
|
clearTimeout(timer);
|
|
if (saving) {
|
|
again = { extra: extra, reload: reload };
|
|
return;
|
|
}
|
|
saving = true;
|
|
setStatus('Speichert …', 'busy');
|
|
var body = new FormData(form);
|
|
if (extra) body.append(extra.name, extra.value);
|
|
fetch(form.getAttribute('action'), {
|
|
method: 'POST',
|
|
body: body,
|
|
credentials: 'same-origin',
|
|
headers: { 'X-Requested-With': 'fetch', 'Accept': 'application/json' }
|
|
})
|
|
.then(function (response) { return response.json(); })
|
|
.then(function (result) {
|
|
if (!result.ok) throw new Error(result.error || 'Speichern fehlgeschlagen');
|
|
if (reload) {
|
|
if (result.errors && result.errors.length) {
|
|
try { window.sessionStorage.setItem(noteKey, result.errors.join(' ')); } catch (e) { /* dann eben ohne */ }
|
|
}
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
applyFragments(result.fragments);
|
|
var tabCount = document.querySelector('.gear-tab.is-active .gear-tab-count');
|
|
if (tabCount) tabCount.textContent = result.count || '';
|
|
if (onState && !again) onState(result.state || {});
|
|
if (result.errors && result.errors.length) setStatus(result.errors.join(' '), 'error');
|
|
else setStatus('✓ Gespeichert', 'ok');
|
|
})
|
|
.catch(function (error) { setStatus(error.message || 'Speichern fehlgeschlagen', 'error'); })
|
|
.then(function () {
|
|
saving = false;
|
|
if (again) {
|
|
var next = again;
|
|
again = null;
|
|
save(next.extra, next.reload);
|
|
}
|
|
});
|
|
};
|
|
var schedule = function (delay) {
|
|
clearTimeout(timer);
|
|
setStatus('Ungespeicherte Änderung …', 'busy');
|
|
timer = setTimeout(function () { save(null, false); }, delay);
|
|
};
|
|
|
|
form.addEventListener('change', function (event) {
|
|
if (event.target.closest('[data-plan-tools]')) return; // Suche und Filter speichern nichts
|
|
if (event.target.hasAttribute('data-plan-reload')) {
|
|
save(null, true);
|
|
return;
|
|
}
|
|
schedule(250);
|
|
});
|
|
form.addEventListener('input', function (event) {
|
|
if (event.target.matches('input[type="number"]')) schedule(700);
|
|
});
|
|
// Knoepfe mit Namen (z.B. "Alle aktivieren") schicken ihren Wert mit
|
|
form.addEventListener('click', function (event) {
|
|
var button = event.target.closest('button[type="submit"][name]');
|
|
if (!button || !form.contains(button)) return;
|
|
event.preventDefault();
|
|
save({ name: button.name, value: button.value }, false);
|
|
});
|
|
form.addEventListener('submit', function (event) {
|
|
event.preventDefault();
|
|
save(null, false);
|
|
});
|
|
return { save: save, schedule: schedule };
|
|
};
|
|
|
|
// ---- Filter und Suche in den Listen (Pets, Dekorationen, Skins) ----
|
|
var setupFilters = function (scope, extraTest) {
|
|
var items = Array.prototype.slice.call(scope.querySelectorAll('[data-filter-item]'));
|
|
if (!items.length) return null;
|
|
var buttons = scope.querySelectorAll('[data-plan-filter] button[data-filter-value]');
|
|
var tools = scope.querySelector('[data-plan-tools]');
|
|
var search = scope.querySelector('[data-filter-search]');
|
|
var domain = scope.querySelector('[data-filter-domain]');
|
|
var placed = scope.querySelector('[data-filter-placed]');
|
|
var key = '';
|
|
if (tools) tools.hidden = false;
|
|
var apply = function () {
|
|
var text = search ? search.value.trim().toLowerCase() : '';
|
|
var wantDomain = domain ? domain.value : '';
|
|
items.forEach(function (item) {
|
|
var show = (!key || item.dataset.filterKey === key)
|
|
&& (!text || (item.dataset.filterText || '').indexOf(text) !== -1)
|
|
&& (!wantDomain || (' ' + (item.dataset.domains || '') + ' ').indexOf(' ' + wantDomain + ' ') !== -1)
|
|
&& (!placed || !placed.checked || item.classList.contains('is-on'))
|
|
&& (!extraTest || extraTest(item));
|
|
item.hidden = !show;
|
|
});
|
|
};
|
|
buttons.forEach(function (button) {
|
|
button.addEventListener('click', function () {
|
|
key = button.dataset.filterValue;
|
|
buttons.forEach(function (other) { other.classList.toggle('is-active', other === button); });
|
|
apply();
|
|
});
|
|
});
|
|
[search, domain, placed].forEach(function (control) {
|
|
if (control) control.addEventListener(control === search ? 'input' : 'change', apply);
|
|
});
|
|
return { apply: apply, visible: function () { return items.filter(function (item) { return !item.hidden; }); } };
|
|
};
|
|
|
|
// ---- Arcana: Skills je Karte nur einmal, Stufen zusammen hoechstens Plaetze + Aufwertung ----
|
|
var arcanaForm = document.querySelector('.gear-arcana-form[data-plan-form]');
|
|
if (arcanaForm) {
|
|
var paintArcana = function (box) {
|
|
var slot = box.closest('[data-arcana-slot]');
|
|
var enchant = slot.querySelector('[data-arcana-enchant]');
|
|
var budget = (parseInt(box.dataset.base, 10) || 0) + (enchant ? parseInt(enchant.value, 10) || 0 : 0);
|
|
var rows = Array.prototype.slice.call(box.querySelectorAll('.gear-arcana-skill-row'));
|
|
var used = 0;
|
|
rows.forEach(function (row) {
|
|
var skill = row.querySelector('[data-arcana-skill]');
|
|
if (skill.value !== '0') used += parseInt(row.querySelector('[data-arcana-level]').value, 10) || 0;
|
|
});
|
|
rows.forEach(function (row) {
|
|
var skill = row.querySelector('[data-arcana-skill]');
|
|
var level = row.querySelector('[data-arcana-level]');
|
|
var taken = rows.filter(function (other) { return other !== row; }).map(function (other) { return other.querySelector('[data-arcana-skill]').value; });
|
|
// Die gewaehlte Option bleibt immer frei - gesperrte schickt der Browser nicht mit (sinkt die
|
|
// Aufwertung, kuerzt der Server die Stufen von hinten)
|
|
Array.prototype.forEach.call(skill.options, function (option) {
|
|
option.disabled = !option.selected && option.value !== '0' && taken.indexOf(option.value) !== -1;
|
|
});
|
|
var picked = skill.options[skill.selectedIndex];
|
|
var max = parseInt(picked && picked.dataset.max ? picked.dataset.max : '4', 10) || 4;
|
|
var mine = skill.value !== '0' ? parseInt(level.value, 10) || 0 : 0;
|
|
Array.prototype.forEach.call(level.options, function (option) {
|
|
var value = parseInt(option.value, 10);
|
|
option.disabled = !option.selected && (value > max || (skill.value !== '0' && used - mine + value > budget));
|
|
});
|
|
level.disabled = skill.value === '0';
|
|
row.classList.toggle('is-on', skill.value !== '0');
|
|
});
|
|
var count = box.querySelector('[data-arcana-used]');
|
|
if (count) count.textContent = used + '/' + budget + ' Stufen';
|
|
box.classList.toggle('is-over', used > budget);
|
|
};
|
|
var arcanaBoxes = function () { return arcanaForm.querySelectorAll('[data-arcana-skills]'); };
|
|
setupForm(arcanaForm, function (state) {
|
|
// Gepruefter Stand vom Server (z.B. zu viele Stufen gekuerzt)
|
|
arcanaForm.querySelectorAll('[data-arcana-slot]').forEach(function (slot) {
|
|
var saved = (state.slots || {})[slot.dataset.arcanaSlot];
|
|
if (!saved) return;
|
|
var enchant = slot.querySelector('[data-arcana-enchant]');
|
|
if (enchant) enchant.value = String(saved.enchant);
|
|
slot.querySelectorAll('.gear-arcana-skill-row').forEach(function (row, i) {
|
|
var entry = saved.skills[i];
|
|
row.querySelector('[data-arcana-skill]').value = entry ? String(entry[0]) : '0';
|
|
if (entry) row.querySelector('[data-arcana-level]').value = String(entry[1]);
|
|
});
|
|
});
|
|
arcanaBoxes().forEach(paintArcana);
|
|
});
|
|
arcanaForm.addEventListener('change', function (event) {
|
|
var slot = event.target.closest('[data-arcana-slot]');
|
|
var box = slot && slot.querySelector('[data-arcana-skills]');
|
|
if (box) paintArcana(box);
|
|
}, true);
|
|
arcanaBoxes().forEach(paintArcana);
|
|
}
|
|
|
|
// ---- Pets ----
|
|
var petsForm = document.querySelector('.gear-pets-form[data-plan-form]');
|
|
if (petsForm) {
|
|
var petsSaver = setupForm(petsForm);
|
|
var petFilters = setupFilters(petsForm);
|
|
var petLevel = function (item) {
|
|
var input = item.querySelector('[data-pet-level]');
|
|
if (!input) return 0;
|
|
return input.type === 'checkbox' ? (input.checked ? 1 : 0) : parseInt(input.value, 10) || 0;
|
|
};
|
|
var paintPets = function () {
|
|
var owned = {};
|
|
var total = 0;
|
|
petsForm.querySelectorAll('.gear-pet').forEach(function (item) {
|
|
var on = petLevel(item) > 0;
|
|
item.classList.toggle('is-on', on);
|
|
if (on) {
|
|
total++;
|
|
owned[item.dataset.filterKey] = (owned[item.dataset.filterKey] || 0) + 1;
|
|
}
|
|
});
|
|
petsForm.querySelectorAll('[data-filter-count]').forEach(function (count) {
|
|
var family = count.dataset.filterCount;
|
|
var all = count.textContent.split('/')[1];
|
|
count.textContent = (family ? owned[family] || 0 : total) + '/' + all;
|
|
});
|
|
};
|
|
petsForm.addEventListener('change', function (event) {
|
|
if (event.target.matches('[data-pet-level]')) paintPets();
|
|
});
|
|
petsForm.querySelectorAll('[data-pets-bulk]').forEach(function (button) {
|
|
button.addEventListener('click', function () {
|
|
var max = button.dataset.petsBulk === 'max';
|
|
(petFilters ? petFilters.visible() : []).forEach(function (item) {
|
|
var input = item.querySelector('[data-pet-level]');
|
|
if (!input) return;
|
|
if (input.type === 'checkbox') input.checked = max;
|
|
else input.value = max ? input.options[input.options.length - 1].value : '0';
|
|
});
|
|
paintPets();
|
|
petsSaver.save(null, false);
|
|
});
|
|
});
|
|
}
|
|
|
|
// ---- Pantheon: je Art nur so viele Dekorationen wie Plaetze ----
|
|
var pantheonForm = document.querySelector('.gear-pantheon-form[data-plan-form]');
|
|
if (pantheonForm) {
|
|
var slots = JSON.parse(pantheonForm.dataset.slots || '{}');
|
|
var decos = Array.prototype.slice.call(pantheonForm.querySelectorAll('.gear-deco'));
|
|
var paintPantheon = function () {
|
|
var used = {};
|
|
decos.forEach(function (deco) {
|
|
var box = deco.querySelector('input[type="checkbox"]');
|
|
deco.classList.toggle('is-on', box.checked);
|
|
if (box.checked) used[deco.dataset.decoUi] = (used[deco.dataset.decoUi] || 0) + 1;
|
|
});
|
|
decos.forEach(function (deco) {
|
|
var box = deco.querySelector('input[type="checkbox"]');
|
|
var full = !box.checked && (used[deco.dataset.decoUi] || 0) >= (slots[deco.dataset.decoUi] || 0);
|
|
box.disabled = full;
|
|
deco.classList.toggle('is-full', full);
|
|
deco.title = full ? 'Alle Plätze dieser Art sind belegt' : '';
|
|
});
|
|
pantheonForm.querySelectorAll('[data-pantheon-count]').forEach(function (count) {
|
|
count.textContent = (used[count.dataset.pantheonCount] || 0) + '/' + (slots[count.dataset.pantheonCount] || 0);
|
|
});
|
|
};
|
|
setupForm(pantheonForm, function (state) {
|
|
var placed = (state.decos || []).map(String);
|
|
decos.forEach(function (deco) {
|
|
var box = deco.querySelector('input[type="checkbox"]');
|
|
box.checked = placed.indexOf(box.value) !== -1;
|
|
});
|
|
paintPantheon();
|
|
});
|
|
setupFilters(pantheonForm);
|
|
pantheonForm.addEventListener('change', function (event) {
|
|
if (event.target.matches('.gear-deco input')) paintPantheon();
|
|
}, true);
|
|
paintPantheon();
|
|
}
|
|
|
|
// ---- Closet: Punkte und Skins ----
|
|
document.querySelectorAll('.gear-closet-points[data-plan-form]').forEach(function (form) { setupForm(form); });
|
|
var skinsForm = document.querySelector('.gear-closet-skins[data-plan-form]');
|
|
if (skinsForm) {
|
|
var skinsSaver = setupForm(skinsForm);
|
|
var skinFilters = setupFilters(skinsForm);
|
|
var paintSkins = function () {
|
|
skinsForm.querySelectorAll('.gear-skin').forEach(function (skin) {
|
|
skin.classList.toggle('is-on', skin.querySelector('input').checked);
|
|
});
|
|
};
|
|
skinsForm.addEventListener('change', paintSkins, true);
|
|
skinsForm.querySelectorAll('[data-closet-bulk]').forEach(function (button) {
|
|
button.addEventListener('click', function () {
|
|
var on = button.dataset.closetBulk === '1';
|
|
(skinFilters ? skinFilters.visible() : []).forEach(function (skin) { skin.querySelector('input').checked = on; });
|
|
paintSkins();
|
|
skinsSaver.save(null, false);
|
|
});
|
|
});
|
|
}
|
|
|
|
// ---- Daevanion: Bretter als Reiter, Felder vom Start aus angrenzend freischalten ----
|
|
var dvRoot = document.querySelector('[data-daevanion], [data-daevanion-view]');
|
|
if (dvRoot) {
|
|
var boards = Array.prototype.slice.call(dvRoot.querySelectorAll('[data-dv-board]'));
|
|
var tabs = dvRoot.querySelector('[data-dv-tabs]');
|
|
var storeKey = 'gear-dv-board';
|
|
var showBoard = function (id) {
|
|
var found = boards.some(function (board) { return board.dataset.dvBoard === id; });
|
|
if (!found && boards.length) id = boards[0].dataset.dvBoard;
|
|
boards.forEach(function (board) { board.hidden = board.dataset.dvBoard !== id; });
|
|
tabs.querySelectorAll('[data-dv-tab]').forEach(function (tab) {
|
|
tab.classList.toggle('is-active', tab.dataset.dvTab === id);
|
|
tab.setAttribute('aria-selected', tab.dataset.dvTab === id ? 'true' : 'false');
|
|
});
|
|
try { window.sessionStorage.setItem(storeKey, id); } catch (e) { /* ohne Speicher eben das erste Brett */ }
|
|
};
|
|
if (tabs && boards.length > 1) {
|
|
tabs.hidden = false;
|
|
tabs.querySelectorAll('[data-dv-tab]').forEach(function (tab) {
|
|
tab.addEventListener('click', function () { showBoard(tab.dataset.dvTab); });
|
|
});
|
|
var remembered = null;
|
|
try { remembered = window.sessionStorage.getItem(storeKey); } catch (e) { remembered = null; }
|
|
showBoard(remembered || boards[0].dataset.dvBoard);
|
|
}
|
|
|
|
// Felder je Brett: Position, Kosten, Nachbarn
|
|
var model = boards.map(function (board) {
|
|
var nodes = Array.prototype.slice.call(board.querySelectorAll('[data-node]')).map(function (el) {
|
|
return {
|
|
el: el,
|
|
input: el.querySelector('input'),
|
|
id: el.dataset.node,
|
|
r: parseInt(el.dataset.r, 10),
|
|
c: parseInt(el.dataset.c, 10),
|
|
cost: parseInt(el.dataset.cost, 10) || 0,
|
|
type: el.dataset.type
|
|
};
|
|
});
|
|
var at = {};
|
|
nodes.forEach(function (node) { at[node.r + ',' + node.c] = node; });
|
|
nodes.forEach(function (node) {
|
|
node.right = at[node.r + ',' + (node.c + 1)] || null;
|
|
node.down = at[(node.r + 1) + ',' + node.c] || null;
|
|
node.links = [at[(node.r - 1) + ',' + node.c], at[(node.r + 1) + ',' + node.c], at[node.r + ',' + (node.c - 1)], at[node.r + ',' + (node.c + 1)]].filter(Boolean);
|
|
});
|
|
return { el: board, point: board.dataset.point, id: board.dataset.dvBoard, nodes: nodes };
|
|
});
|
|
var isOn = function (node) { return node.input ? node.input.checked : node.el.classList.contains('is-on'); };
|
|
var budgets = JSON.parse(dvRoot.dataset.budgets || '{}');
|
|
|
|
var paintDaevanion = function () {
|
|
var spent = {};
|
|
model.forEach(function (board) {
|
|
board.nodes.forEach(function (node) {
|
|
if (isOn(node)) spent[board.point] = (spent[board.point] || 0) + node.cost;
|
|
});
|
|
});
|
|
model.forEach(function (board) {
|
|
var count = 0;
|
|
board.nodes.forEach(function (node) {
|
|
var on = isOn(node);
|
|
if (on) count++;
|
|
var open = !on && (node.type === 'start' || node.links.some(isOn))
|
|
&& (spent[board.point] || 0) + node.cost <= (budgets[board.point] || Infinity);
|
|
node.el.classList.toggle('is-on', on);
|
|
node.el.classList.toggle('is-open', open && !!node.input);
|
|
node.el.classList.toggle('link-r', on && !!node.right && isOn(node.right));
|
|
node.el.classList.toggle('link-d', on && !!node.down && isOn(node.down));
|
|
if (node.input) node.input.disabled = !on && !open;
|
|
});
|
|
var tabCount = tabs ? tabs.querySelector('[data-dv-tab="' + board.id + '"] [data-dv-tab-count]') : null;
|
|
if (tabCount) tabCount.textContent = count + '/' + board.nodes.length;
|
|
});
|
|
dvRoot.querySelectorAll('[data-dv-budget]').forEach(function (budget) {
|
|
var value = budget.querySelector('[data-dv-spent]');
|
|
if (value) value.textContent = spent[budget.dataset.dvBudget] || 0;
|
|
});
|
|
};
|
|
|
|
// Nach dem Entfernen: alles, was vom Start aus nicht mehr ueber gewaehlte Felder erreichbar ist, faellt weg
|
|
var prune = function (board) {
|
|
var reached = {};
|
|
var queue = board.nodes.filter(function (node) { return node.type === 'start' && isOn(node); });
|
|
while (queue.length) {
|
|
var node = queue.shift();
|
|
if (reached[node.id]) continue;
|
|
reached[node.id] = true;
|
|
node.links.forEach(function (next) {
|
|
if (isOn(next) && !reached[next.id]) queue.push(next);
|
|
});
|
|
}
|
|
board.nodes.forEach(function (node) {
|
|
if (node.input && node.input.checked && !reached[node.id]) node.input.checked = false;
|
|
});
|
|
};
|
|
|
|
if (dvRoot.hasAttribute('data-daevanion')) {
|
|
setupForm(dvRoot, function (state) {
|
|
var chosen = (state.nodes || []).map(String);
|
|
model.forEach(function (board) {
|
|
board.nodes.forEach(function (node) { if (node.input) node.input.checked = chosen.indexOf(node.id) !== -1; });
|
|
});
|
|
paintDaevanion();
|
|
});
|
|
dvRoot.addEventListener('change', function (event) {
|
|
var el = event.target.closest('[data-node]');
|
|
if (!el) return;
|
|
var board = model.filter(function (b) { return b.el.contains(el); })[0];
|
|
if (board && !event.target.checked) prune(board);
|
|
paintDaevanion();
|
|
}, true);
|
|
}
|
|
paintDaevanion();
|
|
}
|
|
})();
|