Skip to content

Commit

Permalink
fix(Core): minor zone changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jtmaca9 committed Sep 27, 2023
1 parent 5d5c34b commit 1c942cf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion example/src/Chess/gameConfig/gameConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { isZoneAvailable } from '../gameLogic';
const zones = createGridZones({
rows: 8,
columns: 8,
gridSize: 45,
gridSizeX: 45,
gridSizeY: 45,
offsetX: 20,
offsetY: 20,
});
Expand Down
4 changes: 2 additions & 2 deletions src/Piece/Piece.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import React, { useEffect, useRef, useState, memo } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import Animated, {
useAnimatedStyle,
useSharedValue,
Expand Down Expand Up @@ -280,4 +280,4 @@ function Piece(props: PieceProps) {
);
}

export default memo(Piece);
export default Piece;
29 changes: 23 additions & 6 deletions src/Zone/Zone.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState, memo } from 'react';
import React, { useEffect, useState } from 'react';
import { type StyleProp, type View, Image } from 'react-native';
import styled from 'styled-components/native';

import { ZONE_TYPE, type ZoneType } from './types';
import { type StyleProp, type View } from 'react-native';
import { ZONE_SPACING } from './zoneSpacing';

const Container = styled.TouchableOpacity<Partial<ZoneProps>>`
Expand All @@ -19,6 +20,8 @@ export type ZoneProps = ZoneType & {
available?: boolean;
ctx: any;
moves: any;
zoneImageSource?: any;
zoneImageProps?: any;
};

enum COMPONENT_STATE {
Expand All @@ -27,8 +30,18 @@ enum COMPONENT_STATE {
}

function Zone(props: ZoneProps) {
const { x, y, width, height, devMode, onPress, availableStyle, available } =
props;
const {
x,
y,
width,
height,
devMode,
onPress,
availableStyle,
available,
zoneImageSource,
zoneImageProps,
} = props;

let [xCoord, setXCoord] = useState(
typeof x === 'number' ? x : ZONE_SPACING[x](width)
Expand Down Expand Up @@ -79,8 +92,12 @@ function Zone(props: ZoneProps) {
borderRadius: 5,
},
]}
/>
>
{zoneImageSource ?? (
<Image source={zoneImageSource} {...zoneImageProps} />
)}
</Container>
);
}

export default memo(Zone);
export default Zone;
14 changes: 8 additions & 6 deletions src/Zone/createGridZones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export function createGridZones({
offsetY = 0,
gapX = 0,
gapY = 0,
gridSize,
gridSizeX,
gridSizeY,
}: {
gridSize: number;
gridSizeX: number;
gridSizeY: number;
rows: number;
columns: number;
offsetX?: number;
Expand All @@ -22,10 +24,10 @@ export function createGridZones({
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,
x: x * gridSizeX + offsetX + x * gapX,
y: y * gridSizeY + offsetY + y * gapY,
width: gridSizeX,
height: gridSizeY,
id: `${x}-${y}`,
meta: {
gridX: x,
Expand Down

0 comments on commit 1c942cf

Please sign in to comment.