ecs #58
|
@ -2,8 +2,9 @@
|
|||
Un plugin permettant de savoir si l'on a cliqué sur une entité.
|
||||
"""
|
||||
|
||||
from typing import Callable
|
||||
from engine import GlobalPlugin
|
||||
from engine.ecs import World
|
||||
from engine.ecs import Entity, World
|
||||
from plugins.hover import Hovered
|
||||
from plugins.inputs import Pressed
|
||||
from plugins.render import Sprite
|
||||
|
@ -15,6 +16,15 @@ class Clicked:
|
|||
"""
|
||||
|
||||
|
||||
class Clickable:
|
||||
"""
|
||||
Composant qui permet d'executer une fonction lorsqu'une entité est cliquee.
|
||||
"""
|
||||
|
||||
def __init__(self, callback: Callable[[World, Entity], object]):
|
||||
self.callback = callback
|
||||
|
||||
|
||||
def __update_clicked(world: World):
|
||||
"""
|
||||
Met à jour les composants `Clicked`.
|
||||
|
@ -24,6 +34,8 @@ def __update_clicked(world: World):
|
|||
for entity in sprite_entities:
|
||||
if Hovered in entity and mouse_click:
|
||||
entity[Clicked] = Clicked()
|
||||
if Clickable in entity:
|
||||
entity[Clickable].callback(world, entity)
|
||||
else:
|
||||
del entity[Clicked]
|
||||
|
||||
|
|
Loading…
Reference in a new issue