Exemple #1
0
def build_actor(game, dir, name, parent):
    filename = name + ".json"
    path = os.path.join(dir, filename)
    data = datahelpers.load_json(path)
    data["script_dir"] = dir + "/scripts"
    data["actions"] = [game.actions[action] for action in data["actions"]]
    new_actor = Actor.get_actor(parent, **data)
    # loading item objects in inventory after actor object instantiated
    new_actor.inventory = build_items(game, new_actor, new_actor.inventory)
    if isinstance(new_actor, Player):
        game.pc = new_actor
    return new_actor
Exemple #2
0
def build_exits(game):
    exit_dir = game.base_dir + "/exits"
    for room in game.rooms:
        built_exits = []
        for exit_data in game.rooms[room].exits:
            exit_name = exit_data["exit"]
            filename = exit_name + ".json"
            path = os.path.join(exit_dir, filename)
            data = datahelpers.load_json(path)
            parent = room
            c_room = game.rooms[exit_data["room"]]
            new_exit = Exit(parent=parent, c_room=c_room, **data)
            built_exits.append(new_exit)
        game.rooms[room].exits = built_exits
Exemple #3
0
def build_world(game):
    world_file = game.base_dir + "/world.json"
    data = datahelpers.load_json(world_file)
    parent = game
    return World(parent, **data)
Exemple #4
0
def build_item(game, dir, name, parent):
    filename = name + ".json"
    path = os.path.join(dir, filename)
    data = datahelpers.load_json(path)
    data["action"] = game.actions[data["action"]]
    return Item(parent, **data)