Modification appel callback Hoverable composant
This commit is contained in:
parent
e72d90606f
commit
36e5fa6df3
|
@ -24,10 +24,6 @@ class HoverPlugin(Plugin):
|
||||||
mouse_pos = world[Mouse].position
|
mouse_pos = world[Mouse].position
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
|
|
||||||
# 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_callback(world, entity)
|
|
||||||
|
|
||||||
# Récupération de la position et de la taille de l'entité
|
# Récupération de la position et de la taille de l'entité
|
||||||
entity_pos: Vec2 = entity[Position]
|
entity_pos: Vec2 = entity[Position]
|
||||||
if Offset in entity:
|
if Offset in entity:
|
||||||
|
@ -40,15 +36,19 @@ class HoverPlugin(Plugin):
|
||||||
and mouse_pos.y >= entity_pos.y
|
and mouse_pos.y >= entity_pos.y
|
||||||
and mouse_pos.y <= entity_pos.y + entity_size.y
|
and mouse_pos.y <= entity_pos.y + entity_size.y
|
||||||
):
|
):
|
||||||
|
# si notre entitée est hoverable, on execute son initialisation
|
||||||
|
# et pas encore hover (ce qui fait ce elle est executee une seul fois)
|
||||||
|
if Hoverable in entity and not Hover in entity:
|
||||||
|
entity[Hoverable].entry_callback(world, entity)
|
||||||
|
|
||||||
entity.set(Hover())
|
entity.set(Hover())
|
||||||
|
|
||||||
# si notre entitée est aussi hoverable, on execute son initialisation
|
|
||||||
if Hoverable in entity:
|
if Hoverable in entity:
|
||||||
entity[Hoverable].init_callback(world, entity)
|
entity[Hoverable].update_callback(world, entity)
|
||||||
else:
|
else:
|
||||||
if Hover in entity:
|
if Hoverable in entity and Hover in entity:
|
||||||
entity[Hoverable].end_callback(world, entity)
|
entity[Hoverable].exit_callback(world, entity)
|
||||||
entity.remove(Hover)
|
entity.remove(Hover)
|
||||||
|
|
||||||
def apply(self, game: Game) -> None:
|
def apply(self, game: Game) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -71,12 +71,12 @@ class Hoverable:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
init_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
|
entry_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
|
||||||
update_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 : (),
|
exit_callback: Callable[[World, Entity], None] = lambda _a,_b : (),
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.update_callback = update_callback
|
self.update_callback = update_callback
|
||||||
self.init_callback = init_callback
|
self.entry_callback = entry_callback
|
||||||
self.end_callback = end_callback
|
self.exit_callback = exit_callback
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue