import {
FLOATING_TEXT_STACK_GAP,
floatingTextStackLift,
floatingTextStackLifePenalty,
floatingTextStackMoves,
} from '@datamoc/mw_games/two-d/ui';
const older = { key: 'hero', x: 0, y: 0, height: 10 };
const newcomer = { key: 'hero', x: 0, y: 0, height: 8 };
console.log(FLOATING_TEXT_STACK_GAP); // 4, the gap Java's push leaves
console.log(floatingTextStackLift(older, newcomer)); // -13, where the older line must sit
console.log(floatingTextStackLifePenalty(1)); // 0.2, the age a first lifted line is forced to
console.log(floatingTextStackMoves([older], newcomer)); // [{ index: 0, y: -13, ageAtLeast: 0.2 }]
The whole stacking policy as arithmetic: which of
live(oldest first) share the newcomer's key, where each of them ends up, and what age each is forced to.Newest first, stopping at the first line already clear of the one below it: a stack is ordered, an older line sits above a newer one, so a line that needs no move means nothing above it does either. That is Java's
break, and the reason the walk runs backwards overlive.Pure and exported for the same reason
floatingTextStackLiftis: applying a plan needs aFloatingText, which is aLabel, which needs a DOM. The decision is therefore checked as arithmetic and the class is left with the assignments.pushinlined this loop once, and the loop is where the direction, the order and the life floor were all wrong at the same time.