Example #1
0
    def from_json(json_data):
        from entity import Entity
        main_hand = json_data.get('main_hand')
        off_hand = json_data.get('off_hand')

        equipment = Equipment(Entity.from_json(main_hand) if main_hand else None,
                              Entity.from_json(off_hand) if off_hand else None)

        return equipment
Example #2
0
    def load_game(cls):
        if not os.path.isfile("save_game.json"):
            raise FileNotFoundError

        with open("save_game.json") as save_file:
            json_data = json.load(save_file)

        entities = [
            Entity.from_json(json_data=entity_json_data)
            for entity_json_data in json_data["entities"]
        ]
        player = entities[json_data["player_index"]]

        game_map = GameMap.from_json(json_data=json_data["game_map"])
        message_log = MessageLog.from_json(json_data=json_data["message_log"])
        game_state = GameStates(json_data["game_state"])

        game = cls()
        game.map_generator: Optional[MapGenerator] = MapGenerator(
            map_width=CONSTANTS.map_width, map_height=CONSTANTS.map_height)
        game.entities = entities
        game.player = player

        game.map_generator.game_map = game_map
        game.message_log = message_log
        game.current_state = game_state

        game.camera: Camera = Camera.from_json(json_data=json_data,
                                               player=player)

        return game
    def from_json(cls, json_data):
        from entity import Entity

        if json_data.get('main_hand'):
            main_hand = Entity.from_json(json_data['main_hand'])
        else:
            main_hand = None

        if json_data.get('off_hand'):
            off_hand = Entity.from_json(json_data['off_hand'])
        else:
            off_hand = None

        equipment = cls(main_hand=main_hand, off_hand=off_hand)

        return equipment
Example #4
0
    def from_json(cls, json_data: dict):
        from entity import Entity

        if json_data.get("main_hand"):
            main_hand = Entity.from_json(json_data["main_hand"])
        else:
            main_hand = None

        if json_data.get("off_hand"):
            off_hand = Entity.from_json(json_data["off_hand"])
        else:
            off_hand = None

        equipment = cls(main_hand=main_hand, off_hand=off_hand)

        return equipment
Example #5
0
def json_get_enemy(enemy):
    with open('resources/enemies.json', 'r') as f:
        enemies = json.load(f)
        found_enemy = enemies[enemy]
        #Need these to initialise entity from JSON
        found_enemy['x'] = 0
        found_enemy['y'] = 0
        return Entity.from_json(found_enemy)
Example #6
0
def json_get_item(item):
    with open('resources/items.json', 'r') as f:
        items = json.load(f)
        found_item = items[item]
        #Need these to initialise entity from JSON
        found_item['x'] = 0
        found_item['y'] = 0
        return Entity.from_json(found_item)
Example #7
0
    def from_json(cls, json_data) -> Inventory:
        from entity import Entity

        items = [
            Entity.from_json(item_json_data)
            for item_json_data in json_data.get("items", [])
        ]

        inventory = cls(capacity=json_data.get("capacity"), items=items)

        return inventory
    def from_json(cls, json_data):
        from entity import Entity

        items = [
            Entity.from_json(item_json_data)
            for item_json_data in json_data['items']
        ]

        inventory = cls(capacity=json_data['capacity'], items=items)

        return inventory
Example #9
0
    def from_json(cls, json_data: dict):
        from entity import Entity

        capacity = json_data.get('capacity')
        items_json = json_data.get('items')

        items = [Entity.from_json(item_json) for item_json in items_json]

        inventory = cls(capacity)
        inventory.items = items

        return inventory
Example #10
0
def load_game():
    if not os.path.isfile('save_game.json'):
        raise FileNotFoundError

    with open('save_game.json') as save_file:
        json_data = json.load(save_file)

    entities = [Entity.from_json(json_data=entity_json_data) for entity_json_data in json_data['entities']]
    player = entities[json_data['player_index']]

    game_map = GameMap.from_json(json_data['game_map'])
    message_log = MessageLog.from_json(json_data['message_log'])
    game_state = GameStates(json_data['game_state'])

    return player, entities, game_map, message_log, game_state
Example #11
0
def load_game():
    with open('save_game.json') as save_file:
        data = json.load(save_file)

    player_index = data['player_index']
    entities_json = data['entities']
    game_map_json = data['game_map']
    message_log_json = data['message_log']
    game_state_json = data['game_state']

    entities = [Entity.from_json(entity_json) for entity_json in entities_json]
    player = entities[player_index]
    game_map = GameMap.from_json(game_map_json)
    message_log = MessageLog.from_json(message_log_json)
    game_state = GameStates(game_state_json)

    return player, entities, game_map, message_log, game_state
Example #12
0
def json_load_game():
    with open('savegames/save_game.json', 'r') as save_file:
        data = json.load(save_file)  #Get save data

    player_index = data['player_index']  #Which entity is the player?
    entities_json = data['entities']
    game_map_json = data['game_map']
    message_log_json = data['message_log']
    game_state_json = data['game_state']

    entities = [
        Entity.from_json(entity_json) for entity_json in entities_json
    ]  #Initialise entities from json
    player = entities[player_index]  #Get the player from entities
    game_map = GameMap.from_json(game_map_json)
    message_log = MessageLog.from_json(message_log_json)
    game_state = GameStates(game_state_json)  #Get Enum from int

    return player, entities, game_map, message_log, game_state
Example #13
0
def load_game():
    if not os.path.isfile("save_data"):
        raise FileNotFoundError

    with open("save_data", mode="r") as f:
        json_data = json.load(f)

        player = Entity.from_json(json_data["player"])
        dungeon = {
            int(dungeon_level): GameMap.from_json(map_data)
            for dungeon_level, map_data in json_data["dungeon"].items()
        }
        message_log = MessageLog.from_json(json_data["message_log"])
        game_state = GameState(json_data["game_state"])
        current_level = int(json_data["current_level"])

        dungeon[current_level].entities.append(player)

        return player, dungeon, message_log, game_state, current_level
Example #14
0
def load_game():
    with ZipFile(save_filename, 'r') as savezip:
        json_bytes = savezip.read('savegame.json')

    json_data = json_bytes.decode('utf-8')
    data = json.loads(json_data)

    player_index = data['player_index']
    entities_json = data['entities']
    game_map_json = data['game_map']
    message_log_json = data['message_log']
    game_state_json = data['game_state']

    entities = [Entity.from_json(entity_json) for entity_json in entities_json]
    player = entities[player_index]
    game_map = GameMap.from_json(game_map_json)
    message_log = MessageLog.from_json(message_log_json)
    game_state = GameStates(game_state_json)

    return player, entities, game_map, message_log, game_state
Example #15
0
    def from_json(json_data: Dict) -> "GameMap":
        width = json_data["width"]
        height = json_data["height"]
        tile_map = TileMap.from_json(json_data["tile_map"])
        fov_transparent = np.array(json_data["fov_map_transparent"])
        fov_walkable = np.array(json_data["fov_map_walkable"])
        fov_fov = np.array(json_data["fov_map_fov"])
        explored = np.array(json_data["explored"])
        dungeon_level = json_data["dungeon_level"]
        entities = [Entity.from_json(entity_data) for entity_data in json_data["entities"]]

        loaded_map = GameMap(width, height)
        loaded_map.tile_map = tile_map
        loaded_map.fov_map.transparent[:] = fov_transparent[:]
        loaded_map.fov_map.walkable[:] = fov_walkable[:]
        loaded_map.fov_map.fov[:] = fov_fov[:]
        loaded_map.explored = explored
        loaded_map.dungeon_level = dungeon_level
        loaded_map.entities = entities

        return loaded_map