A member asked for a macro planner. Aion 2's skill window (K -> Macro) has one macro per skill preset 1-3, each with up to 20 numbered entries (skill icon with level, name, trash can) and a delay in ms after each entry (10 ms minimum); held down, the macro runs top to bottom, skipping skills on cooldown, and starts over. The new tab rebuilds that window and its look: star ornament, big numbers, "Verzögerung [10] ms" on a thin line, gold "Makro hinzufügen", preset buttons 1/2/3 with a dot for the used ones. - includes/gear_macro.php: active and stigma skills of the set's class, the level planned in the set (with Daevanion/Arcana bonuses; unplanned stigmas are marked), up to GEAR_MACRO_MAX_ENTRIES = 20 entries per preset, delays 10-9999 ms. Stored in gear_set_plans under "macro" (not a GEAR_PLAN_SECTIONS page), so copying a set and the data export include it. - gear_action.php save_macro: takes the preset as it stands in the form plus one change (add, replace, remove, up, down), drops skills of other classes with a note and returns the redrawn preset. Without JavaScript the buttons submit the form. - assets/js/gear-macro.js: switch presets without reload, picker to add skills (stays open for the next one) or to replace an entry's skill right below it, delays saved shortly after typing, focus follows moved entries, "Als Text kopieren" puts the macro on the clipboard as a list for Discord. gear.js finds skill tooltips via data-tip-ref, so each description is on the page only once. - Sets shown on a profile show their macros read-only. No DPS value: damage formulas, cooldowns and animation times are not available. - README and patch notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
345 lines
16 KiB
JavaScript
345 lines
16 KiB
JavaScript
/**
|
||
* Gear-Planer, Unterseite Makro (includes/gear_macro.php): Presets 1-3 ohne Neuladen wechseln, das Makro als Text
|
||
* kopieren (z. B. fuer Discord) und - im eigenen Set - Eintraege hinzufuegen, austauschen, verschieben und loeschen.
|
||
* Jede Aenderung geht sofort an gear_action.php (save_macro), das neu gezeichnete Makro-Fenster kommt zurueck;
|
||
* Verzoegerungen werden kurz nach dem Tippen gespeichert. Ein Klick auf das Symbol eines Eintrags oeffnet die
|
||
* Skill-Auswahl direkt darunter und tauscht den Skill aus.
|
||
*/
|
||
(function () {
|
||
'use strict';
|
||
|
||
var root = document.querySelector('[data-macro]');
|
||
if (!root) return;
|
||
|
||
function visibleForm() {
|
||
return root.querySelector('[data-macro-form]:not([hidden])');
|
||
}
|
||
|
||
// ---- Presets 1-3 ----
|
||
function showPreset(no) {
|
||
root.querySelectorAll('[data-macro-form]').forEach(function (form) { form.hidden = form.dataset.preset !== no; });
|
||
root.querySelectorAll('[data-macro-preset-link]').forEach(function (link) {
|
||
var on = link.dataset.macroPresetLink === no;
|
||
link.classList.toggle('is-active', on);
|
||
if (on) link.setAttribute('aria-current', 'true');
|
||
else link.removeAttribute('aria-current');
|
||
});
|
||
var label = root.querySelector('[data-macro-preset-no]');
|
||
if (label) label.textContent = no;
|
||
try {
|
||
var url = new URL(window.location.href);
|
||
url.searchParams.set('preset', no);
|
||
window.history.replaceState(null, '', url.toString());
|
||
} catch (e) {
|
||
// aeltere Browser: die Adresse bleibt
|
||
}
|
||
}
|
||
|
||
// ---- Als Text kopieren ----
|
||
var copyButton = root.querySelector('[data-macro-copy]');
|
||
function copyText(text) {
|
||
if (navigator.clipboard && navigator.clipboard.writeText) return navigator.clipboard.writeText(text);
|
||
return new Promise(function (resolve, reject) {
|
||
var area = document.createElement('textarea');
|
||
area.value = text;
|
||
area.setAttribute('readonly', '');
|
||
area.style.position = 'fixed';
|
||
area.style.opacity = '0';
|
||
document.body.appendChild(area);
|
||
area.select();
|
||
var ok = false;
|
||
try { ok = document.execCommand('copy'); } catch (e) { ok = false; }
|
||
area.remove();
|
||
if (ok) resolve(); else reject(new Error('copy'));
|
||
});
|
||
}
|
||
if (copyButton) {
|
||
var copyLabel = copyButton.textContent;
|
||
copyButton.addEventListener('click', function () {
|
||
var form = visibleForm();
|
||
if (!form) return;
|
||
var lines = [(root.dataset.macroTitle || 'Gear-Set') + ' – Makro, Preset ' + form.dataset.preset];
|
||
form.querySelectorAll('[data-macro-entry]').forEach(function (entry, index) {
|
||
var input = entry.querySelector('[data-macro-delay]');
|
||
var shown = entry.querySelector('.gear-macro-delay strong');
|
||
var delay = input ? input.value : (shown ? shown.textContent : '');
|
||
var level = entry.dataset.macroLevel && entry.dataset.macroLevel !== '0' ? ' (Stufe ' + entry.dataset.macroLevel + ')' : '';
|
||
lines.push((index + 1) + '. ' + entry.dataset.macroName + level + ' – ' + delay + ' ms');
|
||
});
|
||
if (lines.length === 1) lines.push('(leer)');
|
||
copyText(lines.join('\n')).then(
|
||
function () { copyButton.textContent = '✓ Kopiert'; },
|
||
function () { copyButton.textContent = 'Kopieren ging nicht'; }
|
||
).then(function () {
|
||
setTimeout(function () { copyButton.textContent = copyLabel; }, 2000);
|
||
});
|
||
});
|
||
}
|
||
|
||
var editable = !!root.querySelector('[data-macro-form] input[name="action"]') && window.fetch && window.FormData;
|
||
|
||
// ---- Skill-Auswahl: unten zum Hinzufuegen, unter einem Eintrag zum Austauschen ----
|
||
var picking = null; // { details, home, next, entry, index }
|
||
|
||
function pickerTitle(details, text) {
|
||
var title = details.querySelector('[data-macro-picker-title]');
|
||
if (title) title.textContent = text;
|
||
}
|
||
|
||
function openPicker(form, index) {
|
||
var details = form.querySelector('[data-macro-picker]');
|
||
var entry = form.querySelector('[data-macro-entry="' + index + '"]');
|
||
if (!details || !entry) return;
|
||
closePicker(false);
|
||
picking = { details: details, home: details.parentNode, next: details.nextSibling, entry: entry, index: index };
|
||
entry.classList.add('is-picking');
|
||
// Zwischen Skill und Verzoegerung des Eintrags
|
||
entry.insertBefore(details, entry.querySelector('.gear-macro-delay'));
|
||
details.classList.add('is-replacing');
|
||
pickerTitle(details, 'Skill für Eintrag ' + (Number(index) + 1) + ' wählen');
|
||
details.open = true;
|
||
var skillField = entry.querySelector('input[name="skill[]"]');
|
||
var current = skillField && details.querySelector('[data-pick-skill="' + skillField.value + '"]');
|
||
(current || details.querySelector('[data-pick-skill]')).focus();
|
||
}
|
||
|
||
function closePicker(focusEntry) {
|
||
root.querySelectorAll('[data-macro-picker][open]').forEach(function (details) {
|
||
if (!picking || details !== picking.details) details.open = false;
|
||
});
|
||
if (!picking) return;
|
||
var p = picking;
|
||
picking = null;
|
||
p.entry.classList.remove('is-picking');
|
||
p.details.open = false;
|
||
p.details.classList.remove('is-replacing');
|
||
p.home.insertBefore(p.details, p.next);
|
||
pickerTitle(p.details, 'Skill für den neuen Eintrag wählen');
|
||
if (focusEntry) {
|
||
var button = p.entry.querySelector('[data-macro-pick]');
|
||
if (button) button.focus();
|
||
}
|
||
}
|
||
|
||
// ---- Speichern ----
|
||
var inflight = null; // 'op' (Aenderung, danach neu gezeichnet) oder 'delay' (nur Verzoegerungen)
|
||
var queued = null; // eine Aenderung, die kam, waehrend Verzoegerungen gespeichert wurden
|
||
var delayAgain = null; // Formular, dessen Verzoegerungen danach noch einmal gespeichert werden
|
||
var timers = {};
|
||
|
||
function setStatus(form, text, kind) {
|
||
var el = form.querySelector('[data-macro-status]');
|
||
if (!el) return;
|
||
el.textContent = text;
|
||
el.className = 'gear-save-status' + (kind ? ' is-' + kind : '');
|
||
}
|
||
|
||
function prepare(form) {
|
||
form.querySelectorAll('[data-autosave-fallback]').forEach(function (button) { button.hidden = true; });
|
||
}
|
||
|
||
/** Nach einer Aenderung dorthin, wo man weitermachen will (Tastatur): mit dem Eintrag mitwandern usw. */
|
||
function focusAfter(form, op) {
|
||
var parts = op.split(':');
|
||
var index = parseInt(parts[1], 10);
|
||
var find = function (selector) { return form.querySelector(selector); };
|
||
var target = null;
|
||
if (parts[0] === 'up') {
|
||
target = find('[name="op"][value="up:' + (index - 1) + '"]:not(:disabled)') || find('[name="op"][value="down:' + (index - 1) + '"]');
|
||
} else if (parts[0] === 'down') {
|
||
target = find('[name="op"][value="down:' + (index + 1) + '"]:not(:disabled)') || find('[name="op"][value="up:' + (index + 1) + '"]');
|
||
} else if (parts[0] === 'remove') {
|
||
target = find('[name="op"][value="remove:' + index + '"]') || find('[name="op"][value="remove:' + (index - 1) + '"]') || find('.gear-macro-add-button');
|
||
} else if (parts[0] === 'replace') {
|
||
target = find('[data-macro-pick="' + index + '"]');
|
||
} else if (parts[0] === 'add') {
|
||
target = find('[data-pick-skill="' + parts[1] + '"]') || find('.gear-macro-add-button');
|
||
}
|
||
if (target) target.focus({ preventScroll: true });
|
||
}
|
||
|
||
function render(form, html, op) {
|
||
var holder = document.createElement('div');
|
||
holder.innerHTML = html;
|
||
var fresh = holder.firstElementChild;
|
||
if (!fresh) return form;
|
||
fresh.hidden = form.hidden;
|
||
form.replaceWith(fresh);
|
||
prepare(fresh);
|
||
// Nach dem Hinzufuegen bleibt die Auswahl offen - so lassen sich mehrere Skills nacheinander eintragen
|
||
var picker = fresh.querySelector('[data-macro-picker]');
|
||
if (picker && op.indexOf('add:') === 0 && !picker.hasAttribute('data-full')) picker.open = true;
|
||
focusAfter(fresh, op);
|
||
if (window.gearTipRefresh) window.gearTipRefresh();
|
||
return fresh;
|
||
}
|
||
|
||
function send(form, op) {
|
||
if (inflight) {
|
||
// Waehrend Verzoegerungen gespeichert werden, bleiben die Nummern gleich - die Aenderung folgt danach.
|
||
// Laeuft schon eine Aenderung, zaehlt der Klick nicht: die Nummern stimmen erst nach dem Neuzeichnen.
|
||
if (op && inflight === 'delay') queued = { form: form, op: op };
|
||
else if (!op) delayAgain = form;
|
||
return;
|
||
}
|
||
if (!op && !form.checkValidity()) {
|
||
setStatus(form, 'Verzögerung: ganze Zahl von 10 bis 9999 ms – nicht gespeichert', 'error');
|
||
return;
|
||
}
|
||
inflight = op ? 'op' : 'delay';
|
||
clearTimeout(timers[form.dataset.preset]);
|
||
var body = new FormData(form);
|
||
if (op) {
|
||
body.append('op', op);
|
||
form.setAttribute('aria-busy', 'true');
|
||
}
|
||
setStatus(form, 'Speichert …', 'busy');
|
||
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');
|
||
var current = form;
|
||
if (op) {
|
||
current = render(form, result.html, op);
|
||
} else {
|
||
// Vom Server begrenzte Verzoegerungen (10-9999 ms) uebernehmen
|
||
var inputs = form.querySelectorAll('[data-macro-delay]');
|
||
(result.entries || []).forEach(function (entry, i) {
|
||
if (inputs[i] && inputs[i] !== document.activeElement && String(entry.d) !== inputs[i].value) inputs[i].value = entry.d;
|
||
});
|
||
}
|
||
var tabCount = document.querySelector('.gear-tab.is-active .gear-tab-count');
|
||
if (tabCount) tabCount.textContent = result.count || '';
|
||
var link = root.querySelector('[data-macro-preset-link="' + current.dataset.preset + '"]');
|
||
if (link) {
|
||
link.classList.toggle('has-entries', !!result.filled);
|
||
var entries = (result.entries || []).length;
|
||
link.title = 'Preset ' + current.dataset.preset + (entries ? ' – ' + entries + (entries === 1 ? ' Eintrag' : ' Einträge') : ' – leer');
|
||
}
|
||
var errors = result.errors || [];
|
||
setStatus(current, errors.length ? errors.join(' ') : '✓ Gespeichert', errors.length ? 'error' : 'ok');
|
||
})
|
||
.catch(function (error) {
|
||
form.removeAttribute('aria-busy');
|
||
setStatus(form, error.message || 'Speichern fehlgeschlagen', 'error');
|
||
})
|
||
.then(function () {
|
||
inflight = null;
|
||
if (queued) {
|
||
var next = queued;
|
||
queued = null;
|
||
send(next.form, next.op);
|
||
} else if (delayAgain) {
|
||
var again = delayAgain;
|
||
delayAgain = null;
|
||
send(again, null);
|
||
}
|
||
});
|
||
}
|
||
|
||
// ---- Klicks: Presets, Eintraege, Auswahl ----
|
||
root.addEventListener('click', function (event) {
|
||
var presetLink = event.target.closest('[data-macro-preset-link]');
|
||
if (presetLink) {
|
||
event.preventDefault();
|
||
closePicker(false);
|
||
showPreset(presetLink.dataset.macroPresetLink);
|
||
return;
|
||
}
|
||
if (!editable) return;
|
||
|
||
var pick = event.target.closest('[data-macro-pick]');
|
||
if (pick) {
|
||
event.preventDefault();
|
||
var form = pick.closest('[data-macro-form]');
|
||
if (picking && picking.entry.contains(pick)) closePicker(true);
|
||
else openPicker(form, pick.dataset.macroPick);
|
||
return;
|
||
}
|
||
|
||
var summary = event.target.closest('.gear-macro-add-button');
|
||
if (summary && summary.tagName === 'SUMMARY') {
|
||
var details = summary.parentNode;
|
||
if (picking) closePicker(false);
|
||
// Volles Makro: nichts hinzufuegen, den Hinweis zeigen
|
||
if (details.hasAttribute('data-full') && !details.open) {
|
||
event.preventDefault();
|
||
var note = details.parentNode.querySelector('[data-macro-full]');
|
||
if (note) {
|
||
note.classList.remove('is-flash');
|
||
void note.offsetWidth;
|
||
note.classList.add('is-flash');
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
var button = event.target.closest('button[name="op"]');
|
||
if (button) {
|
||
event.preventDefault();
|
||
if (button.disabled) return;
|
||
var op = button.value;
|
||
var targetForm = button.closest('[data-macro-form]');
|
||
if (picking && button.hasAttribute('data-pick-skill')) {
|
||
op = 'replace:' + picking.index + ':' + button.dataset.pickSkill;
|
||
}
|
||
// Beim Hinzufuegen bleibt die Auswahl offen, sonst geht sie zu
|
||
if (op.indexOf('add:') !== 0) closePicker(false);
|
||
send(targetForm, op);
|
||
}
|
||
});
|
||
|
||
if (!editable) return;
|
||
|
||
root.querySelectorAll('[data-macro-form]').forEach(prepare);
|
||
|
||
// Ausserhalb der Auswahl geklickt oder Escape: zu
|
||
document.addEventListener('click', function (event) {
|
||
if (picking) {
|
||
if (!picking.details.contains(event.target) && !event.target.closest('[data-macro-pick]')) closePicker(false);
|
||
return;
|
||
}
|
||
root.querySelectorAll('[data-macro-picker][open]').forEach(function (details) {
|
||
if (!details.contains(event.target)) details.open = false;
|
||
});
|
||
});
|
||
document.addEventListener('keydown', function (event) {
|
||
if (event.key !== 'Escape') return;
|
||
if (picking) {
|
||
closePicker(true);
|
||
return;
|
||
}
|
||
root.querySelectorAll('[data-macro-picker][open]').forEach(function (details) {
|
||
details.open = false;
|
||
var summary = details.querySelector('summary');
|
||
if (summary) summary.focus();
|
||
});
|
||
});
|
||
|
||
// ---- Verzoegerungen: kurz nach dem Tippen speichern, Enter sofort ----
|
||
root.addEventListener('input', function (event) {
|
||
if (!event.target.matches('[data-macro-delay]')) return;
|
||
var form = event.target.closest('[data-macro-form]');
|
||
clearTimeout(timers[form.dataset.preset]);
|
||
setStatus(form, 'Ungespeicherte Änderung …', 'busy');
|
||
timers[form.dataset.preset] = setTimeout(function () { send(form, null); }, 700);
|
||
});
|
||
root.addEventListener('change', function (event) {
|
||
if (event.target.matches('[data-macro-delay]')) send(event.target.closest('[data-macro-form]'), null);
|
||
});
|
||
root.addEventListener('keydown', function (event) {
|
||
if (event.key === 'Enter' && event.target.matches('[data-macro-delay]')) {
|
||
event.preventDefault();
|
||
send(event.target.closest('[data-macro-form]'), null);
|
||
}
|
||
});
|
||
root.addEventListener('submit', function (event) {
|
||
event.preventDefault();
|
||
send(event.target, null);
|
||
});
|
||
})();
|