mirror of
https://github.com/TextPlace/CoreTextPlace.git
synced 2025-05-01 05:01:11 +00:00
25 lines
681 B
TypeScript
25 lines
681 B
TypeScript
import type { SectionData, SectionPosition } from "../types/section.ts";
|
|
import type {
|
|
BoardConfig,
|
|
BoardData,
|
|
CharacterPosition,
|
|
} from "../types/board.ts";
|
|
import { createSection } from "./section.ts";
|
|
|
|
export function createBoard(config: BoardConfig): BoardData {
|
|
const sections: SectionData[][] = Array(config.ySections).map((_, sy) =>
|
|
Array(config.xSections).map((_, sx) => createSection({ sx, sy }, config))
|
|
);
|
|
|
|
return { config, sections };
|
|
}
|
|
|
|
export function locateSection(
|
|
{ x, y }: CharacterPosition,
|
|
config: BoardConfig,
|
|
): SectionPosition {
|
|
return {
|
|
sx: Math.floor(x / config.sectionWidth),
|
|
sy: Math.floor(y / config.sectionHeight),
|
|
};
|
|
}
|