Skip to content

Commit

Permalink
fixing entity documentation and using fstrings, added more type annot…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
lunathanael committed Mar 11, 2024
1 parent 14c315c commit 54132c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clash_royale/envs/game_engine/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
These range from the base entity class,
to highly specialized entity classes that implement a custom troop.
"""
"""
31 changes: 16 additions & 15 deletions clash_royale/envs/game_engine/entities/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from clash_royale.envs.game_engine.struct import Stats

if TYPE_CHECKING:
# Only import for typechecking to prevent circular dependency
from clash_royale.envs.game_engine.arena import Arena


Expand Down Expand Up @@ -83,7 +84,7 @@ def arena(self) -> EntityCollection:

return self.collection

def load(self):
def load(self) -> None:
"""
Method called when this entity is loaded.
Expand All @@ -100,21 +101,21 @@ def load(self):

self.state = Entity.LOADED

def unload(self):
def unload(self) -> None:
"""
Method called when this entity is unloaded.
This method is invoked when the entity is unloaded from a high level component.
When this method is called,
it is reasonable to assume that this entity is not going to be used again.
entitys can use this a a sign that their work is done.
entities can use this a a sign that their work is done.
It is recommended to make any final, permanent changes once this method is called.
"""

self.state = Entity.UNLOADED

def start(self):
def start(self) -> None:
"""
Method called when this entity is started.
Expand All @@ -130,7 +131,7 @@ def start(self):

self.state = Entity.STARTED

def stop(self):
def stop(self) -> None:
"""
Method called when this entity is stopped.
Expand All @@ -151,7 +152,7 @@ def stop(self):

self.state = Entity.STOPPED

def render(self):
def render(self) -> None:
"""
Asks this entity to render itself!
Expand All @@ -164,7 +165,7 @@ def render(self):

pass

def simulate(self):
def simulate(self) -> None:
"""
Preforms entity simulation for this frame.
Expand Down Expand Up @@ -208,11 +209,11 @@ class EntityCollection(object):
def __init__(self) -> None:

# entity storage component
self.entities = []
self.entities: list[Entity] = []

self.running = False # Value determining if we are running
self.num_loaded = 0 # Number of entity's currently loaded
self.max_loaded = 0 # Max number of entity's loaded
self.running: bool = False # Value determining if we are running
self.num_loaded: int = 0 # Number of entity's currently loaded
self.max_loaded: int = 0 # Max number of entity's loaded

def load_entity(self, entity: Entity) -> Entity:
"""
Expand Down Expand Up @@ -241,7 +242,7 @@ def load_entity(self, entity: Entity) -> Entity:

# Load error occurred! Raise an exception!

raise Exception("entity load() method failed! Not loading: {}".format(entity), e)
raise Exception(f"entity load() method failed! Not loading: {entity}", e)

# Add the entity to our collection:

Expand Down Expand Up @@ -292,7 +293,7 @@ def unload_entity(self, entity: Entity) -> Entity:

# Raise an exception of our own:

raise Exception("entity failed to unload! Unloading: {}".format(entity), e)
raise Exception(f"entity failed to unload! Unloading: {entity}", e)

# Unload the entity:

Expand Down Expand Up @@ -328,7 +329,7 @@ def stop_entity(self, entity: Entity) -> Entity:

self._unload_entity(entity)

raise Exception("entity stop() method failed! Unloading: {}".format(entity), e)
raise Exception(f"entity stop() method failed! Unloading: {entity}", e)

# Return the entity:

Expand Down Expand Up @@ -364,7 +365,7 @@ def start_entity(self, entity: Entity) -> Entity:

# Raise an exception:

raise Exception("entity start() method failed! Unloading: {}".format(entity), e)
raise Exception(f"entity start() method failed! Unloading: {entity}", e)

# Return the entity:

Expand Down

0 comments on commit 54132c6

Please sign in to comment.