refactor(game): split game.js into sfx, pages, online and workshop modules (P4-5)
Modules are classic-script factories RC.Game<Part>(G); G gives live access to the shared state. Guarded by new browser tests for every moved page and workshop tool (tests/e2e/screens.spec.js).
This commit is contained in:
@@ -26,6 +26,12 @@ async function toLobby(page) {
|
||||
await expect(page.locator('body')).toHaveAttribute('data-mode', 'lobby');
|
||||
}
|
||||
|
||||
const credits = async page => Number((await page.locator('#hMoney').textContent()).replace(/[^\d]/g, ''));
|
||||
// the header shows big amounts short like Kit.fmt does ("10.8K", "1.20M", "3B")
|
||||
const UNIT = { K: 1e3, M: 1e6, B: 1e9 };
|
||||
const parseCredits = text => {
|
||||
const m = String(text).replace(/[,\s]/g, '').match(/([\d.]+)([KMB]?)/i);
|
||||
return m ? Math.round(parseFloat(m[1]) * (UNIT[(m[2] || '').toUpperCase()] || 1)) : NaN;
|
||||
};
|
||||
const credits = async page => parseCredits(await page.locator('#hMoney').textContent());
|
||||
|
||||
module.exports = { mode, login, chooseCountry, toLobby, credits };
|
||||
module.exports = { mode, login, chooseCountry, toLobby, credits, parseCredits };
|
||||
|
||||
Reference in New Issue
Block a user