view update

This commit is contained in:
2026-11-17 14:17:50 +01:00
parent 3e565cf8c7
commit e0496fa089
45 changed files with 2024 additions and 149 deletions

View File

@@ -25,7 +25,7 @@
RC.Shop = function (opt) {
const t = opt.t;
let slot = 'weapon', sel = undefined, tipN = 0, topTab = 'build';
let slot = 'weapon', sel = undefined, tipN = 0, topTab = 'build', designerOpen = false;
function chipsFor(p) {
const s = [];
@@ -68,7 +68,8 @@
$('tabs').querySelectorAll('.tab').forEach(el => { el.onclick = () => { slot = el.dataset.slot; sel = b[slot] || null; opt.sfx.click(); render(); }; });
// part cards
const items = (RC.REQUIRED[slot] ? [] : [null]).concat(RC.partsFor(slot).map(p => p.id));
const locked = opt.locked || (() => false); // event/unlock: hide parts not released yet
const items = (RC.REQUIRED[slot] ? [] : [null]).concat(RC.partsFor(slot).filter(p => !locked(p.id)).map(p => p.id));
$('cards').innerHTML = items.map(id => {
const p = id && RC.PARTS[id], eq = b[slot] === id, own = !id || save.owned.includes(id);
const badge = eq ? `<span class="badge">${t('equipped')}</span>` : own && id ? `<span class="badge own">${t('owned')}</span>` : '';
@@ -126,11 +127,40 @@
const name = $('rname');
if (document.activeElement !== name) name.value = save.robotName;
if (!$('mechTip').textContent) tip();
renderTopTabs(); renderFitted();
renderTopTabs(); renderFitted(); renderDesigner();
// live preview: show the selected part on the 3D robot (even parts you can't afford yet)
if (opt.onPreview) opt.onPreview(topTab === 'build' && sel !== b[slot] ? Object.assign({}, b, { [slot]: sel }) : b);
}
// proportions designer (height / width / length) - only on the chassis slot
function renderDesigner() {
const el = $('designer');
if (!el) return;
if (slot !== 'chassis') { el.classList.add('hide'); return; }
el.classList.remove('hide');
el.classList.toggle('open', designerOpen);
el.classList.toggle('shut', !designerOpen);
const save = opt.getSave(), b = save.build;
if (!b.body) b.body = { hx: 1, wx: 1, lx: 1 };
const row = (key, label, lo, hi) => `<div class="drow"><span>${t('des_' + label)}</span>`
+ `<input type="range" data-k="${key}" min="${lo}" max="${hi}" step="0.05" value="${b.body[key] || 1}">`
+ `<span class="dv" id="dv_${key}">${Math.round((b.body[key] || 1) * 100)}%</span></div>`;
// collapsed by default: only the header; click the title to expand the three sliders
el.innerHTML = `<div class="dh"><span class="dtitle" id="dToggle"><span class="caret">${designerOpen ? '▾' : '▸'}</span>${t('s_body')}</span>${designerOpen ? `<button id="dReset">${t('des_reset')}</button>` : ''}</div>`
+ (designerOpen ? row('hx', 'height', 0.7, 1.6) + row('wx', 'width', 0.8, 1.4) + row('lx', 'length', 0.8, 1.3) : '');
$('dToggle').onclick = () => { designerOpen = !designerOpen; opt.sfx.click(); renderDesigner(); };
if (!designerOpen) return;
el.querySelectorAll('input[type=range]').forEach(inp => {
inp.oninput = () => {
b.body[inp.dataset.k] = +inp.value;
$('dv_' + inp.dataset.k).textContent = Math.round(inp.value * 100) + '%';
opt.onSave(); opt.onPreview(b); // live 3D while dragging
};
inp.onchange = () => render(); // on release: refresh weight bar + stats
});
$('dReset').onclick = () => { b.body = { hx: 1, wx: 1, lx: 1 }; opt.sfx.click(); opt.onSave(); opt.onPreview(b); render(); };
}
// top mode tabs: Parts / Paint / Hangar
function renderTopTabs() {
const tabs = [['build', '🔧 ' + t('tab_build')], ['paint', '🎨 ' + t('tab_paint')], ['hangar', '🚗 ' + t('tab_hangar')]];