refactored according to flake8 and pylint linting
This commit is contained in:
parent
f3d27a7db1
commit
7d049565a7
@ -1,36 +1,36 @@
|
|||||||
from tables import Answer
|
from tables import Answer
|
||||||
|
|
||||||
ANSWERS = [
|
ANSWERS = [
|
||||||
Answer(1,0,1,1),
|
Answer(1, 0, 1, 1),
|
||||||
Answer(2,0,1,2),
|
Answer(2, 0, 1, 2),
|
||||||
Answer(3,1,1,3),
|
Answer(3, 1, 1, 3),
|
||||||
Answer(4,1,1,4),
|
Answer(4, 1, 1, 4),
|
||||||
Answer(5,0,2,6),
|
Answer(5, 0, 2, 6),
|
||||||
Answer(6,0,2,7),
|
Answer(6, 0, 2, 7),
|
||||||
Answer(7,1,2,8),
|
Answer(7, 1, 2, 8),
|
||||||
Answer(8,1,2,9),
|
Answer(8, 1, 2, 9),
|
||||||
Answer(9,0,3,11),
|
Answer(9, 0, 3, 11),
|
||||||
Answer(10,0,3,12),
|
Answer(10, 0, 3, 12),
|
||||||
Answer(11,1,3,13),
|
Answer(11, 1, 3, 13),
|
||||||
Answer(12,1,3,14),
|
Answer(12, 1, 3, 14),
|
||||||
Answer(13,0,4,16),
|
Answer(13, 0, 4, 16),
|
||||||
Answer(14,0,4,17),
|
Answer(14, 0, 4, 17),
|
||||||
Answer(15,1,4,18),
|
Answer(15, 1, 4, 18),
|
||||||
Answer(16,1,4,19),
|
Answer(16, 1, 4, 19),
|
||||||
Answer(17,0,5,21),
|
Answer(17, 0, 5, 21),
|
||||||
Answer(18,0,5,22),
|
Answer(18, 0, 5, 22),
|
||||||
Answer(19,1,5,23),
|
Answer(19, 1, 5, 23),
|
||||||
Answer(20,1,5,24),
|
Answer(20, 1, 5, 24),
|
||||||
Answer(21,0,6,26),
|
Answer(21, 0, 6, 26),
|
||||||
Answer(22,0,6,27),
|
Answer(22, 0, 6, 27),
|
||||||
Answer(23,1,6,28),
|
Answer(23, 1, 6, 28),
|
||||||
Answer(24,1,6,29),
|
Answer(24, 1, 6, 29),
|
||||||
Answer(25,0,7,31),
|
Answer(25, 0, 7, 31),
|
||||||
Answer(26,0,7,32),
|
Answer(26, 0, 7, 32),
|
||||||
Answer(27,1,7,33),
|
Answer(27, 1, 7, 33),
|
||||||
Answer(28,1,7,34),
|
Answer(28, 1, 7, 34),
|
||||||
Answer(29,0,8,36),
|
Answer(29, 0, 8, 36),
|
||||||
Answer(30,0,8,37),
|
Answer(30, 0, 8, 37),
|
||||||
Answer(31,1,8,38),
|
Answer(31, 1, 8, 38),
|
||||||
Answer(32,1,8,39)
|
Answer(32, 1, 8, 39)
|
||||||
]
|
]
|
@ -1,66 +1,66 @@
|
|||||||
from tables import Locale
|
from tables import Locale
|
||||||
|
|
||||||
LOCALES = [
|
LOCALES = [
|
||||||
Locale(0,"FR","Le Médecin"),
|
Locale(0, "FR", "Le Médecin"),
|
||||||
Locale(1,"FR","Il y avait {SALLE} ça m'a intrigué."),
|
Locale(1, "FR", "Il y avait {SALLE} ça m'a intrigué."),
|
||||||
Locale(2,"FR","{SALLE} avait l'air sympa donc j'y suis allé."),
|
Locale(2, "FR", "{SALLE} avait l'air sympa donc j'y suis allé."),
|
||||||
Locale(3,"FR","Il me semble qu'il y avait {NPC}."),
|
Locale(3, "FR", "Il me semble qu'il y avait {NPC}."),
|
||||||
Locale(4,"FR","Je suis pratiquement sûr que j'étais avec {NPC}."),
|
Locale(4, "FR", "Je suis pratiquement sûr que j'étais avec {NPC}."),
|
||||||
Locale(5,"FR","Le Diplomate"),
|
Locale(5, "FR", "Le Diplomate"),
|
||||||
Locale(6,"FR","Je profitais d'une collation dans {SALLE}."),
|
Locale(6, "FR", "Je profitais d'une collation dans {SALLE}."),
|
||||||
Locale(7,"FR","J'admirais la décoration subtile de {SALLE} ... je m'en inspirerais pour chez moi."),
|
Locale(7, "FR", "J'admirais la décoration subtile de {SALLE} ... je m'en inspirerais pour chez moi."),
|
||||||
Locale(8,"FR","Je m'instruisais auprès de {NPC}."),
|
Locale(8, "FR", "Je m'instruisais auprès de {NPC}."),
|
||||||
Locale(9,"FR","Avec {NPC} pour exposer nos différents points de vus sur divers sujets."),
|
Locale(9, "FR", "Avec {NPC} pour exposer nos différents points de vus sur divers sujets."),
|
||||||
Locale(10,"FR","Le Combattant"),
|
Locale(10, "FR", "Le Combattant"),
|
||||||
Locale(11,"FR","{SALLE} nous a servi de salle de duel."),
|
Locale(11, "FR", "{SALLE} nous a servi de salle de duel."),
|
||||||
Locale(12,"FR","J'ai festoillé dans {SALLE}."),
|
Locale(12, "FR", "J'ai festoillé dans {SALLE}."),
|
||||||
Locale(13,"FR","On faisait un bras de fer avec {NPC}."),
|
Locale(13, "FR", "On faisait un bras de fer avec {NPC}."),
|
||||||
Locale(14,"FR","{NPC} et moi nous sommes engagés dans une joute verbale des plus palpitante."),
|
Locale(14, "FR", "{NPC} et moi nous sommes engagés dans une joute verbale des plus palpitante."),
|
||||||
Locale(15,"FR","La Duchesse"),
|
Locale(15, "FR", "La Duchesse"),
|
||||||
Locale(16,"FR","Pour votre gouverne je me trouvais dans {SALLE}."),
|
Locale(16, "FR", "Pour votre gouverne je me trouvais dans {SALLE}."),
|
||||||
Locale(17,"FR","s'il vous faut savoir ... j'étais en train de me reposer dans {SALLE}."),
|
Locale(17, "FR", "s'il vous faut savoir ... j'étais en train de me reposer dans {SALLE}."),
|
||||||
Locale(18,"FR","{NPC} me tenait compagnie."),
|
Locale(18, "FR", "{NPC} me tenait compagnie."),
|
||||||
Locale(19,"FR","J'était avec {NPC}."),
|
Locale(19, "FR", "J'était avec {NPC}."),
|
||||||
Locale(20,"FR","La Diva"),
|
Locale(20, "FR", "La Diva"),
|
||||||
Locale(21,"FR","{SALLE} me semblait être la plus belle pièce de la maison."),
|
Locale(21, "FR", "{SALLE} me semblait être la plus belle pièce de la maison."),
|
||||||
Locale(22,"FR","Je buvais un verre dans {SALLE}."),
|
Locale(22, "FR", "Je buvais un verre dans {SALLE}."),
|
||||||
Locale(23,"FR","Je profitais de la compagnie de {NPC}."),
|
Locale(23, "FR", "Je profitais de la compagnie de {NPC}."),
|
||||||
Locale(24,"FR","J'étais avec {NPC} à partager une délicieuse conversation ainsi qu'une coupe de champagne."),
|
Locale(24, "FR", "J'étais avec {NPC} à partager une délicieuse conversation ainsi qu'une coupe de champagne."),
|
||||||
Locale(25,"FR","La Parieuse"),
|
Locale(25, "FR", "La Parieuse"),
|
||||||
Locale(26,"FR","J'avis monté une table de jeu dans {SALLE}."),
|
Locale(26, "FR", "J'avis monté une table de jeu dans {SALLE}."),
|
||||||
Locale(27,"FR","{SALLE} est tout de même plus agréable une fois changé en casino."),
|
Locale(27, "FR", "{SALLE} est tout de même plus agréable une fois changé en casino."),
|
||||||
Locale(28,"FR","Vous saviez que {NPC} était incroyable avec des cartes à la mains?"),
|
Locale(28, "FR", "Vous saviez que {NPC} était incroyable avec des cartes à la mains?"),
|
||||||
Locale(29,"FR","Si vous tenez à votre argent ne jouez jamisa au poker avec {NPC}."),
|
Locale(29, "FR", "Si vous tenez à votre argent ne jouez jamisa au poker avec {NPC}."),
|
||||||
Locale(30,"FR","L'Agent"),
|
Locale(30, "FR", "L'Agent"),
|
||||||
Locale(31,"FR","On pouvait me retrouver dans {SALLE}."),
|
Locale(31, "FR", "On pouvait me retrouver dans {SALLE}."),
|
||||||
Locale(32,"FR","{SALLE}"),
|
Locale(32, "FR", "{SALLE}"),
|
||||||
Locale(33,"FR","J'étais avec {NPC} au moment des faits."),
|
Locale(33, "FR", "J'étais avec {NPC} au moment des faits."),
|
||||||
Locale(34,"FR","{NPC}"),
|
Locale(34, "FR", "{NPC}"),
|
||||||
Locale(35,"FR","La Voyageuse"),
|
Locale(35, "FR", "La Voyageuse"),
|
||||||
Locale(36,"FR","{SALLE} me semblais un bon endroit pour me poser"),
|
Locale(36, "FR", "{SALLE} me semblais un bon endroit pour me poser"),
|
||||||
Locale(37,"FR","{SALLE} me rappelais mes voyages."),
|
Locale(37, "FR", "{SALLE} me rappelais mes voyages."),
|
||||||
Locale(38,"FR","Nous organisions notre prochain voyage avec {NPC}."),
|
Locale(38, "FR", "Nous organisions notre prochain voyage avec {NPC}."),
|
||||||
Locale(39,"FR","Avec {NPC} on parler des lieux que l’on avait visité. C’était très instructif."),
|
Locale(39, "FR", "Avec {NPC} on parler des lieux que l’on avait visité. C’était très instructif."),
|
||||||
Locale(100,"FR","Ce manoir est plutôt grand ... vous pouvez me dire où vous étiez?"),
|
Locale(100, "FR", "Ce manoir est plutôt grand ... vous pouvez me dire où vous étiez?"),
|
||||||
Locale(101,"FR","Vous étiez où au moment des faits?"),
|
Locale(101, "FR", "Vous étiez où au moment des faits?"),
|
||||||
Locale(102,"FR","Dans quelle salle étiez-vous pendant que le coffre était subtilisé ?"),
|
Locale(102, "FR", "Dans quelle salle étiez-vous pendant que le coffre était subtilisé ?"),
|
||||||
Locale(105,"FR","Etiez-vous seul au moment des faits ?"),
|
Locale(105, "FR", "Etiez-vous seul au moment des faits ?"),
|
||||||
Locale(106,"FR","Quelqu’un peu valider vous alibi pour la soirée ?"),
|
Locale(106, "FR", "Quelqu’un peu valider vous alibi pour la soirée ?"),
|
||||||
Locale(107,"FR","Vous étiez accompagné ce soir-là ?"),
|
Locale(107, "FR", "Vous étiez accompagné ce soir-là ?"),
|
||||||
Locale(120,"FR","méfiant(e)"),
|
Locale(120, "FR", "méfiant(e)"),
|
||||||
Locale(110,"FR","un maintien rigide des traits du visage, un regard de travers. Une crispation des sourcils et parfois des rides autour de la bouche. Ces caractéristiques sont synonmes d'incompréhension ou de peur de ce que peut nous annoncer la personne en face."),
|
Locale(110, "FR", "un maintien rigide des traits du visage, un regard de travers. Une crispation des sourcils et parfois des rides autour de la bouche. Ces caractéristiques sont synonmes d'incompréhension ou de peur de ce que peut nous annoncer la personne en face."),
|
||||||
Locale(121,"FR","heureux(se)"),
|
Locale(121, "FR", "heureux(se)"),
|
||||||
Locale(111,"FR","un visage decontracté et ouvert, les muscles des joues contractés qui laissent apparaître un sourie. On le détermine aussi par des yeux plissés en accord avec les sourcils qui marque la différence avec un faux sourire où les sourcils ne sont pas contractés. Cela montre une complicité avec l'interlocuteur ou un moyen de ne pas laisser paraître ses réelles émotions."),
|
Locale(111, "FR", "un visage decontracté et ouvert, les muscles des joues contractés qui laissent apparaître un sourie. On le détermine aussi par des yeux plissés en accord avec les sourcils qui marque la différence avec un faux sourire où les sourcils ne sont pas contractés. Cela montre une complicité avec l'interlocuteur ou un moyen de ne pas laisser paraître ses réelles émotions."),
|
||||||
Locale(122,"FR","triste"),
|
Locale(122, "FR", "triste"),
|
||||||
Locale(112,"FR","des sourcils contractés et resserés vers le centre du visage auxquels s'ajoute un regard vide ou fuyant de l'interlocuteur soit en fermant les yeux soit en évitant un contact visuel. Ces caractéristiques témoignent d'un sentiment puissant ou du fait d'être atteint par les propos ou accusations de son interlocuteur."),
|
Locale(112, "FR", "des sourcils contractés et resserés vers le centre du visage auxquels s'ajoute un regard vide ou fuyant de l'interlocuteur soit en fermant les yeux soit en évitant un contact visuel. Ces caractéristiques témoignent d'un sentiment puissant ou du fait d'être atteint par les propos ou accusations de son interlocuteur."),
|
||||||
Locale(123,"FR","stressé(e)"),
|
Locale(123, "FR", "stressé(e)"),
|
||||||
Locale(113,"FR","un visage crispé qui s'accompagne habituellement de sourcils froncés, un regard perdu qui se détourne de celui de son interlocuteur. Cela s'accompagne souvent de mouvements de la tête et de la bouche en se mordant les lèvres par exemple. Tout cela traduit une difficulté de concentration ou une peur de ce qu'annonce ou peut nous annoncer l'interlocuteur en face."),
|
Locale(113, "FR", "un visage crispé qui s'accompagne habituellement de sourcils froncés, un regard perdu qui se détourne de celui de son interlocuteur. Cela s'accompagne souvent de mouvements de la tête et de la bouche en se mordant les lèvres par exemple. Tout cela traduit une difficulté de concentration ou une peur de ce qu'annonce ou peut nous annoncer l'interlocuteur en face."),
|
||||||
Locale(124,"FR","surpris(e)"),
|
Locale(124, "FR", "surpris(e)"),
|
||||||
Locale(114,"FR","généralement par des yeux écarquillés et un haussement des sourcils. Cela peut également se distinguer par une bouche ouvert ou au contraire des gens serrées et parfois par un relâchement du visage. Ces caractéristiques correspondent à un choc, une incompréhension ou encore un étonnement de ce que voit ou entend la personne."),
|
Locale(114, "FR", "généralement par des yeux écarquillés et un haussement des sourcils. Cela peut également se distinguer par une bouche ouvert ou au contraire des gens serrées et parfois par un relâchement du visage. Ces caractéristiques correspondent à un choc, une incompréhension ou encore un étonnement de ce que voit ou entend la personne."),
|
||||||
Locale(130,"FR","Le salon"),
|
Locale(130, "FR", "Le salon"),
|
||||||
Locale(131,"FR","La salle de reception"),
|
Locale(131, "FR", "La salle de reception"),
|
||||||
Locale(132,"FR","Le hall d'entrée"),
|
Locale(132, "FR", "Le hall d'entrée"),
|
||||||
Locale(133,"FR","La cuisine"),
|
Locale(133, "FR", "La cuisine"),
|
||||||
Locale(134,"FR","La chambre du maitre"),
|
Locale(134, "FR", "La chambre du maitre"),
|
||||||
Locale(135,"FR","Le jarin")
|
Locale(135, "FR", "Le jarin")
|
||||||
]
|
]
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
from tables import Npc
|
from tables import Npc
|
||||||
|
|
||||||
NPCS = [
|
NPCS = [
|
||||||
Npc(1,0),
|
Npc(1, 0),
|
||||||
Npc(2,5),
|
Npc(2, 5),
|
||||||
Npc(3,10),
|
Npc(3, 10),
|
||||||
Npc(4,15),
|
Npc(4, 15),
|
||||||
Npc(5,20),
|
Npc(5, 20),
|
||||||
Npc(6,25),
|
Npc(6, 25),
|
||||||
Npc(7,30),
|
Npc(7, 30),
|
||||||
Npc(8,35)
|
Npc(8, 35)
|
||||||
]
|
]
|
@ -1,10 +1,10 @@
|
|||||||
from tables import Place
|
from tables import Place
|
||||||
|
|
||||||
PLACES = [
|
PLACES = [
|
||||||
Place(1,130),
|
Place(1, 130),
|
||||||
Place(2,131),
|
Place(2, 131),
|
||||||
Place(3,132),
|
Place(3, 132),
|
||||||
Place(4,133),
|
Place(4, 133),
|
||||||
Place(5,134),
|
Place(5, 134),
|
||||||
Place(6,135)
|
Place(6, 135)
|
||||||
]
|
]
|
@ -1,10 +1,10 @@
|
|||||||
from tables import Question
|
from tables import Question
|
||||||
|
|
||||||
QUESTIONS = [
|
QUESTIONS = [
|
||||||
Question(1,0,100),
|
Question(1, 0, 100),
|
||||||
Question(2,0,101),
|
Question(2, 0, 101),
|
||||||
Question(3,0,102),
|
Question(3, 0, 102),
|
||||||
Question(4,1,105),
|
Question(4, 1, 105),
|
||||||
Question(5,1,106),
|
Question(5, 1, 106),
|
||||||
Question(6,1,107)
|
Question(6, 1, 107)
|
||||||
]
|
]
|
@ -1,44 +1,44 @@
|
|||||||
from tables import Reaction
|
from tables import Reaction
|
||||||
|
|
||||||
REACTIONS = [
|
REACTIONS = [
|
||||||
Reaction(1,110,1,1),
|
Reaction(1, 110, 1, 1),
|
||||||
Reaction(2,110,2,1),
|
Reaction(2, 110, 2, 1),
|
||||||
Reaction(3,110,3,1),
|
Reaction(3, 110, 3, 1),
|
||||||
Reaction(4,110,4,1),
|
Reaction(4, 110, 4, 1),
|
||||||
Reaction(5,110,5,1),
|
Reaction(5, 110, 5, 1),
|
||||||
Reaction(6,110,6,1),
|
Reaction(6, 110, 6, 1),
|
||||||
Reaction(7,110,7,1),
|
Reaction(7, 110, 7, 1),
|
||||||
Reaction(8,110,8,1),
|
Reaction(8, 110, 8, 1),
|
||||||
Reaction(9,111,1,2),
|
Reaction(9, 111, 1, 2),
|
||||||
Reaction(10,111,2,2),
|
Reaction(10, 111, 2, 2),
|
||||||
Reaction(11,111,3,2),
|
Reaction(11, 111, 3, 2),
|
||||||
Reaction(12,111,4,2),
|
Reaction(12, 111, 4, 2),
|
||||||
Reaction(13,111,5,2),
|
Reaction(13, 111, 5, 2),
|
||||||
Reaction(14,111,6,2),
|
Reaction(14, 111, 6, 2),
|
||||||
Reaction(15,111,7,2),
|
Reaction(15, 111, 7, 2),
|
||||||
Reaction(16,111,8,2),
|
Reaction(16, 111, 8, 2),
|
||||||
Reaction(17,112,1,3),
|
Reaction(17, 112, 1, 3),
|
||||||
Reaction(18,112,2,3),
|
Reaction(18, 112, 2, 3),
|
||||||
Reaction(19,112,3,3),
|
Reaction(19, 112, 3, 3),
|
||||||
Reaction(20,112,4,3),
|
Reaction(20, 112, 4, 3),
|
||||||
Reaction(21,112,5,3),
|
Reaction(21, 112, 5, 3),
|
||||||
Reaction(22,112,6,3),
|
Reaction(22, 112, 6, 3),
|
||||||
Reaction(23,112,7,3),
|
Reaction(23, 112, 7, 3),
|
||||||
Reaction(24,112,8,3),
|
Reaction(24, 112, 8, 3),
|
||||||
Reaction(25,113,1,4),
|
Reaction(25, 113, 1, 4),
|
||||||
Reaction(26,113,2,4),
|
Reaction(26, 113, 2, 4),
|
||||||
Reaction(27,113,3,4),
|
Reaction(27, 113, 3, 4),
|
||||||
Reaction(28,113,4,4),
|
Reaction(28, 113, 4, 4),
|
||||||
Reaction(29,113,5,4),
|
Reaction(29, 113, 5, 4),
|
||||||
Reaction(30,113,6,4),
|
Reaction(30, 113, 6, 4),
|
||||||
Reaction(31,113,7,4),
|
Reaction(31, 113, 7, 4),
|
||||||
Reaction(32,113,8,4),
|
Reaction(32, 113, 8, 4),
|
||||||
Reaction(33,114,1,5),
|
Reaction(33, 114, 1, 5),
|
||||||
Reaction(34,114,2,5),
|
Reaction(34, 114, 2, 5),
|
||||||
Reaction(35,114,3,5),
|
Reaction(35, 114, 3, 5),
|
||||||
Reaction(36,114,4,5),
|
Reaction(36, 114, 4, 5),
|
||||||
Reaction(37,114,5,5),
|
Reaction(37, 114, 5, 5),
|
||||||
Reaction(38,114,6,5),
|
Reaction(38, 114, 6, 5),
|
||||||
Reaction(39,114,7,5),
|
Reaction(39, 114, 7, 5),
|
||||||
Reaction(40,114,8,5)
|
Reaction(40, 114, 8, 5)
|
||||||
]
|
]
|
@ -1,9 +1,9 @@
|
|||||||
from tables import Trait
|
from tables import Trait
|
||||||
|
|
||||||
TRAITS = [
|
TRAITS = [
|
||||||
Trait(1,120),
|
Trait(1, 120),
|
||||||
Trait(2,121),
|
Trait(2, 121),
|
||||||
Trait(3,122),
|
Trait(3, 122),
|
||||||
Trait(4,123),
|
Trait(4, 123),
|
||||||
Trait(5,124)
|
Trait(5, 124)
|
||||||
]
|
]
|
@ -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,7 +17,8 @@ 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
|
||||||
|
|
||||||
def get_random_place() -> tables.Place:
|
def get_random_place() -> tables.Place:
|
||||||
@ -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,11 +94,12 @@ 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)
|
||||||
NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"),primary_key=True)
|
NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"), primary_key=True)
|
||||||
TRAIT_ID = Column(Integer, ForeignKey("T_TRAIT.TRAIT_ID"),primary_key=True)
|
TRAIT_ID = Column(Integer, ForeignKey("T_TRAIT.TRAIT_ID"), primary_key=True)
|
||||||
DESC_LID = Column(Integer, ForeignKey("T_LOCALE.TEXT_ID"))
|
DESC_LID = Column(Integer, ForeignKey("T_LOCALE.TEXT_ID"))
|
||||||
LOCALE = relationship("Locale")
|
LOCALE = relationship("Locale")
|
||||||
NPC = relationship("Npc")
|
NPC = relationship("Npc")
|
||||||
|
@ -5,7 +5,8 @@ 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
|
||||||
parameter
|
parameter
|
||||||
@ -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,10 +78,10 @@ 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"] = {}
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
player_results[member.username] = member.results
|
player_results[member.username] = member.results
|
||||||
@ -88,7 +91,7 @@ class Game:
|
|||||||
"""
|
"""
|
||||||
TODO
|
TODO
|
||||||
"""
|
"""
|
||||||
#TODO Get language from player
|
# TODO Get language from player
|
||||||
self.gamedata, self.reaction_table = generate_game_data("FR")
|
self.gamedata, self.reaction_table = generate_game_data("FR")
|
||||||
self.gamedata["game_id"] = self.game_id
|
self.gamedata["game_id"] = self.game_id
|
||||||
|
|
||||||
@ -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,40 +206,44 @@ 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)
|
||||||
data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID)
|
data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc, 0).TEXT_LID)
|
||||||
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)
|
||||||
for place in places:
|
for place in places:
|
||||||
placedata = data[str(place.PLACE_ID)] = {}
|
placedata = data[str(place.PLACE_ID)] = {}
|
||||||
placedata["name"] = get_text_from_lid(lang,place.NAME_LID)
|
placedata["name"] = get_text_from_lid(lang, place.NAME_LID)
|
||||||
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 = {}
|
||||||
npcs = []
|
npcs = []
|
||||||
while len(npcs) != 5:
|
while len(npcs) != 5:
|
||||||
npc = get_random_npc()
|
npc = get_random_npc()
|
||||||
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,26 +117,26 @@ 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"}
|
||||||
image = game_logic.get_npc_image(npc_id)
|
image = game_logic.get_npc_image(npc_id)
|
||||||
if image is None:
|
if image is None:
|
||||||
return {"error": 1, "msg": "npc not found"}
|
return {"error": 1, "msg": "npc not found"}
|
||||||
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