Fixed RPG

This commit is contained in:
2026-06-01 07:44:38 +03:00
parent 600ad78f05
commit d4cd8f02f4
30 changed files with 1516 additions and 816 deletions
+36 -5
View File
@@ -30,7 +30,9 @@ export function initWizard(modalEl, { totalSteps, onStepChange, validateStep })
const dots = modalEl.querySelectorAll('.wizard-step-dot');
const prevBtn = modalEl.querySelector('[id$="Prev"]');
const nextBtn = modalEl.querySelector('[id$="Next"]');
const saveBtn = modalEl.querySelector('[id$="Save"], [id$="Confirm"], [id$="Create"]');
const saveBtn = modalEl.querySelector(
'[id$="Save"], [id$="Confirm"], [id$="Create"], [id$="Import"]',
);
function render() {
pages.forEach(p => p.classList.toggle('active', Number(p.dataset.step) === step));
@@ -45,14 +47,17 @@ export function initWizard(modalEl, { totalSteps, onStepChange, validateStep })
onStepChange?.(step);
}
function goTo(next) {
if (next > step && validateStep && !validateStep(step)) return;
async function goTo(next) {
if (next > step && validateStep) {
const ok = await Promise.resolve(validateStep(step));
if (!ok) return;
}
step = Math.max(1, Math.min(totalSteps, next));
render();
}
prevBtn?.addEventListener('click', () => goTo(step - 1));
nextBtn?.addEventListener('click', () => goTo(step + 1));
prevBtn?.addEventListener('click', () => { goTo(step - 1); });
nextBtn?.addEventListener('click', () => { goTo(step + 1); });
render();
@@ -96,6 +101,32 @@ export function getRpgSettingsFromDom(prefix = '') {
};
}
export function fillGreetingSelect(selectEl, firstMes, alternates = []) {
if (!selectEl) return;
selectEl.innerHTML = '';
const main = document.createElement('option');
main.value = '0';
const mainPreview = (firstMes || '').replace(/\s+/g, ' ').trim();
main.textContent = mainPreview
? `Основное: ${mainPreview.slice(0, 50)}${mainPreview.length > 50 ? '…' : ''}`
: 'Основное (first_mes)';
selectEl.appendChild(main);
alternates.forEach((text, i) => {
const opt = document.createElement('option');
opt.value = String(i + 1);
const preview = String(text).replace(/\s+/g, ' ').trim();
opt.textContent = `Альт. ${i + 1}: ${preview.slice(0, 50)}${preview.length > 50 ? '…' : ''}`;
selectEl.appendChild(opt);
});
}
export function getSelectedGreeting(selectEl, firstMes, alternates = []) {
const v = selectEl?.value ?? '0';
if (v === '0') return firstMes || '';
const idx = parseInt(v, 10) - 1;
return alternates[idx] ?? firstMes ?? '';
}
export function formatSessionDate(iso) {
if (!iso) return '';
const d = new Date(iso.includes('T') ? iso : iso.replace(' ', 'T') + 'Z');