コード例 #1
0
ファイル: app.py プロジェクト: rrees/crumbly-castle
def move(player_id, new_node_id):
    player = graph.player(player_id)

    if int(new_node_id) in [rel.end.id for rel in player.location.relationships.outgoing(["Route"])]:
        graph.unlink(player, "Location")
        graph.link(player, graph.node_by_id(new_node_id), "Location")

    return redirect("/player/" + player_id)
コード例 #2
0
ファイル: app.py プロジェクト: rrees/crumbly-castle
def setup():
    for location_name, location_data in data.locations:
        graph.create_unique_node("locations", "location", location_name, location_data)

    for start, finish, description in data.routes:
        graph.link(graph.location(start), graph.location(finish), "Route", {"description": description})

    return redirect("/")
コード例 #3
0
ファイル: app.py プロジェクト: rrees/crumbly-castle
def new_player():
    form = forms.NewPlayer(request.form)
    if form.validate():
        player_id = uuid.uuid4().hex

        player_data = {"id": player_id}
        player_data.update(form.data)

        player = graph.create_unique_node("characters", "character", player_id, player_data)

        graph.link(player, graph.random_location(), "Location")
        return redirect("/player/" + player_id)

    return render_template("index.html", form=form)
コード例 #4
0
ファイル: app.py プロジェクト: rrees/flow-web-demo-heroku
def journey(journey_id):
    journey = graph.journey(journey_id)

    if not journey.current_question:
        attributes = graph.all_linked_nodes(journey, "Attribute")
        return render_template("journey/conclusion.html", journey=journey, attributes=attributes)

    if request.method == "POST":
        answer = request.form["answer"]
        answer_node = first([a for a in journey.current_question.answers if a["id"] == answer])
        reward_nodes = graph.all_linked_nodes(answer_node, "Reward")
        next_question_node = graph.first_linked_node(answer_node, "Next")

        for reward_node in reward_nodes:
            graph.link(journey, reward_node, "Attribute")

        graph.unlink(journey, "Current")

        if next_question_node:
            graph.link(journey, next_question_node, "Current")

        return redirect("/journey/" + journey_id)

    return render_template("journey/question.html", journey=journey)
コード例 #5
0
    "flow",
    "start",
    flow_id,
    {"title": "After the Apocalypse", "description": "Post-apocalypse character generation in a Fallout vein"},
)

questions = [
    ("q1", "When the bombs started falling where were your parents?"),
    ("s1", "Which section did your parents work in?"),
    ("w1", "Were they affected by the radiation from the fallout?"),
]

for q_id, question in questions:

    graph.create_unique_node("questions", flow_id, q_id, {"id": q_id, "text": question})
    graph.link(flow_node, graph.node("questions", flow_id, q_id), "Question")

answers = [
    ("q1a1", "They had a place in the shelters"),
    ("q1a2", "They had nowhere to run"),
    ("s1a1", "Administration"),
    ("s1a2", "Security"),
    ("s1a3", "Science"),
    ("w1a1", "I don't know whether they were tough or lucky but no"),
    ("w1a2", "Why do you think I look this way?"),
]

for a_id, answer in answers:
    graph.create_unique_node("answers", flow_id, a_id, {"id": a_id, "text": answer})

rewards = [