assets update + hoverable component #23

Merged
tipragot merged 9 commits from menu into main 2023-10-27 22:29:36 +00:00
Showing only changes of commit e72d90606f - Show all commits

View file

@ -26,8 +26,7 @@ class HoverPlugin(Plugin):
# on execute les update de toutes les entities qui ont le composant Hover et qui sont hoverable
if Hover in entity and Hoverable in entity:
entity[Hoverable]._update(world, entity)
entity[Hoverable].callback(world, entity)
entity[Hoverable].update_callback(world, entity)
# Récupération de la position et de la taille de l'entité
entity_pos: Vec2 = entity[Position]
@ -45,9 +44,11 @@ class HoverPlugin(Plugin):
# si notre entitée est aussi hoverable, on execute son initialisation
if Hoverable in entity:
entity[Hoverable].callback(world, entity)
entity[Hoverable].init_callback(world, entity)
else:
entity.remove(Hover)
if Hover in entity:
entity[Hoverable].end_callback(world, entity)
entity.remove(Hover)
def apply(self, game: Game) -> None:
"""
@ -69,9 +70,13 @@ class Hoverable:
Un composant qui marque une entitée comme pouvant etre survolée.
"""
def __init__(self, callback: Callable[[World, Entity], None], update_callback: Callable[[World, Entity], None]) -> None:
def __init__(self,
init_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
update_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
end_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
) -> None:
self.update_callback = update_callback
self.callback = callback
self.init_callback = init_callback
self.end_callback = end_callback
def _update(self, world: World, entity: Entity) -> None:
self.callback = self.update_callback