diff --git a/rsg-chess-rn-graphics/index.js b/rsg-chess-rn-graphics/index.js new file mode 100644 index 0000000..fd3c7a5 --- /dev/null +++ b/rsg-chess-rn-graphics/index.js @@ -0,0 +1,3 @@ +import ChessBoard from './src/ChessBoard'; + +export default ChessBoard; diff --git a/rsg-chess-rn-graphics/package.json b/rsg-chess-rn-graphics/package.json new file mode 100644 index 0000000..2d5f4ad --- /dev/null +++ b/rsg-chess-rn-graphics/package.json @@ -0,0 +1,21 @@ +{ + "name": "rsg-chess-rn-graphics", + "version": "0.0.1", + "description": "Beautiful chess graphics for React Native apps.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "Chess", + "RSG", + "Chess", + "graphics", + "React", + "ReactJS", + "ReactNative", + "react-native" + ], + "author": "Radi Cho /RSG Group/", + "license": "Apache-2.0" +} diff --git a/rsg-chess-rn-graphics/readme.md b/rsg-chess-rn-graphics/readme.md new file mode 100644 index 0000000..0ee43d9 --- /dev/null +++ b/rsg-chess-rn-graphics/readme.md @@ -0,0 +1 @@ +# RSG Chess Graphics API for React Native \ No newline at end of file diff --git a/rsg-chess-rn-graphics/src/ChessBoard.js b/rsg-chess-rn-graphics/src/ChessBoard.js new file mode 100644 index 0000000..4ece8d1 --- /dev/null +++ b/rsg-chess-rn-graphics/src/ChessBoard.js @@ -0,0 +1,134 @@ +import React, { Component } from "react"; +import { + Platform, + StyleSheet, + Text, + View, + TouchableOpacity +} from "react-native"; +import { find } from "lodash"; + +import { Game } from "rsg-chess"; + +type Props = { + showValidMoves?: boolean, + rotated?: boolean, + selected?: object, + board: object, + selected: object, + validBG?: string, + whiteCells?: string, + blackCells?: string, + selectedBG?: string, + boardHeight?: number, + boardWidth?: number, + pieceSize?: number, + self: any, + onPress: any +}; + +export default class ChessBoard extends Component { + render() { + const props = this.props; + const { showValidMoves, rotated, board, selected, onPress, self } = props; + const validMoves = selected && selected.getValidMoves(true); + + return ( + + {board && + board.map((row, i) => ( + + {row.map((cell, j) => ( + + + + {cell && cell.char} + + + + ))} + + ))} + + ); + } +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: "center", + alignItems: "center" + }, + row: { + flexDirection: "row" + }, + cell: { + borderColor: "grey", + borderTopWidth: 1, + borderLeftWidth: 1, + justifyContent: "center", + alignItems: "center" + }, + bottomBorder: { + borderBottomWidth: 1 + }, + rightBorder: { + borderRightWidth: 1 + }, + rotatedStyles: { + transform: [{ rotateX: "180deg" }] + } +}); + +ChessBoard.defaultProps = { + showValidMoves: true, + rotated: false, + selected: null, + validBG: "red", + whiteCells: "rgb(255, 205, 160)", + blackCells: "rgb(210, 140, 70)", + selectedBG: "brown", + boardHeight: 50, + boardWidth: 50, + pieceSize: 38, + selected: null, + board: null, + slef: null, + onPress: () => {} +};