feat: Making the game harder to 'beat'

This commit is contained in:
gauvainboiche
2026-10-08 17:17:21 +02:00
parent 2f7c307f0e
commit 8b15c76b14
20 changed files with 637 additions and 91 deletions
+9 -7
View File
@@ -1,6 +1,7 @@
// Legacy tab: restart the run for permanent points, spend them on perks.
import { legacyGain, perkCost, perkLevel } from '../engine/legacy.js';
import { legacyGain, nextPointAt, perkCost, perkLevel } from '../engine/legacy.js';
import { passiveBonus } from '../engine/modifiers.js';
import { t } from '../services/i18n.js';
import { h, icon, makeBuyable, setBuyable } from './dom.js';
import { bump, purchased } from './fx.js';
@@ -58,7 +59,7 @@ export function createLegacyView(root, actions) {
'section',
{ class: 'panel' },
h('h2', { class: 'panel__title', text: t('tab.legacy') }),
h('p', { class: 'hint', text: t('legacy.intro', { passive: fmt.number(ctx.rules.legacy.passivePerPoint * 100) }) }),
h('p', { class: 'hint', text: t('legacy.intro') }),
h('div', { class: 'tile tile--primary' }, icon('res.legacy'), h('div', {}, h('span', { class: 'tile__label', text: t('theme.res.legacy') }), els.points)),
h(
'dl',
@@ -84,21 +85,22 @@ export function createLegacyView(root, actions) {
}
function update(state, d) {
const { threshold, passivePerPoint } = ctx.rules.legacy;
setText(els.points, fmt.number(state.legacy.points));
setText(els.earned, fmt.number(state.legacy.earned));
setText(els.prestiges, fmt.number(state.legacy.prestiges));
setText(els.passive, t('legacy.passiveValue', { bonus: fmt.number((1 + passivePerPoint) ** state.legacy.earned) }));
setText(els.passive, t('legacy.passiveValue', { bonus: fmt.number(passiveBonus(state, ctx)) }));
const gain = legacyGain(state, ctx, d.mods);
setText(els.gain, t('legacy.gain', { gain: fmt.number(gain) }));
els.progress.max = threshold;
els.progress.value = Math.min(state.totalProduced, threshold);
// Points are earned from everything ever produced, so the bar shows the lifetime total.
const target = nextPointAt(state, ctx);
els.progress.max = target;
els.progress.value = Math.min(state.lifetimeProduced, target);
setText(
els.need,
gain >= 1
? t('legacy.ready')
: t('legacy.need', { have: fmt.number(Math.floor(state.totalProduced)), need: fmt.number(threshold) }),
: t('legacy.need', { have: fmt.number(Math.floor(state.lifetimeProduced)), need: fmt.number(target) }),
);
setText(els.restart, t('legacy.restart'));
els.restart.disabled = gain < 1;
+17 -4
View File
@@ -3,10 +3,23 @@ import { $, h } from './dom.js';
const DURATION_MS = 6000;
const MAX_VISIBLE = 3; // a big jump (import, long absence) must not bury the page in messages
export function showToast(message, { error = false } = {}) {
/**
* Show a message for a few seconds.
* `sticky` messages are important: they stay until clicked, and routine messages never push them away.
*/
export function showToast(message, { error = false, sticky = false } = {}) {
const container = $('#toasts');
const toast = h('p', { class: error ? 'toast toast--error' : 'toast', text: message });
const classes = ['toast', error && 'toast--error', sticky && 'toast--sticky'].filter(Boolean);
const toast = h('p', { class: classes.join(' '), text: message });
if (sticky) {
toast.setAttribute('role', 'alert');
toast.addEventListener('click', () => toast.remove());
} else {
setTimeout(() => toast.remove(), DURATION_MS);
}
container.append(toast);
while (container.children.length > MAX_VISIBLE) container.firstElementChild.remove();
setTimeout(() => toast.remove(), DURATION_MS);
const routine = [...container.children].filter((el) => !el.classList.contains('toast--sticky'));
for (const old of routine.slice(0, Math.max(0, routine.length - MAX_VISIBLE))) old.remove();
}