-
-
Notifications
You must be signed in to change notification settings - Fork 66
Application overview
Already defined game messages are placed here
Game messages are created based on Events and operations. Adding entry to messages.json file is going to generate photon messages during compilation.
Already defined game events are placed here. Translation between <Game Message> and <Game Event> is performed in world and convert modules.
Such translation is necessary because of inconsistency between player ids placed in <Game Message>. E.g player id is different in each zone. Such solution yields much easier use in Application development.
To visualize process we're going to show how UpdateFame <Game Message> is converted and then published as UpdateFame <Game Event>
-
Find event / operation which might contain fame information. Based on Events and operations
UpdateFameis probably a jackpot. -
Adding entry to
messages.jsonto generateUpdateFamemessage{ "name": "UpdateFame", "code": 72, "params": [] }From decompiled .dll we know that
UpdateFamehas code72(it's 72th event on the list) -
In the
backend.logfile we can see following entry17:41:57 [ INFO] UpdateFame parameters: {7: Short(371), 2: Integer(100000000), 6: Float(1.0), 252: Short(72), 1: Long(781457927639), 0: Short(327)}As I've used a book which gives 10k fame it looks like parameter
2contains information about fame.Parameter
7is probably responsible for identifying source of this message (in this case our character)Let's update
JSONentry{ "name": "UpdateFame", "code": 72, "params": [ { "name": "source", "id": 0, "param_type": "Number" }, { "name": "fame", "id": 2, "param_type": "Number" } ] }, -
Translating
UpdateFamemessage intoUpdateFameeventSince we knew that book gave us 10k fame but value visible in message was 10k bigger we need to adjust that.
// convert.rs impl From<EventIntermediate<messages::UpdateFame>> for events::Event { fn from(intermediate: EventIntermediate<messages::UpdateFame>) -> Self { Self::UpdateFame(events::Fame { source: intermediate.id, value: intermediate.message.fame as f32 / 10000.0, }) } }
We want to have static id's accessible from GUI, therefore final event is constructed in the following way:
// world.rs photon_messages::Message::UpdateFame(msg) => { let static_id = self.get_static_id(msg.source)?; Some(vec![self.get_intermediate(static_id, msg)?.into()]) }
-
Publishing
UpdateFamegame event to the applicationSince our target application is created in python we need to translate
GameEventinto pythondictionary. Such translation is done in crosslang/python/convert.rs module// convert.rs impl ToPyObject for Event { type ObjectType = PyObject; fn to_py_object(&self, py: Python) -> Self::ObjectType { let event = PyDict::new(py); match self { // other events omitted Event::UpdateFame(e) => { event.set_item(py, "name", "UpdateFame".into_py_object(py)).unwrap_or(()); event.set_item(py, "value", e.into_py_object(py)).unwrap_or(()); } } event.into_object() } } impl ToPyObject for events::Fame { type ObjectType = PyObject; fn to_py_object(&self, py: Python) -> Self::ObjectType { let event = PyDict::new(py); event.set_item(py, "source", self.source.into_py_object(py)).unwrap_or(()); event.set_item(py, "value", self.value.into_py_object(py).into_object()).unwrap_or(()); event.into_object() } }
-
Accessing
FameUpdateevent in python applicationclass EventReceiver(abc.ABC): def receive(self, event): # other events omitted if event_name == consts.EvNameUpdateFame: self.on_fame_update(value[consts.EvKeyValue])