From 8cc8bf4afaa87b1a37ccff48ac53ec629d6014af Mon Sep 17 00:00:00 2001 From: RaffaeleFiorillo Date: Tue, 26 Oct 2021 19:31:09 -0100 Subject: [PATCH] Refactoring Adding typing hints to the code --- Auxiliary_Functionalities.py | 18 ++++++++++++------ eventos.py | 2 +- parameters/levels info/2.txt | 2 +- parameters/levels info/3.txt | 2 +- saves/Test/data.txt | 2 +- saves/Test/next_level.txt | 3 ++- texts/1.txt | 14 +++++++------- texts/6.txt | 12 ++++++------ to do list.gitignore | 2 ++ 9 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Auxiliary_Functionalities.py b/Auxiliary_Functionalities.py index 8352805..8b663c6 100644 --- a/Auxiliary_Functionalities.py +++ b/Auxiliary_Functionalities.py @@ -677,14 +677,14 @@ def decrypt_letter(letter: str, key: int) -> str: # given a string, returns the decrypted version of it -def decrypt_line(data: str, key): +def decrypt_line(data: str, key) -> str: data = data if "\n" not in data else data[:-1] decrypted_data = "".join(reversed([decrypt_letter(char, key) for char in data])) return decrypted_data # de crypts a file given his directory -def decrypt_file(directory: str): +def decrypt_file(directory: str) -> None: with open(directory, "r") as file: # get file content lines = file.readlines() if len(lines) == 0: # prevents list index error if file is empty @@ -699,7 +699,9 @@ def decrypt_file(directory: str): file.write(decrypt_line(lines[-1][start_index:], key)) -def read_file_content(file_directory, lines_to_read=0): +# reads an encrypted file and returns its decrypted content. Takes the directory of the encrypted file and the number +# of lines that we need to be returned. the output is a list of strings (every string is a different line of the file). +def read_file_content(file_directory: str, lines_to_read: int = 0) -> [str]: decrypt_file(file_directory) with open(file_directory, "r") as file: if lines_to_read == 0: @@ -710,13 +712,16 @@ def read_file_content(file_directory, lines_to_read=0): return file_content -def write_file_content(file_directory, content): +# Takes as parameters the file directory where the data will be written; and the content (to be written). content is +# a string containing all the data to be written in the file. +def write_file_content(file_directory: str, content: str) -> None: with open(file_directory, "w") as file: file.writelines(content) encrypt_file(file_directory) -def encrypt_all_files(directories): +# encrypts all .txt files in a list of directories passed as parameter +def encrypt_all_files(directories: [str]) -> None: for directory in directories: print(f"encrypting: {directory}") try: @@ -725,7 +730,8 @@ def encrypt_all_files(directories): print(f"!!! Error in current directory: {directory} !!!") -def decrypt_all_files(directories): +# decrypts all .txt files in a list of directories passed as parameter +def decrypt_all_files(directories: [str]) -> None: for directory in directories: print(f"decrypting: {directory}") try: diff --git a/eventos.py b/eventos.py index 1b5b6dc..8eaf975 100644 --- a/eventos.py +++ b/eventos.py @@ -160,6 +160,6 @@ def initiate_test(self): "parameters/levels info/13.txt", "texts/1.txt", "texts/2.txt", "texts/3.txt", "texts/4.txt", "texts/5.txt", "texts/6.txt", "texts/7.txt", "texts/8.txt", ] -Af.encrypt_all_files(directories) +# Af.encrypt_all_files(directories) # [print(f'"{directory}",') for directory in directories] diff --git a/parameters/levels info/2.txt b/parameters/levels info/2.txt index 933443b..3d9b5d8 100644 --- a/parameters/levels info/2.txt +++ b/parameters/levels info/2.txt @@ -1 +1 @@ -30 ..YzY zYV \ No newline at end of file +20 TTOpOQpOL \ No newline at end of file diff --git a/parameters/levels info/3.txt b/parameters/levels info/3.txt index 148a13d..ddeec48 100644 --- a/parameters/levels info/3.txt +++ b/parameters/levels info/3.txt @@ -1 +1 @@ -65 888yY35Y81 \ No newline at end of file +43 lllcCgiCle \ No newline at end of file diff --git a/saves/Test/data.txt b/saves/Test/data.txt index 86b3ac9..06f3ac2 100644 --- a/saves/Test/data.txt +++ b/saves/Test/data.txt @@ -1 +1 @@ -44 kDkDfedDfeiDeDggDeh \ No newline at end of file +2 9,B3,543,6A9,6,66,47 \ No newline at end of file diff --git a/saves/Test/next_level.txt b/saves/Test/next_level.txt index d55097a..20482e0 100644 --- a/saves/Test/next_level.txt +++ b/saves/Test/next_level.txt @@ -1 +1,2 @@ -56 p \ No newline at end of file +1 _A +11 K \ No newline at end of file diff --git a/texts/1.txt b/texts/1.txt index 62209b6..1338457 100644 --- a/texts/1.txt +++ b/texts/1.txt @@ -1,7 +1,7 @@ -26 vV -52 dYLe4LOUSQadL.YLUcQLdcQedLj.Q,Lh'XLdh'. LjT'R'9 -28 QF3ExOG0xQDL53P7xOGFCxGLx7D4AKKGHEAxQDD35AL53JH -56 RnmUaU PgjdPc,PijVPRYhgYk,cJPY_iPc,PYgUPhgUih -51 .gdK,TTgdTQKcXKcbPdcKU.KbTQ_e,KTWdKMiPGKiZ X7 -38 UK8 ZCNCI8TWv8AUPQKNNKD8FGTFPWJ8TWQH8FPC8FGTFPWJ -35 8DQDGS5STN5SRDFFHA5DGS5SNM \ No newline at end of file +9 eE +6 yobzObekigvybtobkxgbyxgzyb5tgsb3unby3utqb5juhuT +56 ncUbPld_PnaiWUmYPldc'PdiPYaV,hhdeb,PnaaUW,iWUge +13 kBAnynti582i1vi78oikr65r9v1ciru7i1vir5ni65n76 +28 GOLxF77OL74xKAxKJ3LKx8GxJ74EMFx70LxzQ3txQCDAj +25 H8uNMzAz6uGJiuxHCD8AA81u34G3CJ7uGJD5u3Czu34G3CJ7 +25 x4G47IuIJDuIH46681u47IuIDC \ No newline at end of file diff --git a/texts/6.txt b/texts/6.txt index 84a9b8e..044d0ad 100644 --- a/texts/6.txt +++ b/texts/6.txt @@ -1,6 +1,6 @@ -45 Ei -53 eQ.VfekEMdR,aEMVYfMWaM,,RMk,dRV'MeV_RfM'gEMVYF -37 SPl70UOFDSFQ7FOJO7UOJPQ7FOJO7ZUFOJO7UVPCg70TTBN -37 OFU7UVPCB7FSB7FSFIU79IUSBk7OP7EOBT7GP7OJBSH7IDBF -19 xA86oxAtoxAx1horxBAxE27iox1Co72oBAtCBow7tBD81C -59 V_kj_nafMS_'lSfaSkjXlkSfX'lS_q_SjmgqSfaSkeg'lX \ No newline at end of file +16 lK +2 ubogvu1U,tcnqU,gjv,hq,nnc,1ntcgp,ugmcv,pwU,gjV +5 wtKadysjhwjuajsnsaysntuajsnsa4yjsnsayztgFadxxfr +50 _ScJcd,POJSaOJSaSVcJLVcaOxJ_,JR_ObJT,J_WOaUJVQOS +55 XfcaOXfTOXfX HORXgfXj_bIOX hOb_OgfThgOWbTgic h +3 bhvuhylqX.hkw.ql.vudwv.qdkw.h2h.uxr2.ql.vprkwd \ No newline at end of file diff --git a/to do list.gitignore b/to do list.gitignore index 4e590ed..1ffd7e8 100644 --- a/to do list.gitignore +++ b/to do list.gitignore @@ -36,4 +36,6 @@ Include type-hints for variables and returned values During the game rare Letters turn red and in one text they form a cheat-word | Pendent | 9 | 9 | ------------------------------------------------------------------------------------------------------------------ Make cheat-words to unlock hidden functionalities&stuff (like skins,boosts&powers)| Pendent | 9 | 9 | +------------------------------------------------------------------------------------------------------------------ +Change some of the "exit" buttons to a more adapt name | Pendent | 2 | 2 | ------------------------------------------------------------------------------------------------------------------ \ No newline at end of file