-
Notifications
You must be signed in to change notification settings - Fork 2
Signals flow
Godot use signals to transmit information and notify of events. This sections presents how informations should flow form the reception of a WebSocket (WS) or and HTTP response packet to updating the display.
In general the HTTP response are JSON that should be converted to a dictionary. The WebSocket event has always an dictionary (that can be empty). See Network for more information how to define a new WS event.
It is good practice to centralize all the WS event in the same node which is present during all the lifespan of the scene (this would point to use the root node of the scene).
However the state are stored in resources and not dictionary.
The first thing to do is to either update the resource or create a new one.
Be careful, we use a system of reference, meaning that signals are connected to the reference and therefore your new object is not connected to anything even though it represent the same object.
You should always prefer updating a over creating a new one.
Luckily, common data type have a method to update the data of the resource form a dictionary, which is load_dict(dict).
You may want however to write your custom function to update specific part of the resource, and dispatch signals as load_dict(dict) does not emit signals.
Nodes used to display information should connect to relevant data in the game state and update its content on reception of signals.