fix any in CotMG helper

This commit is contained in:
Olivier Gagnon 2022-07-18 03:26:07 -04:00
parent 55c5190986
commit 7455b80466
3 changed files with 8 additions and 8 deletions

@ -13,18 +13,18 @@ export function loadStaneksGift(saveString: string): void {
}
}
export function zeros(dimensions: number[]): any {
export function zeros(width: number, height: number): number[][] {
const array = [];
for (let i = 0; i < dimensions[0]; ++i) {
array.push(dimensions.length == 1 ? 0 : zeros(dimensions.slice(1)));
for (let i = 0; i < width; ++i) {
array.push(Array(height).fill(0));
}
return array;
}
export function calculateGrid(gift: IStaneksGift): number[][] {
const newgrid = zeros([gift.width(), gift.height()]) as unknown as number[][];
const newgrid = zeros(gift.width(), gift.height()) as unknown as number[][];
for (let i = 0; i < gift.width(); i++) {
for (let j = 0; j < gift.height(); j++) {
const fragment = gift.fragmentAt(i, j);

@ -13,7 +13,7 @@ interface IProps {
export function DummyGrid(props: IProps): React.ReactElement {
const gift = new DummyGift(props.width, props.height, props.fragments);
const ghostGrid = zeros([props.width, props.height]);
const ghostGrid = zeros(props.width, props.height);
return (
<Box>
<Table sx={{ width: props.width, height: props.height }}>

@ -18,7 +18,7 @@ interface IProps {
}
export function MainBoard(props: IProps): React.ReactElement {
const [ghostGrid, setGhostGrid] = React.useState(zeros([props.gift.width(), props.gift.height()]));
const [ghostGrid, setGhostGrid] = React.useState(zeros(props.gift.width(), props.gift.height()));
const [pos, setPos] = React.useState([0, 0]);
const [rotation, setRotation] = React.useState(0);
const [selectedFragment, setSelectedFragment] = React.useState(NoneFragment);
@ -26,7 +26,7 @@ export function MainBoard(props: IProps): React.ReactElement {
function moveGhost(worldX: number, worldY: number, rotation: number): void {
setPos([worldX, worldY]);
if (selectedFragment.type === FragmentType.None || selectedFragment.type === FragmentType.Delete) return;
const newgrid = zeros([props.gift.width(), props.gift.height()]);
const newgrid = zeros(props.gift.width(), props.gift.height());
for (let y = 0; y < selectedFragment.height(rotation); y++) {
for (let x = 0; x < selectedFragment.width(rotation); x++) {
if (!selectedFragment.fullAt(x, y, rotation)) continue;
@ -61,7 +61,7 @@ export function MainBoard(props: IProps): React.ReactElement {
function updateSelectedFragment(fragment: Fragment): void {
setSelectedFragment(fragment);
const newgrid = zeros([props.gift.width(), props.gift.height()]);
const newgrid = zeros(props.gift.width(), props.gift.height());
setGhostGrid(newgrid);
}