mirror of
https://github.com/TextPlace/CoreTextPlace.git
synced 2025-07-09 21:25:32 +00:00
test: more tests
This commit is contained in:
parent
302d6cef3e
commit
9a4927f9b2
6 changed files with 86 additions and 6 deletions
|
@ -5,7 +5,8 @@ import type {
|
|||
CharacterPosition,
|
||||
FullBoard,
|
||||
} from "../types/board.ts";
|
||||
import { createSection } from "./section.ts";
|
||||
import { applyChange, createSection } from "./section.ts";
|
||||
import { BoardChange } from "../types/change.ts";
|
||||
|
||||
export function createBoard(config: BoardConfig): BoardData {
|
||||
const sections: SectionData[][] = Array(config.ySections)
|
||||
|
@ -29,6 +30,12 @@ export function locateSection(
|
|||
};
|
||||
}
|
||||
|
||||
export function applyChangeOnBoard(change: BoardChange, board: BoardData) {
|
||||
const { sx, sy } = locateSection(change, board.config);
|
||||
const section = board.sections[sy][sx];
|
||||
applyChange(change, section);
|
||||
}
|
||||
|
||||
export function renderFullBoard(data: BoardData): FullBoard {
|
||||
const totalLineCount = data.config.sectionHeight * data.config.ySections;
|
||||
const lineLength = data.config.sectionWidth * data.config.xSections;
|
||||
|
|
|
@ -36,6 +36,12 @@ export function applyChange(change: BoardChange, section: SectionData) {
|
|||
const xInSection = change.x - section.offsetX;
|
||||
const yInSection = change.y - section.offsetY;
|
||||
|
||||
const validX = xInSection >= 0 && xInSection < section.ch[0].length;
|
||||
const validY = yInSection >= 0 && yInSection < section.ch.length;
|
||||
if (!validX || !validY) {
|
||||
throw new Error("Change does not belong to this section");
|
||||
}
|
||||
|
||||
if (change.ch) {
|
||||
const chWidth = getCharacterWidth(change.ch);
|
||||
const xCharacterOffset = xInSection % 2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue