HeladoDeBrownie / Nexus

creative sandbox game in early development
MIT License
3 stars 1 forks source link

move modification detection hooks into the thing being modified #110

Open HeladoDeBrownie opened 3 years ago

HeladoDeBrownie commented 3 years ago

Session needs to know when its Scene is modified. this logic happens in SceneView. it ought to happen in Scene instead, by way of callback registration or the like, so that SceneView doesn't have to care what a session is

likewise, Chunk's api is somewhat defensive when it comes to accessing its sprites, because it needs to know when to update itself when they've changed. this can likewise be handled in Sprite itself using callback registration

HeladoDeBrownie commented 3 years ago

this calls for a mixin, call it EventSource, with methods emit and register. emit takes an event name and optional arguments and runs all registered callbacks. register takes an event name and a function and registers the function as a callback

HeladoDeBrownie commented 3 years ago

SceneView.broadcast_position and SceneView.broadcast_sprite are both functions that serve a purpose that will be implemented in Scene itself instead. they will be removed completely along with all references to self.session in that module

this necessitates a change in Network/Session.lua as well. it will call listen on the Scene instead of having to tell the SceneView about itself