Exemplo n.º 1
0
def creation_wizard(character_id=None, name=None, phase=None):
    character = get_character(character_id or name)
    if character is None:
        flash('character' + (name or str(character_id)) + ' does not exist')
        return redirect(url_for('campaign.view'))
    if not phase:
        phase = character.creation_phase
    if not phase:
        phase = creation_phases[0]
    if phase not in creation_phases:
        flash('phase "' + phase + '" is not a valid phase')
        return redirect(url_for('campaign.view'))

    require_scripts('character', 'characters', 'updates', 'binds', 'wizard',
                    'character_creation_wizard')
    require_styles('wizard')
    g.bundle['characters'] = [character]
    g.bundle['wizard_current_phase'] = phase
    g.bundle['wizard_phases'] = creation_phases
    g.bundle['fetch_updates_url'] = character.fetch_updates_url
    g.bundle['stream_updates_url'] = character.stream_updates_url

    done_url = character.view_url
    return render_template('wizard/wizard.html',
                           current_phase=phase,
                           phases=creation_phases,
                           done_url=done_url,
                           character=character)
Exemplo n.º 2
0
def view(character_id=None, name=None):
    character = get_character(character_id or name)
    if character:
        if character.creation_phase != 'done':
            return redirect(character.creation_wizard_url)

        g.bundle['races'] = list_races()
        g.bundle['skills'] = list_skills()
        g.bundle['abilities'] = list_abilities()
        g.bundle['characters'] = [character]
        g.bundle['fetch_updates_url'] = character.fetch_updates_url
        g.bundle['stream_updates_url'] = character.stream_updates_url
        g.bundle['fetch_item_url'] = url_for('ItemType.get')

        require_scripts('chat', 'character', 'characters', 'binds', 'ItemType',
                        'updates', 'tabs', 'view_character')
        require_styles('character', 'tabs')

        response = make_response(
            render_template('view_character.html', character=character))
        response.set_cookie('character', str(character.id))
        return response
    else:
        flash("Character not found: " + (name or str(character_id)))
        return redirect('/')
Exemplo n.º 3
0
def update(character_id=None, name=None):
    character = get_character(character_id or name)
    if character is None:
        raise ValueError('Could not find character: ' + str((character_id, name)))
    json_data = request.get_json()
    for key in json_data:
        key = str(key)
        if key in update_handlers.keys():
            update_handlers.get(key)(character, json_data[key])
        else:
            raise Exception('Invalid attribute: ' + key)
    return {'updates': updates.get_updates(character.id)}
Exemplo n.º 4
0
def character_id_to_messages(character_id):
    """
    Get the MessagesComponent for a character or return the DM's messenger if the character is 0.
    :param character_id:
    :rtype: MessagesComponent
    """
    if character_id == DM_ID:
        return get_dm_messages()
    else:
        character = get_character(character_id)
        if character is None:
            raise Exception('character with id', character_id, 'does not exist')
        return character.messages
Exemplo n.º 5
0
def update(character_id=None, name=None):
    character = get_character(character_id or name)
    if character is None:
        raise ValueError('Could not find character: ' +
                         str((character_id, name)))
    json_data = request.get_json()
    for key in json_data:
        key = str(key)
        if key in update_handlers.keys():
            update_handlers.get(key)(character, json_data[key])
        else:
            raise Exception('Invalid attribute: ' + key)
    return {'updates': updates.get_updates(character.id)}
Exemplo n.º 6
0
def character_id_to_messages(character_id):
    """
    Get the MessagesComponent for a character or return the DM's messenger if the character is 0.
    :param character_id:
    :rtype: MessagesComponent
    """
    if character_id == DM_ID:
        return get_dm_messages()
    else:
        character = get_character(character_id)
        if character is None:
            raise Exception('character with id', character_id,
                            'does not exist')
        return character.messages
Exemplo n.º 7
0
def view(character_id=None, name=None):
    character = get_character(character_id or name)
    if character:
        if character.creation_phase != 'done':
            return redirect(character.creation_wizard_url)

        g.bundle['races'] = list_races()
        g.bundle['skills'] = list_skills()
        g.bundle['abilities'] = list_abilities()
        g.bundle['characters'] = [character]
        g.bundle['fetch_updates_url'] = character.fetch_updates_url
        g.bundle['stream_updates_url'] = character.stream_updates_url
        g.bundle['fetch_item_url'] = url_for('ItemType.get')

        require_scripts('chat', 'character', 'characters', 'binds', 'ItemType', 'updates', 'tabs', 'view_character')
        require_styles('character', 'tabs')

        response = make_response(render_template('view_character.html', character=character))
        response.set_cookie('character', str(character.id))
        return response
    else:
        flash("Character not found: " + (name or str(character_id)))
        return redirect('/')
Exemplo n.º 8
0
def creation_wizard(character_id=None, name=None, phase=None):
    character = get_character(character_id or name)
    if character is None:
        flash('character' + (name or str(character_id)) + ' does not exist')
        return redirect(url_for('campaign.view'))
    if not phase:
        phase = character.creation_phase
    if not phase:
        phase = creation_phases[0]
    if phase not in creation_phases:
        flash('phase "' + phase + '" is not a valid phase')
        return redirect(url_for('campaign.view'))

    require_scripts('character', 'characters', 'updates', 'binds', 'wizard', 'character_creation_wizard')
    require_styles('wizard')
    g.bundle['characters'] = [character]
    g.bundle['wizard_current_phase'] = phase
    g.bundle['wizard_phases'] = creation_phases
    g.bundle['fetch_updates_url'] = character.fetch_updates_url
    g.bundle['stream_updates_url'] = character.stream_updates_url

    done_url = character.view_url
    return render_template('wizard/wizard.html', current_phase=phase, phases=creation_phases,
                           done_url=done_url, character=character)
Exemplo n.º 9
0
def stream_updates(character_id=None, name=None):
    if character_id is None:
        character_id = get_character(name).id
    return Response(updates.update_stream(character_id),
                    mimetype="text/event-stream")
Exemplo n.º 10
0
def fetch_updates(character_id=None, name=None):
    if character_id is None:
        character_id = get_character(name).id
    return {'updates': updates.get_updates(character_id)}
Exemplo n.º 11
0
def stream_updates(character_id=None, name=None):
    if character_id is None:
        character_id = get_character(name).id
    return Response(updates.update_stream(character_id), mimetype="text/event-stream")
Exemplo n.º 12
0
def fetch_updates(character_id=None, name=None):
    if character_id is None:
        character_id = get_character(name).id
    return {'updates': updates.get_updates(character_id)}