Exemplo n.º 1
0
 def _ref2obj(ref):
     obj_keys = ref.keys()
     local_object = BoardItemVoid()
     if 'Wall' in ref['object']:
         local_object = Structures.Wall()
     elif 'Treasure' in ref['object']:
         local_object = Structures.Treasure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
     elif 'GenericStructure' in ref['object']:
         local_object = Structures.GenericStructure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
     elif 'Door' in ref['object']:
         local_object = Structures.Door()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
         if 'restorable' in obj_keys:
             local_object.set_restorable(ref['restorable'])
     elif 'GenericActionableStructure' in ref['object']:
         local_object = Structures.GenericActionableStructure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
     elif 'NPC' in ref['object']:
         local_object = NPC()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'hp' in obj_keys:
             local_object.hp = ref['hp']
         if 'max_hp' in obj_keys:
             local_object.max_hp = ref['max_hp']
         if 'step' in obj_keys:
             local_object.step = ref['step']
         if 'remaining_lives' in obj_keys:
             local_object.remaining_lives = ref['remaining_lives']
         if 'attack_power' in obj_keys:
             local_object.attack_power = ref['attack_power']
         if 'actuator' in obj_keys:
             if 'RandomActuator' in ref['actuator']['type']:
                 local_object.actuator = RandomActuator(moveset=[])
                 if 'moveset' in ref['actuator'].keys():
                     for m in ref['actuator']['moveset']:
                         local_object.actuator.moveset.append(
                             _string_to_constant(m))
             elif 'PathActuator' in ref['actuator']['type']:
                 local_object.actuator = PathActuator(path=[])
                 if 'path' in ref['actuator'].keys():
                     for m in ref['actuator']['path']:
                         local_object.actuator.path.append(
                             _string_to_constant(m))
     # Now what remains is what is common to all BoardItem
     if not isinstance(local_object, BoardItemVoid):
         if 'name' in obj_keys:
             local_object.name = ref['name']
         if 'model' in obj_keys:
             local_object.model = ref['model']
         if 'type' in obj_keys:
             local_object.type = ref['type']
     return local_object
Exemplo n.º 2
0
 def _ref2obj(ref):
     obj_keys = ref.keys()
     local_object = BoardItemVoid()
     if "Wall" in ref["object"]:
         local_object = Structures.Wall()
     elif "Treasure" in ref["object"]:
         local_object = Structures.Treasure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
     elif "GenericStructure" in ref["object"]:
         local_object = Structures.GenericStructure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
     elif "Door" in ref["object"]:
         local_object = Structures.Door()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
         if "restorable" in obj_keys:
             local_object.set_restorable(ref["restorable"])
     elif "GenericActionableStructure" in ref["object"]:
         local_object = Structures.GenericActionableStructure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
     elif "NPC" in ref["object"]:
         local_object = NPC()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "hp" in obj_keys:
             local_object.hp = ref["hp"]
         if "max_hp" in obj_keys:
             local_object.max_hp = ref["max_hp"]
         if "step" in obj_keys:
             local_object.step = ref["step"]
         if "remaining_lives" in obj_keys:
             local_object.remaining_lives = ref["remaining_lives"]
         if "attack_power" in obj_keys:
             local_object.attack_power = ref["attack_power"]
         if "actuator" in obj_keys:
             if "RandomActuator" in ref["actuator"]["type"]:
                 local_object.actuator = RandomActuator(moveset=[])
                 if "moveset" in ref["actuator"].keys():
                     for m in ref["actuator"]["moveset"]:
                         local_object.actuator.moveset.append(
                             _string_to_constant(m))
             elif "PathActuator" in ref["actuator"]["type"]:
                 local_object.actuator = PathActuator(path=[])
                 if "path" in ref["actuator"].keys():
                     for m in ref["actuator"]["path"]:
                         local_object.actuator.path.append(
                             _string_to_constant(m))
     # Now what remains is what is common to all BoardItem
     if not isinstance(local_object, BoardItemVoid):
         if "name" in obj_keys:
             local_object.name = ref["name"]
         if "model" in obj_keys:
             local_object.model = ref["model"]
         if "type" in obj_keys:
             local_object.type = ref["type"]
     return local_object