Skip to content

Commit

Permalink
Add alternate battle display mode using new layers
Browse files Browse the repository at this point in the history
  • Loading branch information
tiliv committed May 27, 2024
1 parent 99befd6 commit 265bde9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/components/DisplayWorld.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ export default function DisplayWorld({
const buffers = [];

if (battle) {
const spacers = Array.from({ length: parseInt(height / 2) }, () => Array.from({ length: width }, () => ' '));
const strips = [
(layers.foreground || []).join(''),
(layers.background1 || []).join(''),
(layers.background2 || []).join(''),
];
const y = position.y + 1;
const prefix = `^(${y}|${y-1}|${y-2}),`;
const see = Object.entries(interactions).filter(([k]) => k.match(prefix));
see.forEach(([coord, data]) => {
const [r, c] = coord.split(',').map(Number);
const x = (c - 1) % width;
const layer = Math.abs(r - position.y - 1);
strips[layer] = strips[layer].slice(0, x) + data.sprite + strips[layer].slice(x + 1);
});
buffers.push(
{ fg: '#5553', buffer: [...spacers, strips[2]] },
{ fg: '#5558', buffer: [...spacers, strips[1]] },
{ fg: '#555', buffer: [...spacers, strips[0]] },
{ fg: '#000', buffer: [...spacers, ' '.repeat(local.x) + marker] },
);
} else {
buffers.push(...[
{ fg: '#555', buffer: layers.solid },
Expand Down

0 comments on commit 265bde9

Please sign in to comment.