Skip to content

Commit

Permalink
fix(Core): type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jtmaca9 committed Sep 21, 2023
1 parent 3c5722b commit 7b30023
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion example/src/Chess/gameConfig/gameConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createGridZones } from '../../../../src/Zone/utils';
import { createGridZones } from '../../../../src/Zone/createGridZones';
import { MOVE_ERROR } from '../../../../src/Game/state';
import { createGameConfig } from '../../../../src/Game/gameConfig';
import pieces from './pieces';
Expand Down
8 changes: 3 additions & 5 deletions src/Piece/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { StyleProp } from 'react-native';

export type PieceBlueprintType = {
id: string;
asset: string;
width?: number;
height?: number;
activeStyle?: StyleProp<any>;
availableStyle?: StyleProp<any>;
defaultStyle?: StyleProp<any>;
activeStyle?: any;
availableStyle?: any;
defaultStyle?: any;
variants: { [key: string]: Partial<PieceBlueprintType> };
};

Expand Down
38 changes: 38 additions & 0 deletions src/Zone/createGridZones.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ZONE_TYPE, type ZoneType } from './types';

export function createGridZones({
rows,
columns,
offsetX = 0,
offsetY = 0,
gapX = 0,
gapY = 0,
gridSize,
}: {
gridSize: number;
rows: number;
columns: number;
offsetX?: number;
offsetY?: number;
gapX?: number;
gapY?: number;
}): ZoneType[] {
const zones: ZoneType[] = [];
for (let x = 0; x < rows; x++) {
for (let y = 0; y < columns; y++) {
zones.push({
zType: ZONE_TYPE.single,
x: x * gridSize + offsetX + x * gapX,
y: y * gridSize + offsetY + y * gapY,
width: gridSize,
height: gridSize,
id: `${x}-${y}`,
meta: {
gridX: x,
gridY: y,
},
});
}
}
return zones;
}
37 changes: 0 additions & 37 deletions src/Zone/utils.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
import { ZONE_TYPE, type ZoneType } from './types';
import { ZONE_SPACING } from './zoneSpacing';

export function createGridZones({
rows,
columns,
offsetX = 0,
offsetY = 0,
gapX = 0,
gapY = 0,
gridSize,
}: {
gridSize: number;
rows: number;
columns: number;
offsetX?: number;
offsetY?: number;
gapX?: number;
gapY?: number;
}): ZoneType[] {
const zones: ZoneType[] = [];
for (let x = 0; x < rows; x++) {
for (let y = 0; y < columns; y++) {
zones.push({
zType: ZONE_TYPE.single,
x: x * gridSize + offsetX + x * gapX,
y: y * gridSize + offsetY + y * gapY,
width: gridSize,
height: gridSize,
id: `${x}-${y}`,
meta: {
gridX: x,
gridY: y,
},
});
}
}
return zones;
}

export function findZoneByCoords(
zones: ZoneType[],
x: number,
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import useGameState from './Game/state/useGameState';

// Zone
import { Zone, ZoneRenderer } from './Zone';
import { createGridZones, movePieceToZone, createSlotsRow } from './Zone/utils';
import { movePieceToZone, createSlotsRow } from './Zone/utils';
import { createGridZones } from './Zone/createGridZones';
import type { ZoneType } from './Zone';
import { ZONE_SPACING } from './Zone/zoneSpacing';
import { ZONE_SPACING_OPTIONS, ZONE_TYPE } from './Zone/types';
Expand Down

0 comments on commit 7b30023

Please sign in to comment.