refactored according to flake8 and pylint linting
This commit is contained in:
parent
f3d27a7db1
commit
7d049565a7
@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import truthseeker.logic.data_persistance.tables as tables
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy import engine as eg
|
from sqlalchemy import engine as eg
|
||||||
import random
|
|
||||||
import truthseeker.logic.data_persistance.tables as tables
|
|
||||||
|
|
||||||
url_object = eg.URL.create(
|
url_object = eg.URL.create(
|
||||||
"mariadb+pymysql",
|
"mariadb+pymysql",
|
||||||
@ -17,6 +17,7 @@ url_object = eg.URL.create(
|
|||||||
engine = create_engine(url_object)
|
engine = create_engine(url_object)
|
||||||
session = Session(engine)
|
session = Session(engine)
|
||||||
|
|
||||||
|
|
||||||
def get_text_from_lid(lang, lid) -> str:
|
def get_text_from_lid(lang, lid) -> str:
|
||||||
return session.query(tables.Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT
|
return session.query(tables.Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT
|
||||||
|
|
||||||
@ -31,12 +32,12 @@ def get_npc_random_trait_id(npc) -> int:
|
|||||||
reaction = random.choice(reactions)
|
reaction = random.choice(reactions)
|
||||||
return reaction.TRAIT_ID
|
return reaction.TRAIT_ID
|
||||||
|
|
||||||
def get_npc_random_answer(npc, QA_TYPE) -> tables.Answer :
|
def get_npc_random_answer(npc, qa_type) -> tables.Answer :
|
||||||
answers = session.query(tables.Answer).filter_by(QA_TYPE=QA_TYPE,NPC_ID=npc.NPC_ID).all()
|
answers = session.query(tables.Answer).filter_by(QA_TYPE=qa_type,NPC_ID=npc.NPC_ID).all()
|
||||||
return random.choice(answers)
|
return random.choice(answers)
|
||||||
|
|
||||||
def get_random_question(QA_TYPE) -> tables.Answer :
|
def get_random_question(qa_type) -> tables.Answer :
|
||||||
answers = session.query(tables.Question).filter_by(QUESTION_TYPE=QA_TYPE).all()
|
answers = session.query(tables.Question).filter_by(QUESTION_TYPE=qa_type).all()
|
||||||
return random.choice(answers)
|
return random.choice(answers)
|
||||||
|
|
||||||
def get_trait_from_text(text):
|
def get_trait_from_text(text):
|
||||||
|
@ -35,42 +35,36 @@ with Session(engine) as session:
|
|||||||
session.add(locale)
|
session.add(locale)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding places")
|
print("adding places")
|
||||||
for place in PLACES:
|
for place in PLACES:
|
||||||
print(place)
|
print(place)
|
||||||
session.add(place)
|
session.add(place)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding NPCS")
|
print("adding NPCS")
|
||||||
for npc in NPCS:
|
for npc in NPCS:
|
||||||
print(npc)
|
print(npc)
|
||||||
session.add(npc)
|
session.add(npc)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding trait")
|
print("adding trait")
|
||||||
for trait in TRAITS:
|
for trait in TRAITS:
|
||||||
print(trait)
|
print(trait)
|
||||||
session.add(trait)
|
session.add(trait)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding questions")
|
print("adding questions")
|
||||||
for question in QUESTIONS:
|
for question in QUESTIONS:
|
||||||
print(question)
|
print(question)
|
||||||
session.add(question)
|
session.add(question)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding answers")
|
print("adding answers")
|
||||||
for answer in ANSWERS:
|
for answer in ANSWERS:
|
||||||
print(answer)
|
print(answer)
|
||||||
session.add(answer)
|
session.add(answer)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
print("adding reactions")
|
print("adding reactions")
|
||||||
for reaction in REACTIONS:
|
for reaction in REACTIONS:
|
||||||
print(reaction)
|
print(reaction)
|
||||||
|
@ -4,6 +4,7 @@ from sqlalchemy.orm import declarative_base, relationship
|
|||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class Locale(Base):
|
class Locale(Base):
|
||||||
__tablename__ = 'T_LOCALE'
|
__tablename__ = 'T_LOCALE'
|
||||||
TEXT_ID = Column(Integer, primary_key=True)
|
TEXT_ID = Column(Integer, primary_key=True)
|
||||||
@ -18,6 +19,7 @@ class Locale(Base):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.TEXT_ID} {self.LANG} {self.TEXT}"
|
return f"{self.TEXT_ID} {self.LANG} {self.TEXT}"
|
||||||
|
|
||||||
|
|
||||||
class Place(Base):
|
class Place(Base):
|
||||||
__tablename__ = 'T_PLACE'
|
__tablename__ = 'T_PLACE'
|
||||||
PLACE_ID = Column(Integer, primary_key=True)
|
PLACE_ID = Column(Integer, primary_key=True)
|
||||||
@ -31,6 +33,7 @@ class Place(Base):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.PLACE_ID} {self.NAME_LID}"
|
return f"{self.PLACE_ID} {self.NAME_LID}"
|
||||||
|
|
||||||
|
|
||||||
class Question(Base):
|
class Question(Base):
|
||||||
__tablename__ = "T_QUESTION"
|
__tablename__ = "T_QUESTION"
|
||||||
QUESTION_ID = Column(Integer, primary_key=True)
|
QUESTION_ID = Column(Integer, primary_key=True)
|
||||||
@ -46,6 +49,7 @@ class Question(Base):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.QUESTION_ID} {self.QUESTION_TYPE} {self.TEXT_LID}"
|
return f"{self.QUESTION_ID} {self.QUESTION_TYPE} {self.TEXT_LID}"
|
||||||
|
|
||||||
|
|
||||||
class Answer(Base):
|
class Answer(Base):
|
||||||
__tablename__ = "T_ANSWER"
|
__tablename__ = "T_ANSWER"
|
||||||
ANSWER_ID = Column(Integer, primary_key=True)
|
ANSWER_ID = Column(Integer, primary_key=True)
|
||||||
@ -64,6 +68,7 @@ class Answer(Base):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.ANSWER_ID} {self.QA_TYPE} {self.NPC_ID} {self.TEXT_LID}"
|
return f"{self.ANSWER_ID} {self.QA_TYPE} {self.NPC_ID} {self.TEXT_LID}"
|
||||||
|
|
||||||
|
|
||||||
class Npc(Base):
|
class Npc(Base):
|
||||||
__tablename__ = "T_NPC"
|
__tablename__ = "T_NPC"
|
||||||
NPC_ID = Column(Integer, primary_key=True)
|
NPC_ID = Column(Integer, primary_key=True)
|
||||||
@ -76,6 +81,7 @@ class Npc(Base):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.NPC_ID} {self.NAME_LID}"
|
return f"{self.NPC_ID} {self.NAME_LID}"
|
||||||
|
|
||||||
|
|
||||||
class Trait(Base):
|
class Trait(Base):
|
||||||
__tablename__ = "T_TRAIT"
|
__tablename__ = "T_TRAIT"
|
||||||
TRAIT_ID = Column(Integer, primary_key=True)
|
TRAIT_ID = Column(Integer, primary_key=True)
|
||||||
@ -88,6 +94,7 @@ class Trait(Base):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.TRAIT_ID} {self.NAME_LID}"
|
return f"{self.TRAIT_ID} {self.NAME_LID}"
|
||||||
|
|
||||||
|
|
||||||
class Reaction(Base):
|
class Reaction(Base):
|
||||||
__tablename__ = "T_REACTION"
|
__tablename__ = "T_REACTION"
|
||||||
REACTION_ID = Column(Integer, primary_key=True)
|
REACTION_ID = Column(Integer, primary_key=True)
|
||||||
|
@ -5,6 +5,7 @@ from typing import Union
|
|||||||
from truthseeker.logic.data_persistance.data_access import *
|
from truthseeker.logic.data_persistance.data_access import *
|
||||||
from truthseeker import APP
|
from truthseeker import APP
|
||||||
|
|
||||||
|
|
||||||
def random_string(length: int) -> str:
|
def random_string(length: int) -> str:
|
||||||
"""
|
"""
|
||||||
This function create a random string as long as the lint passed as
|
This function create a random string as long as the lint passed as
|
||||||
@ -15,6 +16,7 @@ def random_string(length: int) ->str:
|
|||||||
"""
|
"""
|
||||||
return "".join(random.choice(string.ascii_letters) for _ in range(length))
|
return "".join(random.choice(string.ascii_letters) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
class Member:
|
class Member:
|
||||||
"""
|
"""
|
||||||
stores information related to the member of a given game
|
stores information related to the member of a given game
|
||||||
@ -30,11 +32,12 @@ class Member:
|
|||||||
self.results = None
|
self.results = None
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "Member[username={}]".format(self.username)
|
return f"Member[username={self.username}]"
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
"""
|
"""
|
||||||
The game info class stores all information linked to a active game
|
The game info class stores all information linked to a active game
|
||||||
@ -75,8 +78,8 @@ class Game:
|
|||||||
for npc_id in self.gamedata["npcs"]:
|
for npc_id in self.gamedata["npcs"]:
|
||||||
npcs[npc_id] = {}
|
npcs[npc_id] = {}
|
||||||
npcs[npc_id]["name"] = self.gamedata["npcs"][npc_id]["name"]
|
npcs[npc_id]["name"] = self.gamedata["npcs"][npc_id]["name"]
|
||||||
traitId = self.reaction_table[npc_id]
|
trait_id = self.reaction_table[npc_id]
|
||||||
trait = get_trait_from_trait_id(traitId)
|
trait = get_trait_from_trait_id(trait_id)
|
||||||
npcs[npc_id]["reaction"] = get_text_from_lid("FR", trait.NAME_LID)
|
npcs[npc_id]["reaction"] = get_text_from_lid("FR", trait.NAME_LID)
|
||||||
npcs[npc_id]["description"] = get_reaction_description("FR", npc_id, trait.TRAIT_ID)
|
npcs[npc_id]["description"] = get_reaction_description("FR", npc_id, trait.TRAIT_ID)
|
||||||
player_results = data["player"] = {}
|
player_results = data["player"] = {}
|
||||||
@ -120,7 +123,7 @@ class Game:
|
|||||||
"""
|
"""
|
||||||
TODO + TODO TYPES
|
TODO + TODO TYPES
|
||||||
"""
|
"""
|
||||||
if npc_id not in self.reaction_table.keys():
|
if npc_id not in self.reaction_table:
|
||||||
return 0
|
return 0
|
||||||
reaction_id = self.reaction_table[npc_id]
|
reaction_id = self.reaction_table[npc_id]
|
||||||
return read_image(f"./truthseeker/static/images/npc/{npc_id}/{reaction_id}.png")
|
return read_image(f"./truthseeker/static/images/npc/{npc_id}/{reaction_id}.png")
|
||||||
@ -138,7 +141,6 @@ class Game:
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def has_finished(self) -> bool:
|
def has_finished(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Checks if the game has finished by checking if every Member has submitted answers
|
Checks if the game has finished by checking if every Member has submitted answers
|
||||||
@ -146,15 +148,17 @@ class Game:
|
|||||||
:return: True if the game has finished, else False
|
:return: True if the game has finished, else False
|
||||||
"""
|
"""
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
if member.results == None : return False
|
if member.results is None:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "Game[game_id={}, owner={}, members={}]".format(self.game_id, self.owner, self.members)
|
return f"Game[game_id={self.game_id}, owner={self.owner}, members={self.members}]"
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
|
|
||||||
def create_game(owner: str) -> Game:
|
def create_game(owner: str) -> Game:
|
||||||
"""
|
"""
|
||||||
This function creates a new game by creating a Game object and stores
|
This function creates a new game by creating a Game object and stores
|
||||||
@ -169,6 +173,7 @@ def create_game(owner: str) -> Game:
|
|||||||
APP.games_list[game.game_id] = game
|
APP.games_list[game.game_id] = game
|
||||||
return game
|
return game
|
||||||
|
|
||||||
|
|
||||||
def get_game(game_id: str) -> Union[Game, None]:
|
def get_game(game_id: str) -> Union[Game, None]:
|
||||||
"""
|
"""
|
||||||
Get a game from its ID
|
Get a game from its ID
|
||||||
@ -181,6 +186,7 @@ def get_game(game_id: str) -> Union[Game, None]:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def check_username(username: str) -> bool:
|
def check_username(username: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if a username is valid using a set of rules
|
Check if a username is valid using a set of rules
|
||||||
@ -200,6 +206,7 @@ def check_username(username: str) -> bool:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def generate_npc_text(npc: tables.Npc, lang: str) -> dict:
|
def generate_npc_text(npc: tables.Npc, lang: str) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
data["name"] = get_text_from_lid(lang, npc.NAME_LID)
|
data["name"] = get_text_from_lid(lang, npc.NAME_LID)
|
||||||
@ -207,9 +214,11 @@ def generate_npc_text(npc: tables.Npc, lang: str) -> dict:
|
|||||||
data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc, 1).TEXT_LID)
|
data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc, 1).TEXT_LID)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def generate_npc_reactions(npc: tables.Npc) -> list:
|
def generate_npc_reactions(npc: tables.Npc) -> list:
|
||||||
return get_npc_random_trait_id(npc)
|
return get_npc_random_trait_id(npc)
|
||||||
|
|
||||||
|
|
||||||
def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
random.shuffle(npcs)
|
random.shuffle(npcs)
|
||||||
@ -219,11 +228,12 @@ def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
|||||||
placedata["npcs"] = []
|
placedata["npcs"] = []
|
||||||
for _ in npcs:
|
for _ in npcs:
|
||||||
placedata["npcs"].append(npcs.pop().NPC_ID)
|
placedata["npcs"].append(npcs.pop().NPC_ID)
|
||||||
if len(placedata["npcs"]) == 2: break
|
if len(placedata["npcs"]) == 2:
|
||||||
|
break
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def generate_game_data(LANG):
|
def generate_game_data(lang):
|
||||||
data = {}
|
data = {}
|
||||||
data["npcs"] = {}
|
data["npcs"] = {}
|
||||||
reactions_table = {}
|
reactions_table = {}
|
||||||
@ -233,7 +243,7 @@ def generate_game_data(LANG):
|
|||||||
if npc not in npcs:
|
if npc not in npcs:
|
||||||
npcs.append(npc)
|
npcs.append(npc)
|
||||||
for npc in npcs:
|
for npc in npcs:
|
||||||
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc,LANG)
|
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc, lang)
|
||||||
reactions_table[str(npc.NPC_ID)] = generate_npc_reactions(npc)
|
reactions_table[str(npc.NPC_ID)] = generate_npc_reactions(npc)
|
||||||
|
|
||||||
places = []
|
places = []
|
||||||
@ -242,22 +252,25 @@ def generate_game_data(LANG):
|
|||||||
if place not in places:
|
if place not in places:
|
||||||
places.append(place)
|
places.append(place)
|
||||||
|
|
||||||
data["rooms"] = generate_place_data(npcs,places,LANG)
|
data["rooms"] = generate_place_data(npcs, places, lang)
|
||||||
data["questions"] = {}
|
data["questions"] = {}
|
||||||
data["questions"]["QA_0"] = get_text_from_lid("FR", get_random_question(0).TEXT_LID)
|
data["questions"]["QA_0"] = get_text_from_lid("FR", get_random_question(0).TEXT_LID)
|
||||||
data["questions"]["QA_1"] = get_text_from_lid("FR", get_random_question(1).TEXT_LID)
|
data["questions"]["QA_1"] = get_text_from_lid("FR", get_random_question(1).TEXT_LID)
|
||||||
data["traits"] = get_traits(LANG)
|
data["traits"] = get_traits(lang)
|
||||||
return data, reactions_table
|
return data, reactions_table
|
||||||
|
|
||||||
def read_image(path:str):
|
|
||||||
|
def read_image(path: str) -> bytes:
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as file:
|
||||||
return f.read()
|
return file.read()
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_trait_id_from_string(trait):
|
|
||||||
|
def get_trait_id_from_string(trait: str) -> int:
|
||||||
return get_trait_from_text(trait)
|
return get_trait_from_text(trait)
|
||||||
|
|
||||||
|
|
||||||
def get_npc_image(npc_id):
|
def get_npc_image(npc_id):
|
||||||
return read_image(f"./truthseeker/static/images/npc/{npc_id}/0.png")
|
return read_image(f"./truthseeker/static/images/npc/{npc_id}/0.png")
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
from truthseeker import APP
|
from truthseeker import APP
|
||||||
@ -11,7 +10,7 @@ routes_api = flask.Blueprint("api", __name__)
|
|||||||
@routes_api.route("/createGame", methods=["GET", "POST"])
|
@routes_api.route("/createGame", methods=["GET", "POST"])
|
||||||
def create_game():
|
def create_game():
|
||||||
username = flask.request.values.get("username")
|
username = flask.request.values.get("username")
|
||||||
if username==None:
|
if username is None:
|
||||||
return {"error": 1, "msg": "username not set"}
|
return {"error": 1, "msg": "username not set"}
|
||||||
if not game_logic.check_username(username):
|
if not game_logic.check_username(username):
|
||||||
return {"error": 1, "msg": "invalid username"}
|
return {"error": 1, "msg": "invalid username"}
|
||||||
@ -30,11 +29,11 @@ def create_game():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
@routes_api.route("/getGameMembers", methods=["GET", "POST"])
|
@routes_api.route("/getGameMembers", methods=["GET", "POST"])
|
||||||
def getMembers():
|
def get_members():
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 1, "msg": "No session"}
|
return {"error": 1, "msg": "No session"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
|
|
||||||
response = {"error" : 0}
|
response = {"error" : 0}
|
||||||
@ -46,13 +45,13 @@ def getMembers():
|
|||||||
def join_game():
|
def join_game():
|
||||||
game_id = flask.request.values.get("game_id")
|
game_id = flask.request.values.get("game_id")
|
||||||
username = flask.request.values.get("username")
|
username = flask.request.values.get("username")
|
||||||
if game_id==None or username==None:
|
if game_id is None or username is None:
|
||||||
return {"error": 1, "msg": "username or game id not set"}
|
return {"error": 1, "msg": "username or game id not set"}
|
||||||
if not game_logic.check_username(username):
|
if not game_logic.check_username(username):
|
||||||
return {"error": 1, "msg": "invalid username"}
|
return {"error": 1, "msg": "invalid username"}
|
||||||
|
|
||||||
game = game_logic.get_game(game_id)
|
game = game_logic.get_game(game_id)
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "game does not exist"}
|
return {"error": 1, "msg": "game does not exist"}
|
||||||
|
|
||||||
if not game.add_member(username):
|
if not game.add_member(username):
|
||||||
@ -71,7 +70,7 @@ def is_owner():
|
|||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 0, "owner": False}
|
return {"error": 0, "owner": False}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 0, "owner": False}
|
return {"error": 0, "owner": False}
|
||||||
|
|
||||||
if not flask.session["is_owner"]:
|
if not flask.session["is_owner"]:
|
||||||
@ -84,7 +83,7 @@ def has_joined():
|
|||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 0, "joined": False}
|
return {"error": 0, "joined": False}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 0, "joined": False}
|
return {"error": 0, "joined": False}
|
||||||
return {"error": 0, "joined": True}
|
return {"error": 0, "joined": True}
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ def start_game():
|
|||||||
if not flask.session["is_owner"]:
|
if not flask.session["is_owner"]:
|
||||||
return {"error": 1, "msg": "you are not the owner of this game"}
|
return {"error": 1, "msg": "you are not the owner of this game"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
if game.has_started:
|
if game.has_started:
|
||||||
return {"error": 1, "msg": "this game is already started"}
|
return {"error": 1, "msg": "this game is already started"}
|
||||||
@ -109,7 +108,7 @@ def get_data():
|
|||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 1, "msg": "No session"}
|
return {"error": 1, "msg": "No session"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
|
|
||||||
response = {}
|
response = {}
|
||||||
@ -118,7 +117,7 @@ def get_data():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
@routes_api.route("/getNpcImage", methods=["GET", "POST"])
|
@routes_api.route("/getNpcImage", methods=["GET", "POST"])
|
||||||
def getNpcImage():
|
def get_npc_image():
|
||||||
npc_id = flask.request.values.get("npcid")
|
npc_id = flask.request.values.get("npcid")
|
||||||
if npc_id is None:
|
if npc_id is None:
|
||||||
return {"error": 1, "msg": "no npc was given"}
|
return {"error": 1, "msg": "no npc was given"}
|
||||||
@ -128,16 +127,16 @@ def getNpcImage():
|
|||||||
response = flask.make_response(image)
|
response = flask.make_response(image)
|
||||||
response.headers.set('Content-Type', 'image/png')
|
response.headers.set('Content-Type', 'image/png')
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
'Content-Disposition', 'attachment', filename=f'0.png')
|
'Content-Disposition', 'attachment', filename='0.png')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@routes_api.route("/getNpcReaction", methods=["GET", "POST"])
|
@routes_api.route("/getNpcReaction", methods=["GET", "POST"])
|
||||||
def getNpcReaction():
|
def get_npc_reaction():
|
||||||
|
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 1, "msg": "No session"}
|
return {"error": 1, "msg": "No session"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
npc_id = flask.request.values.get("npcid")
|
npc_id = flask.request.values.get("npcid")
|
||||||
|
|
||||||
@ -149,16 +148,17 @@ def getNpcReaction():
|
|||||||
response = flask.make_response(image)
|
response = flask.make_response(image)
|
||||||
response.headers.set('Content-Type', 'image/png')
|
response.headers.set('Content-Type', 'image/png')
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
'Content-Disposition', 'attachment', filename=f'reaction.png')
|
'Content-Disposition', 'attachment', filename='reaction.png')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@routes_api.route("/gameProgress", methods=["GET", "POST"])
|
@routes_api.route("/gameProgress", methods=["GET", "POST"])
|
||||||
def gameProgress():
|
def game_progress():
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 1, "msg": "No session"}
|
return {"error": 1, "msg": "No session"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
|
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
|
|
||||||
username = flask.session["username"]
|
username = flask.session["username"]
|
||||||
@ -168,35 +168,35 @@ def gameProgress():
|
|||||||
|
|
||||||
return {"error": 0}
|
return {"error": 0}
|
||||||
|
|
||||||
|
|
||||||
@routes_api.route("/submitAnswers", methods=["GET", "POST"])
|
@routes_api.route("/submitAnswers", methods=["GET", "POST"])
|
||||||
def checkAnwser():
|
def check_anwser():
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
return {"error": 1, "msg": "No session"}
|
return {"error": 1, "msg": "No session"}
|
||||||
game = game_logic.get_game(flask.session["game_id"])
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
|
|
||||||
if game == None:
|
if game is None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
|
|
||||||
member = game.get_member(flask.session["username"])
|
member = game.get_member(flask.session["username"])
|
||||||
|
|
||||||
if member.results != None:
|
if member.results is not None:
|
||||||
return {"error": 1, "msg": "answers already submitted for this member"}
|
return {"error": 1, "msg": "answers already submitted for this member"}
|
||||||
|
|
||||||
playerResponses = flask.request.values.get("responses")
|
player_responses = flask.request.values.get("responses")
|
||||||
|
|
||||||
if playerResponses == None:
|
if player_responses is None:
|
||||||
return {"error": 1, "msg": "no responses were sent"}
|
return {"error": 1, "msg": "no responses were sent"}
|
||||||
|
|
||||||
results = game.get_player_results(json.loads(playerResponses))
|
results = game.get_player_results(json.loads(player_responses))
|
||||||
if results == False:
|
if results is False:
|
||||||
return {"error": 1, "msg": "invalid npc sent"}
|
return {"error": 1, "msg": "invalid npc sent"}
|
||||||
|
|
||||||
member.has_submitted = True
|
member.has_submitted = True
|
||||||
member.results = results
|
member.results = results
|
||||||
if game.has_finished():
|
if game.has_finished():
|
||||||
jsonGameResults = game.generate_game_results()
|
json_game_results = game.generate_game_results()
|
||||||
APP.socketio_app.emit("gamefinshed",jsonGameResults,room="game."+game.game_id)
|
APP.socketio_app.emit("gamefinshed", json_game_results, room="game."+game.game_id)
|
||||||
# TODO desctruct game
|
# TODO desctruct game
|
||||||
response = {"error": 0}
|
response = {"error": 0}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -17,5 +17,3 @@ def connect(auth):
|
|||||||
|
|
||||||
room = join_room("game."+auth["game_id"])
|
room = join_room("game."+auth["game_id"])
|
||||||
join_room(room)
|
join_room(room)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,33 +1,39 @@
|
|||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
|
||||||
routes_ui = flask.Blueprint("ui", __name__)
|
routes_ui = flask.Blueprint("ui", __name__)
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/")
|
@routes_ui.route("/")
|
||||||
def index():
|
def index():
|
||||||
return flask.render_template("index.html")
|
return flask.render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/privacy")
|
@routes_ui.route("/privacy")
|
||||||
def privacy():
|
def privacy():
|
||||||
return flask.render_template("privacy.html")
|
return flask.render_template("privacy.html")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/licenses")
|
@routes_ui.route("/licenses")
|
||||||
def licenses():
|
def licenses():
|
||||||
return flask.render_template("licenses.html")
|
return flask.render_template("licenses.html")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/legal")
|
@routes_ui.route("/legal")
|
||||||
def legal():
|
def legal():
|
||||||
return flask.render_template("legal.html")
|
return flask.render_template("legal.html")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/lobby/<game_id>")
|
@routes_ui.route("/lobby/<game_id>")
|
||||||
def lobby(game_id):
|
def lobby(game_id):
|
||||||
# rendered by the javascript client-side
|
# rendered by the javascript client-side
|
||||||
return flask.render_template("lobby.html", gameid=game_id)
|
return flask.render_template("lobby.html", gameid=game_id)
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/solo")
|
@routes_ui.route("/solo")
|
||||||
def solo():
|
def solo():
|
||||||
return flask.render_template("game.html")
|
return flask.render_template("game.html")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/multi")
|
@routes_ui.route("/multi")
|
||||||
def multi():
|
def multi():
|
||||||
return flask.render_template("game.html")
|
return flask.render_template("game.html")
|
||||||
|
Loading…
Reference in New Issue
Block a user