from siege import game
from siege.component import Component, ComponentDefinition, ComponentFactory


class Ammo(ComponentDefinition):
    def __init__(self, projectile):
        ComponentDefinition.__init__(self)
        self.projectile = projectile
        self.freeze()

    def getType(self):
        return AmmoComponent.TYPE


class AmmoComponent(Component):
    TYPE = "ammo"
    CID = 0
    VERSION = 1

    @staticmethod
    def create(entity, componentType, definition):
        ammo = AmmoComponent(definition)
        entity.add(ammo)
        return ammo

    def __init__(self, definition):
        Component.__init__(self)
        self.projectile = definition.projectile
        self.projectileContent = game.content.get(self.projectile)
        self.freeze()

    @staticmethod
    def register():
        AmmoComponent.CID = game.entity.requestCid(AmmoComponent.TYPE, Ammo)
        game.registerComponent(AmmoComponent.TYPE, ComponentFactory.create(AmmoComponent.create))
