from components import PaperDoll, Brain
from components.enums import Intention
from engine import GameScene
from systems.utilities import retract_intention, retract_turn

"""
Handle equipping an item to a PaperDoll.
"""


def run(scene: GameScene):
    for brain in [b for b in scene.cm.get(Brain) if b.intention is Intention.EQUIP_ITEM]:
        entity = brain.entity
        target = brain.intention_target
        paper_doll = scene.cm.get_one(PaperDoll, entity=entity)
        paper_doll.weapon = target
        retract_intention(scene, entity)
        retract_turn(scene, entity)
