imralav wrote: ↑21 October 2024, 12:27
Tof63 wrote: ↑21 October 2024, 10:40
I wouldn't be so categorical, it depends on the game...
For some games with a “simple” interface here, the game board is displayed with a canvas in which the interface is drawn. For this kind of game, if the board were displayed with a piece of React code, I think it would be just as good...
For the one I made (
https://boardgamearena.com/gamepanel?ga ... reflection) this is the case: the whole game is made in the traditional way, except for the game grid which is in React. And I think it saved me a lot of time to do that ...
How did you integrate react with BGA? And what difficulties did you face? It's interesting, please elaborate on that a little more.
It is quite simple in fact.
The game is separated into two distinct parts:
- the main (php + javascript) project using the “classic” bga framework. This manages the reception of events from the server and the sending of actions to the server + the display of players panels.
This project defines window.game.actionXXX functions that are called by the React project when the user performs an action on the game board.
- the React project, which manages only the display of the game board and player actions on it.
This project defines window.game.onEventXXX functions, which are called in javascript (by the main project) when events are received from the server.
In the .tpl file of the main project I have this code : <div id="root"></div>
And in my React project I render the React component in this div.
When the React project is built, the .js result file is copied in "modules" folder of the main project, and is loaded like this :
define([
"dojo", "dojo/_base/declare",
"ebg/core/gamegui",
"ebg/counter",
g_gamethemeurl + "modules/main.js"
],
You have the full code here if you want :
https://github.com/cdelaforge/reflection
It was one of my first React project, and I'd never developed in php before either, so if I had to do it again now I think I'd do it better and prettier, but it does the job ...
