As an example, I have a component called table and a System game which listens for a SocketIO event containing a list of winners (players sat at the table). The game system effectively emits the same event it receives so that each A-Frame component can listen for the ones they need. In my case, when the table "hears" the event emitted by the game System that contains the list of winners, I loop through each and highlight the winning player. At the moment my crude implementation is just to have the table component add some text to the element that has the same id as the corresponding player. This works, but at some point I'd like to call a function on the player component that could do a variety of things (e.g. play a sound, animation, change colour, etc.).
I can see there are a couple of approaches to achieving this:
- Get the
tableto emit an event for each winning player in a way that theplayercomponent can listen for it and do whatever it needs.
OR
- Call a function directly on the player component from the table component by finding the element and then doing something like
playerEl.playWinningAnimation()
Are either of these considered particularly "bad practice"? What are the reasons for one approach over the other?