Exemplo n.º 1
0
def add_asset_instance_to_scene(scene_id, asset_id, description=""):
    """
    Create a new asset instance for given asset and scene.
    """
    instance = AssetInstance.query \
        .filter(AssetInstance.scene_id == scene_id) \
        .filter(AssetInstance.asset_id == asset_id) \
        .order_by(desc(AssetInstance.number)) \
        .first()

    number = 1
    if instance is not None:
        number = instance.number + 1
    name = build_asset_instance_name(asset_id, number)

    asset_instance = AssetInstance.create(asset_id=asset_id,
                                          scene_id=scene_id,
                                          number=number,
                                          name=name,
                                          description=description).serialize()

    events.emit(
        "asset_instance:new", {
            "scene_id": scene_id,
            "asset_id": asset_id,
            "asset_instance_id": asset_instance["id"]
        })
    return asset_instance
Exemplo n.º 2
0
def add_asset_instance_to_asset(asset_id,
                                asset_to_instantiate_id,
                                description=""):
    """
    Create a new asset instance for given asset and scene.
    """
    instance = (AssetInstance.query.filter(
        AssetInstance.target_asset_id == asset_id).filter(
            AssetInstance.asset_id == asset_to_instantiate_id).order_by(
                desc(AssetInstance.number)).first())

    number = 1
    if instance is not None:
        number = instance.number + 1
    name = build_asset_instance_name(asset_to_instantiate_id, number)

    asset_instance = AssetInstance.create(
        asset_id=asset_to_instantiate_id,
        target_asset_id=asset_id,
        number=number,
        name=name,
        description=description,
    ).serialize()

    events.emit(
        "asset_instance:new",
        {
            "asset_id": asset_id,
            "asset_instantiated": asset_to_instantiate_id,
            "asset_instance_id": asset_instance["id"],
        },
    )
    return asset_instance
Exemplo n.º 3
0
def get_asset_instance_raw(asset_instance_id):
    try:
        asset_instance = AssetInstance.get(asset_instance_id)
    except StatementError:
        raise AssetInstanceNotFoundException

    if asset_instance is None:
        raise AssetInstanceNotFoundException

    return asset_instance
Exemplo n.º 4
0
 def generate_fixture_scene_asset_instance(self,
                                           asset=None,
                                           scene=None,
                                           number=1):
     if asset is None:
         asset = self.entity
     if scene is None:
         scene = self.scene
     self.asset_instance = AssetInstance.create(
         asset_id=asset.id,
         entity_id=scene.id,
         entity_type_id=self.scene_type.id,
         number=number,
         description="Asset instance description")
Exemplo n.º 5
0
 def generate_fixture_asset_asset_instance(self,
                                           asset=None,
                                           target_asset=None,
                                           number=1):
     if asset is None:
         asset = self.asset_character
     if target_asset is None:
         target_asset = self.asset
     self.asset_instance = AssetInstance.create(
         asset_id=asset.id,
         target_asset_id=target_asset.id,
         number=number,
         name=breakdown_service.build_asset_instance_name(asset.id, number),
         description="Asset instance description")
     return self.asset_instance
Exemplo n.º 6
0
 def generate_fixture_scene_asset_instance(self,
                                           asset=None,
                                           scene=None,
                                           number=1):
     if asset is None:
         asset = self.asset
     if scene is None:
         scene = self.scene
     self.asset_instance = AssetInstance.create(
         asset_id=asset.id,
         scene_id=scene.id,
         number=number,
         name=breakdown_service.build_asset_instance_name(
             self.asset.id, number),
         description="Asset instance description")
     return self.asset_instance
Exemplo n.º 7
0
def add_asset_instance_to_entity(entity_id, asset_id, description=""):
    entity = entities_service.get_entity_raw(entity_id)
    instance = AssetInstance.query \
        .filter(AssetInstance.entity_type_id == entity.entity_type_id) \
        .filter(AssetInstance.entity_id == entity_id) \
        .filter(AssetInstance.asset_id == asset_id) \
        .order_by(desc(AssetInstance.number)) \
        .first()

    number = 1
    if instance is not None:
        number = instance.number + 1

    return AssetInstance.create(asset_id=asset_id,
                                entity_id=entity_id,
                                entity_type_id=entity.entity_type_id,
                                number=number,
                                description=description).serialize()