Exemple #1
0
def editor(game, level, char_name, conversations):
    options = [
        {'key': 'c', 'text': 'create new'},
        {'key': 'e', 'text': 'bind existing'},
    ]
    cmd = txt.promptInput('Conversation Editor', options)
    if cmd[0] == 'e':
        choice = txt.getOption('Select Conversation', conversations)

        options = [
            {'key': 'l', 'text': 'location'},
            {'key': 'co', 'text': 'conversation'},
        ]
        s_cmd = txt.promptInput('Conversation Editor', options)
        if s_cmd[0] == 'l':
            [old_loc, char_name] = conversations[choice].split('-')
            new_loc = util.chooseLocation(game, level, exclude=[old_loc])
            game_obj = util.loadLocalizedGameObj('conversations',
                                     game, level, old_loc, char_name)

            game_obj['location'] = new_loc
            util.removeLocalizedGameObj('conversations',
                                        game, level, old_loc, char_name)
            util.saveLocalizedGameObj('conversations',
                                     game, level, new_loc, char_name, game_obj)
            conversations.remove(conversations[choice])
            conversations.append(util.getLocalizedReference('conversations',
                                                level, location, char_name))
        if s_cmd[0] == 'co':
            [location, char_name] = conversations[choice].split('-')
            edit(game, level, char_name, location)
    elif cmd[0] == 'c':
        conversations.append(createNew(game, level, char_name))

    return conversations
Exemple #2
0
def editor(game, level, location_name, connection_objs):
    if connection_objs is None:
        connection_objs = []
    print(connection_objs)
    inputOptions = [
        {
            'key': 'e',
            'text': 'edit'
        },
        {
            'key': 'a',
            'text': 'add'
        },
    ]
    cmd = txt.promptInput('Connection Editor', inputOptions)

    if cmd[0] == 'e':
        arg_id = txt.getOption(
            'Which connection?',
            [connection['direction'] for connection in connection_objs])
        connection_objs[arg_id] = edit(game, connection_objs[arg_id], level,
                                       location_name)
    elif cmd[0] == 'a':
        connection_objs.append(createNew(game, level, location_name))
    return connection_objs
Exemple #3
0
def edit(game, connection_obj, location_level, location_name):
    cmd = ['']
    while cmd[0] != ':q':
        inputOptions = [{
            'key': 'di',
            'text': 'change direction name'
        }, {
            'key': 'l',
            'text': 'change location reference'
        }, {
            'key': 'b',
            'text': 'change blockade'
        }, {
            'key': 'de',
            'text': 'change travel description'
        }, {
            'key': ':q',
            'text': 'Done editing'
        }]
        print(yaml.dump(connection_obj))
        cmd = txt.promptInput("Connection Editor", inputOptions)
        if cmd[0] == 'di':
            print(
                "DON'T CHANGE A CARDINAL DIRECTION, if you must, edit it manually in the configs"
            )
            connection_obj['direction'] = txt.getStr("Direction")
        elif cmd[0] == 'l':
            current_ref = connection_obj['location']
            location_ref = getLocationRef(game, location_level, location_name)
            from_ref = util.getReference('locations', location_level,
                                         location_name)

            if current_ref is not None:
                removeInboundConnectionFromRef(game,
                                               connection_obj['direction'],
                                               from_ref, current_ref)
            addInboundConnectionToRef(game, from_ref,
                                      connection_obj['direction'],
                                      location_ref)

            connection_obj['location'] = location_ref
        elif cmd[0] == 'b':
            if connection_obj['travel_blockade'] is not None:
                connection_obj['travel_blockade'] = editBlocker(
                    game, connection_obj['travel_blockade'])
            else:
                connection_obj['travel_blockade'] = createNewBlocker(game)

        elif cmd[0] == 'de':
            connection_obj['travel_description'] = txt.getStr(
                'Travel Description')

    return connection_obj
