can now load a character from a cookie
This commit is contained in:
21
app.py
21
app.py
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
import zlib
|
||||
from main import *
|
||||
from adventurers import *
|
||||
from flask import Flask, render_template, redirect, request, make_response
|
||||
from flask_session import Session
|
||||
|
||||
@@ -37,6 +38,20 @@ def party():
|
||||
@app.route('/character', methods = ["GET","POST"])
|
||||
def characters():
|
||||
if request.method == "GET":
|
||||
c_id = request.args.get("id", default=0, type=int)
|
||||
character = returnCharacter(c_id)
|
||||
return render_template("character.html", character=character)
|
||||
c_id = str(request.args.get("id", default=0, type=int))
|
||||
cookie_encoded = request.cookies[c_id]
|
||||
cookie_compressed = base64.urlsafe_b64decode(cookie_encoded)
|
||||
character_dict = json.loads(zlib.decompress(cookie_compressed).decode())
|
||||
chosen_class = character_dict['player_class']
|
||||
c_id = character_dict['id']
|
||||
level = character_dict['level']
|
||||
adv_dict = Adventurer.get_subclass_dict()
|
||||
chosen_class = adv_dict[chosen_class]
|
||||
# note, i wonder if i can find a way to use the dict in a one liner, like from hw1
|
||||
# makes a new character of the correct player class
|
||||
new_char = chosen_class(c_id=c_id, level=level)
|
||||
# loads in all the values from the dict
|
||||
for k, v in character_dict.items():
|
||||
# https://realpython.com/ref/builtin-functions/setattr/
|
||||
setattr(new_char,k, v)
|
||||
return render_template("character.html", character=new_char)
|
||||
|
||||
Reference in New Issue
Block a user