~blowry/pokegen

d21805c5cc6eae6a840180ac82f5636de3d0db6a — Benjamin Lowry 5 months ago a85a084
Add checkbox for toggling ubers
M app.py => app.py +6 -2
@@ 17,10 17,14 @@ def index():
@app.route("/", methods=["POST"])
def index_post():
    if request.form["action"] == "generate":
        if "ubers" in request.form.keys():
            tiers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        else:
            tiers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        if request.form["score"] != "":
            team = make_team(pokedex, point_total=int(request.form["score"]))
            team = make_team(pokedex, point_total=int(request.form["score"]), allowed_tiers=tiers)
        else:
            team = make_team(pokedex)
            team = make_team(pokedex, allowed_tiers=tiers)
        uuid = str(uuid4())
        r.set(uuid, dumps(team), ex=3600) # 1 hour should be enough, right?
        return render_template("generated_team.html", team=team, teamscore=get_team_score(team), uuid=uuid)

M team.py => team.py +3 -3
@@ 1,10 1,10 @@
def make_team(dex, point_total=None, require_tier=None):
def make_team(dex, point_total=None, require_tier=None, allowed_tiers=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]):
    team = []
    if point_total:
        while get_team_score(team) != point_total: # TODO: do this more efficiently
            team = []
            while len(team) != 6:
                mon = dex.get_random_pokemon()
                mon = dex.get_random_pokemon(allowed_tiers)
                if mon not in team:
                    team.append(mon)
    else:


@@ 12,7 12,7 @@ def make_team(dex, point_total=None, require_tier=None):
            if require_tier:
                mon = dex.get_random_pokemon(allowed_tiers=[require_tier])
            else:
                mon = dex.get_random_pokemon()
                mon = dex.get_random_pokemon(allowed_tiers)
            if mon not in team:
                team.append(mon)
    return team

M templates/finalized_team.html => templates/finalized_team.html +4 -2
@@ 21,7 21,9 @@
</form>
<form method="post">
    <input type="hidden" name="action" value="generate" />
    <input type="hidden" name="score" value="{{ teamscore }}" />
    <button>This one sucks, generate another!</button>
    <button>This one sucks, generate another!</button><br/>
    Team total score: <input type="number" name="score" value="{{ teamscore }}" /><br/>
    Use this to change how powerful the generated team will be. Leave blank for random.<br/>
    {% include "gensettings.html" %}
</form>
{% endblock %}

M templates/generated_team.html => templates/generated_team.html +4 -2
@@ 28,7 28,9 @@
</form>
<form method="post">
    <input type="hidden" name="action" value="generate" />
    <input type="hidden" name="score" value="{{ teamscore }}" />
    <button>This one sucks, generate another!</button>
    <button>This one sucks, generate another!</button><br/>
    Team total score: <input type="number" name="score" value="{{ teamscore }}" /><br/>
    Use this to change how powerful the generated team will be. Leave blank for random.<br/>
    {% include "gensettings.html" %}
</form>
{% endblock %}

A templates/gensettings.html => templates/gensettings.html +1 -0
@@ 0,0 1,1 @@
    <input type="checkbox" name="ubers" /> Allow ubers

M templates/index.html => templates/index.html +2 -1
@@ 12,6 12,7 @@
    <button>Generate</button>
    <br/>
    Team total score: <input type="number" name="score" value="" /><br/>
    Use this to change how powerful the generated team will be. Leave blank for random.
    Use this to change how powerful the generated team will be. Leave blank for random.<br/>
    {% include "gensettings.html" %}
</form>
{% endblock %}

M templates/shared_team.html => templates/shared_team.html +10 -6
@@ 2,12 2,8 @@
{% block title %}Shared Team - pokegen{% endblock %}
{% block content %}
<div>
    This team was generated and shared using pokegen, a random Pokémon team generator. Wanna try
    <form action="./" method="post">
        <input type="hidden" name="action" value="generate" />
        <input type="hidden" name="score" value="{{ teamscore }}" />
        <button>making your own?</button>
    </form>
    This team was generated and shared using pokegen, a random Pokémon team
    generator. Scroll down if you wanna try making your own!
</div>
<ul>
    {% for pokemon in team %}


@@ 19,4 15,12 @@
<div>
    Team score: {{ teamscore }}
</div>
<form action="./" method="post">
    <input type="hidden" name="action" value="generate" />
    <button>Generate</button>
    <br/>
    Team total score: <input type="number" name="score" value="{{ teamscore }}" /><br/>
    Use this to change how powerful the generated team will be. Leave blank for random.<br/>
    {% include "gensettings.html" %}
</form>
{% endblock %}