コード例 #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)
コード例 #2
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,
    }
コード例 #3
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
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)