Exemple #4
0
def createNew(game, location_level, location_name):
    if txt.getYesNo('Cardinal Direction? (y/n)'):
        inputOptions = [
            {
                'key': 'n',
                'text': 'north'
            },
            {
                'key': 's',
                'text': 'south'
            },
            {
                'key': 'e',
                'text': 'east'
            },
            {
                'key': 'w',
                'text': 'west'
            },
            {
                'key': 'u',
                'text': 'up'
            },
            {
                'key': 'd',
                'text': 'down'
            },
        ]
        cmd = txt.promptInput('Cardinal Directions', inputOptions)
        direction = [
            opt['text'] for opt in inputOptions if opt['key'] == cmd[0]
        ][0]

    to_text = txt.getStr("Travel to Description")

    if txt.getYesNo('Has Blocker? (y/n) '):
        travel_blockade = createNewBlocker(game)
    else:
        travel_blockade = None

    # Allow inter-level connections (level changes smoothly via travel)
    location_ref = getLocationRef(game, location_level, location_name)
    from_ref = util.getReference('locations', location_level, location_name)
    addInboundConnectionToRef(game, from_ref, direction, location_ref)

    return {
        'direction': direction,
        'location': location_ref + '.name',
        'travel_blockade': travel_blockade,
        'travel_description': to_text,
    }
Exemple #5
0
def edit(game, level, location):
    print(game, level, location)
    location_obj = util.loadConfig('locations', game, level, location)
    original_name = location_obj['name']
    cmd = ['']
    options = [
        {
            'key': 'd',
            'text': 'description'
        },
        {
            'key': 'c',
            'text': 'connections'
        },
        {
            'key': 'e',
            'text': 'examine_text'
        },
        {
            'key': 'n',
            'text': 'name'
        },
        {
            'key': ':q',
            'text': 'quit'
        },
    ]
    while cmd[0] != ':q':
        print(yaml.dump(location_obj))
        cmd = txt.promptInput('Location Editor', options)

        if cmd[0] == 'n':
            location_obj['name'] = util.chooseUniqueName(
                'locations', game, level)
        elif cmd[0] == 'd':
            location_obj['description'] = txt.getStr('description')
        elif cmd[0] == 'e':
            location_obj['examine_text'] = txt.getStr('examine_txt')
        elif cmd[0] == 'c':
            location_obj['connections'] = connection.editor(
                game, level, location_obj['name'], location_obj['connections'])

    if original_name != location_obj['name']:
        util.removeGameObj('locations', game, level, original_name,
                           location_obj)
    util.saveGameObj('locations', game, level, location_obj['name'],
                     location_obj)

    return location_obj['name'].lower().replace(' ', '_')
Exemple #6
0
def editBlocker(game, blocker):
    cmd = ['']
    while cmd[0] != ':q':
        print(yaml.dump(blocker))
        options = [
            {
                'key': 's',
                'text': 'replace state'
            },
            {
                'key': 'v',
                'text': 'replace value'
            },
            {
                'key': 'f',
                'text': 'repplace failure_text'
            },
            {
                'key': 'p',
                'text': 'replace success_text'
            },
            {
                'key': ':q',
                'text': 'quit'
            },
        ]
        cmd = txt.promptInput('Blocker Editor', options)

        if cmd[0] == 's':
            blocker['state'] = txt.getStr('Block State')
        if cmd[0] == 'v':
            blocker['value'] = txt.getStr('Block State Value')
        if cmd[0] == 'f':
            blocker['failure'] = txt.getStr('Failure Text')
        if cmd[0] == 'p':
            blocker['success'] = txt.getStr('Success Text')

    return blocker
