mirror of
https://github.com/TextPlace/CoreTextPlace.git
synced 2025-05-01 05:01:11 +00:00
feat: renderFullBoard
This commit is contained in:
parent
2836153a7f
commit
b2158a63c2
1 changed files with 57 additions and 0 deletions
|
@ -3,6 +3,7 @@ import type {
|
|||
BoardConfig,
|
||||
BoardData,
|
||||
CharacterPosition,
|
||||
FullBoard,
|
||||
} from "../types/board.ts";
|
||||
import { createSection } from "./section.ts";
|
||||
|
||||
|
@ -23,3 +24,59 @@ export function locateSection(
|
|||
sy: Math.floor(y / config.sectionHeight),
|
||||
};
|
||||
}
|
||||
|
||||
export function renderFullBoard(data: BoardData): FullBoard {
|
||||
const totalLineCount = data.config.sectionHeight * data.config.ySections;
|
||||
const lineLength = data.config.sectionWidth * data.config.xSections;
|
||||
|
||||
const chLines: string[] = Array(totalLineCount);
|
||||
const colorLines: string[] = Array(totalLineCount);
|
||||
const bgColorLines: string[] = Array(totalLineCount);
|
||||
const widthLines: string[] = Array(totalLineCount);
|
||||
|
||||
for (let y = 0; y < totalLineCount; y++) {
|
||||
let chLine = "";
|
||||
let colorLine = "";
|
||||
let bgColorLine = "";
|
||||
let widthLine = "";
|
||||
|
||||
let charsToSkip = 0;
|
||||
|
||||
for (let x = 0; x < lineLength; x++) {
|
||||
if (charsToSkip > 0) {
|
||||
charsToSkip--;
|
||||
continue;
|
||||
}
|
||||
|
||||
const { sx, sy } = locateSection({ x, y }, data.config);
|
||||
const section = data.sections[sy][sx];
|
||||
const xInSection = x % data.config.sectionWidth;
|
||||
const yInSection = y % data.config.sectionHeight;
|
||||
|
||||
const cCh = section.ch[yInSection][xInSection];
|
||||
const cCo = section.color[yInSection][xInSection];
|
||||
const cBg = section.bgColor[yInSection][xInSection];
|
||||
const cWd = section.width[yInSection][xInSection];
|
||||
|
||||
chLine += cCh;
|
||||
colorLine += cCo;
|
||||
bgColorLine += cBg;
|
||||
widthLine += cWd.toString();
|
||||
charsToSkip += cWd - 1;
|
||||
}
|
||||
|
||||
chLines[y] = chLine;
|
||||
colorLines[y] = colorLine;
|
||||
bgColorLines[y] = bgColorLine;
|
||||
widthLines[y] = widthLine;
|
||||
}
|
||||
|
||||
return {
|
||||
w: lineLength,
|
||||
h: totalLineCount,
|
||||
ch: chLines.join("\n"),
|
||||
color: colorLines.join("\n"),
|
||||
bg_color: bgColorLines.join("\n"),
|
||||
width: widthLines.join("\n"),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue