Closed DrummerSi closed 4 years ago
Any additional props that you pass to the client component are passed down to the board. So, you can have your board component be a wrapper that is able to switch between layouts like this:
const HQBoard = ({ layout }) => {
if (layout == 'board 1') return <Board1/>;
if (layout == 'board 2') return <Board2/>;
};
render() {
const HQClient = Client({
game: HQGame,
board: HQBoard,
})
return (
<div>
GAME
<HQClient layout="board 1" />
</div>
);
}
If you want to pass options to the game config, then you should use setupData.
Hope that answers your question! Feel free to continue discussion here or on Gitter.
Thanks for the speedy response.. unfortunately it seems the setupData is only available via the game creation API, which is setup for multiplayer only.. I wanted it offline, and to build a basic AI to play against.. Which I understand multiplayer doesn't support.
If I understand your game correctly, you want to pass an option to change something UI related (a board layout) and not something that affects moves etc.?
Are you familiar with the boardgame Heroquest?
It takes place on the same playing board, but each quest adds furniture and doors to the board, changing the layout each time you play.. Because these items change the board layout, they would be required on the game logic to verify moves are legal, etc.
So what I hoped I could do is something like initialise the Client with a quest name.. The client can then load a related json file for the visual tiles, while the game engine will load the json file to track which tiles are valid movement spots, etc
This looks a great framework, but I realise this may be slightly more complex that what it was designed for.
For these cases you should typically perform the selection (the choice of layout) outside of boardgame.io and then initialize the game and client once you do have the exact layout (and relevant game logic) that you want to use.
How is it possible to set options for a game?
I can see that Client.game only has the option 'numPlayers'.. But say I had multiple board layouts, I'd like to pass through which board to use.. ie: board: 1, boards: 2, etc.