Exemple #7
0
def edit(game, level, location, item_name):
    item_obj = util.loadItem(game, level, location, item_name)
    original_location = util.extractReference(
        item_obj['start_location'])['obj_name']
    original_name = item_obj['name']
    inputOptions = [
        {
            'key': 'n',
            'text': 'name'
        },
        {
            'key': 'd',
            'text': 'description'
        },
        {
            'key': 'e',
            'text': 'examine'
        },
        {
            'key': 'l',
            'text': 'location'
        },
        {
            'key': 't',
            'text': 'is_takeable'
        },
        {
            'key': 'c',
            'text': 'is_container'
        },
        {
            'key': ':q',
            'text': 'quit'
        },
    ]
    cmd = ['']
    while cmd[0] != ':q':
        print(yaml.dump(item_obj))

        cmd = txt.promptInput('Item Editor', inputOptions)

        if cmd[0] == 'n':
            if len(cmd) > 1:
                name = ' '.join(cmd[1:])
            else:
                name = util.chooseUniqueName('items', game, level)
            item_obj['name'] = name

        elif cmd[0] == 'd':
            if len(cmd) > 1:
                description = ' '.join(cmd[1:])
            else:
                description = txt.getStr('Description')
            item_obj['description'] = description

        elif cmd[0] == 'e':
            if len(cmd) > 1:
                examine = ' '.join(cmd[1:])
            else:
                examine = txt.getStr('Examine')
            item_obj['examine'] = examine

        elif cmd[0] == 'l':
            item_obj['start_location'] = util.chooseStartingLocation(
                game, level)

        elif cmd[0] == 't':
            is_takeable = txt.getYesNo("Is takeable?\n> ")
            if is_takeable:
                take_suggestion = item_obj.get('take_text', '')
                drop_suggestion = item_obj.get('drop_text', '')
                item_obj['take_text'] = txt.getStr("Take Text",
                                                   take_suggestion)
                item_obj['drop_text'] = txt.getStr("Drop Text",
                                                   drop_suggestion)
            elif not is_takeable:
                item_obj['take_text'] = None
                item_obj['drop_text'] = None
            item_obj['takeable'] = is_takeable

        elif cmd[0] == 'c':
            item_obj['is_container'] = txt.getYesNo("Is Container?\n> ")

    location = util.extractReference(item_obj['start_location'])['obj_name']
    if original_name != item_obj['name'] or original_location != location:
        util.removeItem(game, level, original_location, original_name)
    util.saveItem(game, level, location, item_obj['name'], item_obj)
def edit(game, level, location, character_name):
    char_obj = util.loadConfig('characters', game, level, character_name)
    inputOptions = [
        {'key': 'n', 'text': 'name'},
        {'key': 'd', 'text': 'description'},
        {'key': 'l', 'text': 'location'},
        {'key': 'e', 'text': 'examine'},
        {'key': 't', 'text': 'take'},
        {'key': 'ic', 'text': 'is_container'},
        {'key': 'cv', 'text': 'convo'},
        {'key': ':q', 'text': 'quit'},
    ]

    cmd = ['']
    while cmd[0] != ':q':
        print(yaml.dump(char_obj))
        cmd = txt.promptInput('Character Editor', inputOptions)

        if cmd[0] == 'n':
            if len(cmd) > 1:
                name = ' '.join(cmd[1:])
            else:
                name = util.chooseUniqueName('characters', game, level)
            char_obj['name'] = name

        elif cmd[0] == 'd':
            if len(cmd) > 1:
                description = ' '.join(cmd[1:])
            else:
                description = txt.getStr('Description')
            char_obj['description'] = description

        elif cmd[0] == 'e':
            if len(cmd) > 1:
                examine = ' '.join(cmd[1:])
            else:
                examine = txt.getStr('Examine')
            char_obj['examine'] = examine

        elif cmd[0] == 'l':
            char_obj['start_location'] = util.chooseStartingLocation(game, level)

        elif cmd[0] == 't':
            is_takeable = txt.getYesNo("Is takeable?\n> ")
            if is_takeable:
                take_suggestion = char_obj.get('take_text', '')
                drop_suggestion = char_obj.get('drop_text', '')
                char_obj['take_text'] = txt.getStr("Take Text", take_suggestion)
                char_obj['drop_text'] = txt.getStr("Drop Text", drop_suggestion)
            elif not is_takeable:
                char_obj['take_text'] = None
                char_obj['drop_text'] = None
            char_obj['takeable'] = is_takeable

        elif cmd[0] == 'ic':
            char_obj['container'] = txt.getYesNo("Is Container?\n> ")

        elif cmd[0] == 'cv':
            convo.editor(game, level, char_obj['name'], char_obj['dialogue'])

    util.saveGameObj('characters', game, level, char_obj['name'], char_obj)
