Open jbheard opened 3 years ago
We will also want some object resolving functionality in the context manager. For example functions:
# Name is unique to templates, not instances, this can return many
def get_by_name(self, name: str) -> GameObject:
return [obj for obj in self.objects if obj.name == name]
# IDs are unique to instances, this will only ever return 1
def get_by_id(self, id: int) -> GameObject:
for obj in self.objects:
if obj.id == id:
return obj
return None
Added GameObject
class in #34. The changes to Item
also rely on having a sort of global game context.
Now we need to decide whether to add the context as:
I'm leaning towards making it instantiable and each Game
object will have a single context. I'm not sure if this is the right way to go about things though. I doubt we will ever need to load multiple games simultaneously, but this approach would allow it.
Create a global game context with basic functionality. This has a few parts:
Base class for all GameObjects
GameObject
class and extend with enemy, item, etc specific behaviours. See below for a very simple example class.GameObjects
and some base functionality without caring what they actually areSeparation of game and context
Game
object stores all game information, and leans towards maintaining context as well. Ideally, we should have aGameContext
object that maintains the game context, and theGame
class is only responsibleSeparation of template objects from instance objects
load_from_template
implemented for all GameObjects? See example below.GameObject Skeleton:
For the method
load_from_template
above, see here. It seems like static & abstract don't mingle very well on their own and need a custom fix.