Esempio n. 1
0
def createNew(game, level, location=None):
    item_name = util.chooseUniqueName('items', game, level)
    if location is None:
        start_location = util.chooseStartingLocation(game, level)
    else:
        start_location = util.getReference('locations', level, location)
    description = txt.getStr("Description", prompt_end=":")
    examine_text = txt.getStr("Examine Text", prompt_end=":")
    is_container = txt.getYesNo("Is a container?\n> ")
    is_takeable = txt.getYesNo("Is takeable?\n> ")
    if is_takeable:
        take_text = txt.getStr("Take Text", prompt_end=":")
        drop_text = txt.getStr("Drop Text", prompt_end=":")
    else:
        take_text = None
        drop_text = None

    item_obj = {
        'name': item_name,
        'description': description,
        'start_location': start_location + '.name',
        'examine_text': examine_text,
        'takeable': is_takeable,
        'take_text': take_text,
        'drop_text': drop_text,
        'is_container': is_container
    }

    util.saveItem('items', game, level, location, item_name, item_obj)
Esempio n. 2
0
def chooseUniqueName(obj_type, game, level):
    existing_objs = getGameObjects(obj_type, game, level)
    existing_names = [obj.replace('_', ' ').lower() for obj in existing_objs]
    item_uniq_name = txt.getStr("Unique Name")
    while item_uniq_name.lower().replace('_', ' ') in existing_names:
        item_uniq_name = txt.getStr(f"{item_uniq_name} is already taken. Please choose another\nUnique Name")
    return item_uniq_name
Esempio n. 3
0
def createNewBlocker(game):
    state = txt.getStr('Block State')
    value = txt.getStr('Block State Value')
    failure_text = txt.getStr('Failure Text')
    success_text = txt.getStr('Success Text')
    travel_blockade = {
        'state': state,
        'value': value,
        'failure': failure_text,
        'success': success_text,
    }
    return travel_blockade
Esempio n. 4
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
Esempio n. 5
0
def createNew(game, level):
    location_name = util.chooseUniqueName('locations', game, level)
    description = txt.getStr("Description", prompt_end=":")
    examine_text = txt.getStr("Examine Text", prompt_end=":")

    location_obj = {
        'name': location_name,
        'description': description,
        'examine_text': examine_text,
        'connections': [],
    }

    util.saveGameObj('locations', game, level, location_name, location_obj)
    return location_name.lower().replace(' ', '_')
Esempio n. 6
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(' ', '_')
Esempio n. 7
0
def chooseAnyLocation(game, allow_new_location = False):
    level = chooseLevel(game)
    prompt = "Choose Location"
    locations = getLocations(game, level)
    if allow_new_location:
        options = locations + ["New Location"]
    choice = txt.getOption(prompt, options)
    location = options[choice]
    if location == 'New Location':
        location = txt.getStr('Location Name (New)')
    return getReference('locations', level, location)
Esempio n. 8
0
def makeNewNpcMessage(parent):
    npc_uid = str(uuid.uuid4())
    npc_message_str = txt.getStr("NPC_Response")
    npc_message = {
        'uid':  npc_uid,
        'type': 'npc',
        'txt':  npc_message_str,
        'next': None,
        'parent': parent,
    }
    return npc_message
Esempio n. 9
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,
    }
Esempio n. 10
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
Esempio n. 11
0
def getLocationRef(game, location_level, location_name):
    if txt.getYesNo("Connecting to same level? (y/n)"):
        level = location_level
    else:
        level = util.chooseLevel(game)
    location = util.chooseLocation(
        game,
        level,
        allow_new_location=True,
        exclude=[location_name.lower().replace(' ', '_')])
    if location == 'New Location':
        location = txt.getStr('Location Name (new)')
    location_ref = util.getReference('locations', level, location)
    return location_ref
Esempio n. 12
0
def createNew(game, level, location=None):
    char_name = util.chooseUniqueName('characters', game, level)

    if location is None:
        start_location = util.chooseStartingLocation(game, level)
    else:
        start_location = util.getReference('locations', level, location)
    description = txt.getStr("Description", prompt_end = ":")
    examine_text = txt.getStr("Examine Text", prompt_end = ":")
    is_container = txt.getYesNo("Is a container? (y/n)\n> ")
    is_takeable = txt.getYesNo("Is takeable? (y/n)\n> ")

    if is_takeable:
        take_text = txt.getStr("Take Text", prompt_end = ":")
        drop_text = txt.getStr("Drop Text", prompt_end = ":")
    else:
        take_text = None
        drop_text = None

    char_obj = {
        'name': char_name,
        'description': description,
        'start_location': start_location+'.name',
        'examine_text': examine_text,
        'takeable': is_takeable,
        'take_text': take_text,
        'drop_text': drop_text,
        'is_container': is_container,
        'dialogue': [],
    }

    if txt.getYesNo("Add conversation? (y/n)\n> "):
        char_obj['dialogue'].append(
            convo.createNew(game, level, char_name, location)
        )

    util.saveGameObj('characters', game, level, char_name, char_obj)
Esempio n. 13
0
def makeLevel(game):
    level = txt.getStr("Name of the Level?")
    level_root = getLevelRoot(game, level.replace(' ', '_'))
    if not os.path.exists(level_root):
        os.mkdir(level_root)
    game_dirs = [
        getObjRoot('conversations', game, level),
        getObjRoot('items', game, level),
        getObjRoot('locations', game, level),
        getObjRoot('characters', game, level)
    ]
    for directory in game_dirs:
        if not os.path.exists(directory):
            os.mkdir(directory)
    return level
Esempio n. 14
0
def makeGame():
    game_name = txt.getStr("Name of the Game?")
    game_root = getGameRoot(game_name.replace(' ', '_'))
    if not os.path.exists(game_root):
        os.mkdir(game_root)
    return game_name
Esempio n. 15
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
Esempio n. 16
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)
Esempio n. 17
0
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)