Exemple #9
0
                'text': 'change level'
            },
            {
                'key': 'el',
                'text': 'edit level'
            },
            {
                'key': 'me',
                'text': 'edit meta data'
            },
            {
                'key': ':q',
                'text': 'quit'
            },
        ]
        r_cmd = txt.promptInput('Game Editor', inputOptions)
    else:
        initializing = False
        r_cmd = ['el']

    if r_cmd[0] == 'cg':
        game = util.chooseGame()
        level = util.chooseLevel(game)
    elif r_cmd[0] == 'cl':
        level = util.chooseLevel(game)
    elif r_cmd[0] == 'me':
        game_meta.edit(game)
    elif r_cmd[0] == 'el':
        location_name = None

        cmd = ['']
Exemple #10
0
def conversationTreeEditor(conversation, character_name, cur_msg):
    cur_opt = conversation[cur_msg]['next']
    cont = True
    while cont:
        output = txt.formatHtmlBlock(describe.conversationMessage(
                character_name,
                conversation[cur_msg]['txt'],
                conversation[cur_opt]['opt']
            ))
        for block in output:
            print(block.replace('<br>', '\n'))

        inputOptions = [
            {'key': 's', 'text':'select'},
            {'key': 'b', 'text':'back'},
            {'key': 'e', 'text':'Edit'},
            {'key': 'a', 'text':'Add Option'},
            {'key': 'rm','text':'Remove Option'},
            {'key': 'w', 'text':'write-to-file'},
            {'key': ':q','text':'quit'},
        ]
        cmd = txt.promptInput(' ', inputOptions)
        print(cmd)

        if cmd[0] == 's':
            if conversation[cur_opt]['opt'][int(cmd[1])].get('next', None) not in conversation:
                [msg, rsp] = makeMessagePair(cur_opt)
                conversation[cur_opt]['opt'][int(cmd[1])]['next'] = msg['uid']

                cur_msg = msg['uid']
                cur_opt = rsp['uid']

                conversation[cur_msg] = msg
                conversation[cur_opt] = rsp
            else:
                cur_msg = conversation[cur_opt]['opt'][int(cmd[1])]['next']
                cur_opt = conversation[cur_msg]['next']

        elif cmd[0] == 'b':
            if conversation[cur_msg]['parent'] is not None:
                cur_opt = conversation[cur_msg]['parent']
                cur_msg = conversation[cur_opt]['parent']

        elif cmd[0] == 'e':
            if len(cmd) == 1:
                print(conversation[cur_msg]['txt'])
                new_response = txt.getStr("Response", prompt_end=":")
                conversation[cur_msg]['txt'] = new_response

            else:
                print(conversation[cur_opt]['opt'][int(cmd[1])]['txt'])
                new_response = txt.getStr("Response", prompt_end = ":")
                conversation[cur_opt]['opt'][int(cmd[1])]['txt'] = new_response

        elif cmd[0] == 'a':
            if len(cmd) == 1:
                new_response = txt.getStr("Response", prompt_end = ":")
            else:
                new_response = " ".join(cmd[1:])
            conversation[cur_opt]['opt'].append({
                'txt':new_response,
                'next':None,
            })

        elif cmd[0] == 'rm':
            del conversation[cur_opt]['opt'][cmd[1]]

        elif cmd[0] == ':q':
            return conversation