from .initializer import Initializer


class InitializerObject(Initializer):
    """
    Initializer used to initialize an Object.
    An initializer can be executed by the Engine (by default) or processed by the Interface.

    An initializer is created from a dictionary. the format is the following:

    - name: name of the initializer used as id
    - value_type: for Characteristic, the type of the value (as string)
    - subclass_initializer: name of sub initializer used to initialize sub BaseObject.\
                          For an object, the name of the subclass_initializer must be 'objectstate'.\
                          These initializers must already exist in the game

    :param game: the game where the initializer is created
    :param initializer_dict: the dictionary used to create the initializer
    """

    def apply(self, one_object):
        """
        Apply the initializer for an Object. Apply the initializer of the ObjectState

        :param one_object: the Object to initialize
        """
        init_object_state = self.subclass_initializer['objectstate']
        init_object_state.apply(one_object.object_state)
