hughe update
This commit is contained in:
54
game/shop.js
54
game/shop.js
@@ -10,9 +10,13 @@
|
||||
'use strict';
|
||||
const RC = root.RC, $ = Kit.$;
|
||||
RC.PAINTS = [0xd8452b, 0xff7a1a, 0xf2c230, 0x5fae3b, 0x2e9c8f, 0x2a6fd8, 0x6a3fb0, 0xd94f9a, 0xe6e6e6, 0x8c8c8c, 0x3a3d44, 0x15171b];
|
||||
// ready-made [body, accent] combinations
|
||||
RC.SCHEMES = [[0xff7a1a, 0x15171b], [0x15171b, 0xff7a1a], [0x2a6fd8, 0xe6e6e6], [0xd8452b, 0xf2c230],
|
||||
[0x5fae3b, 0x15171b], [0x6a3fb0, 0xf2c230], [0xe6e6e6, 0xd8452b], [0x3a3d44, 0x2e9c8f]];
|
||||
const hex = n => '#' + (n >>> 0).toString(16).padStart(6, '0');
|
||||
const SELL = 0.5;
|
||||
const GLYPH = { chassis: '🧱', motor: '⚙️', wheels: '🛞', battery: '🔋', armour: '🛡️', weapon: '🪓', tower: '🔥' };
|
||||
const HOTKEY = { weapon: 'hk_weapon', tower: 'hk_tower', gadget: 'hk_gadget' };
|
||||
const GLYPH = { chassis: '🧱', motor: '⚙️', wheels: '🛞', battery: '🔋', armour: '🛡️', weapon: '🪓', tower: '🔥', gadget: '🧰' };
|
||||
const ICO = { hp: ['ico_hp', '❤️'], armour: ['ico_armour', '🛡️'], speed: ['ico_speed', '⏱️'], weight: ['ico_weight', '⚖️'],
|
||||
power: ['ico_power', '⚡'], money: ['ico_credits', '🪙'], fame: ['ico_fame', '⭐'], accel: [null, '🚀'], turn: [null, '↻'] };
|
||||
RC.pic = (name, glyph = '', cls = '') =>
|
||||
@@ -21,7 +25,7 @@
|
||||
|
||||
RC.Shop = function (opt) {
|
||||
const t = opt.t;
|
||||
let slot = 'weapon', sel = undefined, tipN = 0;
|
||||
let slot = 'weapon', sel = undefined, tipN = 0, topTab = 'build';
|
||||
|
||||
function chipsFor(p) {
|
||||
const s = [];
|
||||
@@ -32,6 +36,8 @@
|
||||
if (p.dmg) s.push(`<span>${t('st_dmg', { n: p.dmg })}</span>`);
|
||||
if (p.dps) s.push(`<span>${t('st_dps', { n: p.dps })}</span>`);
|
||||
if (p.range) s.push(`<span>${t('st_range', { n: p.range })}</span>`);
|
||||
// which button works this part in a fight
|
||||
if (HOTKEY[p.slot]) s.push(`<span class="key">⌨ ${t(HOTKEY[p.slot])}</span>`);
|
||||
s.push(`<span>${ico('weight')}${p.weight} kg</span>`);
|
||||
if (p.slot === 'battery') s.push(`<span>${ico('power')}+${p.power}</span>`);
|
||||
else if (p.power) s.push(`<span>${ico('power')}${p.power}</span>`);
|
||||
@@ -101,14 +107,54 @@
|
||||
|
||||
// paint
|
||||
for (const [id, key] of [['paintBody', 'body'], ['paintAccent', 'accent']]) {
|
||||
$(id).innerHTML = `<span class="lb">${t('paint_' + key)}</span>` + RC.PAINTS.map(c => `<span class="sw ${save.paint[key] === c ? 'on' : ''}" data-c="${c}" style="background:${hex(c)}"></span>`).join('');
|
||||
$(id).innerHTML = RC.PAINTS.map(c => `<span class="sw ${save.paint[key] === c ? 'on' : ''}" data-c="${c}" style="background:${hex(c)}"></span>`).join('');
|
||||
$(id).querySelectorAll('.sw').forEach(el => { el.onclick = () => { save.paint[key] = +el.dataset.c; opt.sfx.click(); opt.onSave(); opt.onPaint(); render(); }; });
|
||||
}
|
||||
// ready-made two-colour schemes
|
||||
const sc = $('paintSchemes');
|
||||
if (sc) {
|
||||
sc.innerHTML = RC.SCHEMES.map(([b2, a2]) => {
|
||||
const on = save.paint.body === b2 && save.paint.accent === a2;
|
||||
return `<span class="sw duo ${on ? 'on' : ''}" data-b="${b2}" data-a="${a2}"><i style="background:${hex(b2)}"></i><i style="background:${hex(a2)}"></i></span>`;
|
||||
}).join('');
|
||||
sc.querySelectorAll('.sw').forEach(el => {
|
||||
el.onclick = () => { save.paint.body = +el.dataset.b; save.paint.accent = +el.dataset.a; opt.sfx.click(); opt.onSave(); opt.onPaint(); render(); };
|
||||
});
|
||||
}
|
||||
$('gErr').textContent = v.errors.map(e => t('err_' + e.replace(/^(need|bad)_.*/, '$1'), { slot: t('slot_' + e.split('_')[1]) })).join(' · ');
|
||||
$('bLeague').disabled = !v.ok; $('bTrain').disabled = !v.ok;
|
||||
const name = $('rname');
|
||||
if (document.activeElement !== name) name.value = save.robotName;
|
||||
if (!$('mechTip').textContent) tip();
|
||||
renderTopTabs(); renderFitted();
|
||||
// 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);
|
||||
}
|
||||
|
||||
// top mode tabs: Parts / Paint / Hangar
|
||||
function renderTopTabs() {
|
||||
const tabs = [['build', '🔧 ' + t('tab_build')], ['paint', '🎨 ' + t('tab_paint')], ['hangar', '🚗 ' + t('tab_hangar')]];
|
||||
$('shopTabs').innerHTML = tabs.map(([k, label]) => `<button class="${k === topTab ? 'on' : ''}" data-tab="${k}">${label}</button>`).join('');
|
||||
$('shopTabs').querySelectorAll('button').forEach(bt => { bt.onclick = () => { setTab(bt.dataset.tab); opt.sfx.click(); }; });
|
||||
$('buildView').classList.toggle('hide', topTab !== 'build');
|
||||
$('paintView').classList.toggle('hide', topTab !== 'paint');
|
||||
$('hangarView').classList.toggle('hide', topTab !== 'hangar');
|
||||
if (topTab === 'hangar' && opt.onHangarView) opt.onHangarView($('hangarView'));
|
||||
}
|
||||
function setTab(k) { topTab = k; renderTopTabs(); }
|
||||
|
||||
// fitted parts summary (left column): every slot with the equipped part + quick remove/jump
|
||||
function renderFitted() {
|
||||
const save = opt.getSave(), b = save.build;
|
||||
$('fitted').innerHTML = RC.SLOTS.map(sl => {
|
||||
const id = b[sl], p = id && RC.PARTS[id];
|
||||
const rm = p && !RC.REQUIRED[sl] ? `<span class="frm" data-rm="${sl}">✕</span>` : '<span></span>';
|
||||
return `<div class="frow" data-goto="${sl}">${RC.pic('slot_' + sl, GLYPH[sl])}<span class="fn ${p ? '' : 'empty'}">${p ? p.name : t('none')}</span>${rm}</div>`;
|
||||
}).join('');
|
||||
$('fitted').querySelectorAll('.frow').forEach(el => { el.onclick = e => {
|
||||
if (e.target.dataset.rm) { const s = e.target.dataset.rm; opt.getSave().build[s] = null; opt.sfx.click(); opt.onSave(); opt.onBuild(); render(); return; }
|
||||
slot = el.dataset.goto; sel = opt.getSave().build[slot] || null; topTab = 'build'; opt.sfx.click(); render();
|
||||
}; });
|
||||
}
|
||||
|
||||
function act2(what) {
|
||||
@@ -140,6 +186,6 @@
|
||||
});
|
||||
$('rname').addEventListener('keydown', e => { if (e.key === 'Enter') $('rname').blur(); e.stopPropagation(); });
|
||||
$('mechPic').innerHTML = `<img src="${Kit.asset('assets/Sprites/npc_mechanic.png')}" alt="" onerror="this.classList.add('missing')">`;
|
||||
return { render, tip, reset() { sel = undefined; } };
|
||||
return { render, tip, setTab, reset() { sel = undefined; topTab = 'build'; } };
|
||||
};
|
||||
})(window);
|
||||
|
||||
Reference in New Issue
Block a user