use snake case for functions

This commit is contained in:
Thomas Rubini 2023-01-13 13:38:35 +01:00
parent f682d39c5a
commit ad76bda3e6
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 27 additions and 27 deletions

View File

@ -17,38 +17,38 @@ url_object = eg.URL.create(
engine = create_engine(url_object) engine = create_engine(url_object)
session = Session(engine) session = Session(engine)
def getTextFromLid(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 getRandomPlace() -> tables.Place: def get_random_place() -> tables.Place:
return random.choice(session.query(tables.Place).all()) return random.choice(session.query(tables.Place).all())
def getRandomNpc() -> tables.Npc : def get_random_npc() -> tables.Npc :
return random.choice(session.query(tables.Npc).all()) return random.choice(session.query(tables.Npc).all())
def getNpcRandomTraitId(npc) -> int: def get_npc_random_trait_id(npc) -> int:
reactions = session.query(tables.Reaction).filter_by(NPC_ID=npc.NPC_ID).all() reactions = session.query(tables.Reaction).filter_by(NPC_ID=npc.NPC_ID).all()
reaction = random.choice(reactions) reaction = random.choice(reactions)
return reaction.TRAIT_ID return reaction.TRAIT_ID
def getNpcRandomAnswer(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 getRandomQuestion(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 getTraitFromText(text): def get_trait_from_text(text):
trait_lid = session.query(tables.Locale).filter_by(TEXT=text).one().TEXT_ID trait_lid = session.query(tables.Locale).filter_by(TEXT=text).one().TEXT_ID
return session.query(tables.Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID return session.query(tables.Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID
def getTraitFromTraitId(trait_id): def get_trait_from_trait_id(trait_id):
trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one() trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one()
return trait return trait
def getTraits(lang): def get_traits(lang):
traits = [] traits = []
for trait in session.query(tables.Trait).all(): for trait in session.query(tables.Trait).all():
traits.append(getTextFromLid(lang,trait.NAME_LID)) traits.append(get_text_from_lid(lang,trait.NAME_LID))
return traits return traits

View File

@ -76,8 +76,8 @@ class Game:
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] traitId = self.reaction_table[npc_id]
trait = getTraitFromTraitId(traitId) trait = get_trait_from_trait_id(traitId)
npcs[npc_id]["reaction"] = getTextFromLid("FR",trait.NAME_LID) npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID)
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
@ -130,7 +130,7 @@ class Game:
results = {} results = {}
try: try:
for npc_id in responses: for npc_id in responses:
trait_id = getTraitIdFromString(responses[npc_id]) trait_id = get_trait_id_from_string(responses[npc_id])
results[npc_id] = trait_id == str(self.reaction_table[npc_id]) results[npc_id] = trait_id == str(self.reaction_table[npc_id])
return results return results
except: except:
@ -200,20 +200,20 @@ def check_username(username: str) -> bool:
def generateNpcText(npc: tables.Npc, lang: str) -> dict: def generateNpcText(npc: tables.Npc, lang: str) -> dict:
data = {} data = {}
data["name"] = getTextFromLid(lang, npc.NAME_LID) data["name"] = get_text_from_lid(lang, npc.NAME_LID)
data["QA_0"] = getTextFromLid(lang, getNpcRandomAnswer(npc,0).TEXT_LID) data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID)
data["QA_1"] = getTextFromLid(lang, getNpcRandomAnswer(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 generateNpcReactions(npc: tables.Npc) ->list: def generateNpcReactions(npc: tables.Npc) ->list:
return getNpcRandomTraitId(npc) return get_npc_random_trait_id(npc)
def generatePlaceData(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"] = getTextFromLid(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)
@ -227,7 +227,7 @@ def generateGameData(LANG):
reactions_table = {} reactions_table = {}
npcs = [] npcs = []
while len(npcs) != 5: while len(npcs) != 5:
npc = getRandomNpc() 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:
@ -236,15 +236,15 @@ def generateGameData(LANG):
places = [] places = []
while len(places) != 3: while len(places) != 3:
place = getRandomPlace() place = get_random_place()
if place not in places: if place not in places:
places.append(place) places.append(place)
data["rooms"] = generatePlaceData(npcs,places,LANG) data["rooms"] = generate_place_data(npcs,places,LANG)
data["questions"] = {} data["questions"] = {}
data["questions"]["QA_0"] = getTextFromLid("FR",getRandomQuestion(0).TEXT_LID) data["questions"]["QA_0"] = get_text_from_lid("FR",get_random_question(0).TEXT_LID)
data["questions"]["QA_1"] = getTextFromLid("FR",getRandomQuestion(1).TEXT_LID) data["questions"]["QA_1"] = get_text_from_lid("FR",get_random_question(1).TEXT_LID)
data["traits"] = getTraits(LANG) data["traits"] = get_traits(LANG)
return data, reactions_table return data, reactions_table
def read_image(path:str): def read_image(path:str):
@ -253,8 +253,8 @@ def read_image(path:str):
except: except:
return 1 return 1
def getTraitIdFromString(trait): def get_trait_id_from_string(trait):
return getTraitFromText(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")