diff --git a/Files/CsvLogic/Cards.py b/Files/CsvLogic/Cards.py index 57a096a..aacc506 100644 --- a/Files/CsvLogic/Cards.py +++ b/Files/CsvLogic/Cards.py @@ -1,93 +1,45 @@ -import csv +from Files.CsvReader import CsvReader class Cards: - def get_spg_id(): + def get_spg_id(self): CardSkillsID = [] - with open('GameAssets/csv_logic/cards.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - - if line_count == 0 or line_count == 1: - line_count += 1 - else: - if row[6].lower() == '4' or row[6].lower() == '5': - CardSkillsID.append(line_count - 2) - line_count += 1 - - return CardSkillsID - + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/cards.csv') + for row in rowData: + if row[6].lower() == '4' or row[6].lower() == '5': + CardSkillsID.append(rowData.index(row)) + return CardSkillsID def check_spg_id(self, id): - with open('GameAssets/csv_logic/cards.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - - if line_count == 0 or line_count == 1: - line_count += 1 - else: - if line_count-2 == id: - return row[6].lower() - - line_count += 1 - - - def get_spg_by_brawler_id(self, brawler_id, type): - char_file = open('GameAssets/csv_logic/characters.csv') - csv_reader = csv.reader(char_file, delimiter=',') - line_count = 0 - - for row in csv_reader: - if line_count == 0 or line_count == 1: - line_count += 1 - else: - line_count += 1 - if line_count == brawler_id + 3: - name = row[0] - line_count += 1 + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/cards.csv') + for row in rowData: + if rowData.index(row) == id: + return row[6].lower() - cards_file = open('GameAssets/csv_logic/cards.csv') - csv_reader = csv.reader(cards_file, delimiter=',') - line_count = 0 - for row in csv_reader: - if line_count == 0 or line_count == 1: - line_count += 1 - else: - line_count += 1 - if type == 4: - if row[6].lower() == '4' and row[3] == name: - id = line_count - 3 - char_file.close() - cards_file.close() - return id - - elif type == 5: - if row[3] == name and row[6].lower() == '5': - id = line_count - 3 - char_file.close() - cards_file.close() - return id - - - - - def get_brawler_unlock(): + def get_brawler_unlock(self): CardUnlockID = [] + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/cards.csv') + for row in rowData: + if row[6].lower() == '0': + CardUnlockID.append(rowData.index(row)) + return CardUnlockID - with open('GameAssets/csv_logic/cards.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - - if line_count == 0 or line_count == 1: - line_count += 1 - else: - if row[6].lower() == '0': - CardUnlockID.append(line_count - 2) - line_count += 1 - - return CardUnlockID \ No newline at end of file + def get_spg_by_brawler_id(self, brawler_id, type): + reader = CsvReader() + charsData = reader.readCsv('GameAssets/csv_logic/characters.csv') + cardsData = reader.readCsv('GameAssets/csv_logic/cards.csv') + for row in charsData: + if charsData.index(row) == brawler_id: + name = row[0] + for row in cardsData: + if type == 4: + if row[6].lower() == '4' and row[3] == name: + return cardsData.index(row) + elif type == 5: + if row[3] == name and row[6].lower() == '5': + return cardsData.index(row) \ No newline at end of file diff --git a/Files/CsvLogic/Characters.py b/Files/CsvLogic/Characters.py index c5e923a..6e313f4 100644 --- a/Files/CsvLogic/Characters.py +++ b/Files/CsvLogic/Characters.py @@ -1,59 +1,29 @@ -import csv +from Files.CsvReader import CsvReader class Characters: - def get_brawlers_id(): + def get_brawlers_id(self): BrawlersID = [] - with open('GameAssets/csv_logic/characters.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/characters.csv') + for row in rowData: + if row[20] == 'Hero' and row[2].lower() != 'true' and row[1].lower() != 'true': + BrawlersID.append(rowData.index(row)) - if line_count == 0 or line_count == 1: - line_count += 1 - else: - if row[20] == 'Hero' and row[2].lower() != 'true' and row[1].lower() != 'true': - BrawlersID.append(line_count - 2) - line_count += 1 - - return BrawlersID + return BrawlersID def get_brawler_by_skin_id(self, skin_id): - skins_file = open('GameAssets/csv_logic/skins.csv') - csv_reader = csv.reader(skins_file, delimiter=',') - line_count = 0 - for row in csv_reader: - if line_count == 0 or line_count == 1: - line_count += 1 - else: - line_count += 1 - if line_count == skin_id + 3: - conf = row[1] - line_count += 1 - - sconf_file = open('GameAssets/csv_logic/skin_confs.csv') - csv_reader = csv.reader(sconf_file, delimiter=',') - line_count = 0 - - for row in csv_reader: - if row[0] == conf: - brawler = row[1] - - char_file = open('GameAssets/csv_logic/characters.csv') - csv_reader = csv.reader(char_file, delimiter=',') - line_count = 0 - - for row in csv_reader: - if line_count == 0 or line_count == 1: - line_count += 1 - else: - line_count += 1 - if row[0] == brawler: - id = line_count - 3 - - skins_file.close() - sconf_file.close() - char_file.close() - - return id \ No newline at end of file + reader = CsvReader() + charsData = reader.readCsv('GameAssets/csv_logic/characters.csv') + skinsData = reader.readCsv('GameAssets/csv_logic/skins.csv') + skinsConfsData = reader.readCsv('GameAssets/csv_logic/skin_confs.csv') + for row in skinsData: + if skinsData.index(row) == skin_id: + conf = row[1] + for row in skinsConfsData: + if row[0] == conf: + brawler = row[1] + for row in charsData: + if row[0] == brawler: + return charsData.index(row) \ No newline at end of file diff --git a/Files/CsvLogic/Emotes.py b/Files/CsvLogic/Emotes.py index 96095fe..e31627f 100644 --- a/Files/CsvLogic/Emotes.py +++ b/Files/CsvLogic/Emotes.py @@ -1,18 +1,13 @@ -import csv +from Files.CsvReader import CsvReader class Emotes: - def get_emotes_id(): + def get_emotes_id(self): emotesID = [] - with open('GameAssets/csv_logic/emotes.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - if line_count == 0 or line_count == 1: - line_count += 1 - else: - if row[1].lower() != 'true' and row[6].lower != 'true': - emotesID.append(line_count - 2) - line_count += 1 + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/emotes.csv') + for row in rowData: + if row[1].lower() != 'true' and row[6].lower != 'true': + emotesID.append(rowData.index(row)) - return emotesID + return emotesID diff --git a/Files/CsvLogic/Skins.py b/Files/CsvLogic/Skins.py index df5e02d..ecdcfd5 100644 --- a/Files/CsvLogic/Skins.py +++ b/Files/CsvLogic/Skins.py @@ -1,19 +1,11 @@ -import csv +from Files.CsvReader import CsvReader class Skins: - def get_skins_id(): + def get_skins_id(self): SkinsID = [] - with open('GameAssets/csv_logic/skins.csv') as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - - if line_count == 0 or line_count == 1: - line_count += 1 - else: - SkinsID.append(line_count - 2) - line_count += 1 - - return SkinsID - + reader = CsvReader() + rowData = reader.readCsv('GameAssets/csv_logic/skins.csv') + for row in rowData: + SkinsID.append(rowData.index(row)) + return SkinsID \ No newline at end of file diff --git a/Files/CsvReader.py b/Files/CsvReader.py new file mode 100644 index 0000000..fa0665e --- /dev/null +++ b/Files/CsvReader.py @@ -0,0 +1,15 @@ +import csv + +class CsvReader: + def readCsv(self, filename): + self.rowData = [] + self.lineCount = 0 + with open(filename) as csvFile: + self.csvReader = csv.reader(csvFile, delimiter=',') + for row in self.csvReader: + if self.lineCount == 0 or self.lineCount == 1: + self.lineCount += 1 + else: + self.rowData.append(row) + self.lineCount += 1 + return self.rowData diff --git a/Logic/Player.py b/Logic/Player.py index fad98e1..d953431 100644 --- a/Logic/Player.py +++ b/Logic/Player.py @@ -13,11 +13,11 @@ class Player: ID = 0 token = None - skinsID = Skins.get_skins_id() - emotesID = Emotes.get_emotes_id() - brawlersID = Characters.get_brawlers_id() - cardsSkillsID = Cards.get_spg_id() - cardsUnlockID = Cards.get_brawler_unlock() + skinsID = Skins().get_skins_id() + emotesID = Emotes().get_emotes_id() + brawlersID = Characters().get_brawlers_id() + cardsSkillsID = Cards().get_spg_id() + cardsUnlockID = Cards().get_brawler_unlock() brawlers_skins = {} @@ -90,6 +90,5 @@ def createPlayerAccount(self, token = Helpers.randomToken(), id = Helpers.random def updateAccount(self, var, value): self.DB = DataBase() - self.Data[var] = value self.DB.updatePlayerAccount('data', json.dumps(self.Data), self.token) \ No newline at end of file diff --git a/Protocol/LogicMessageFactory.py b/Protocol/LogicMessageFactory.py index 1279531..3a9ec3f 100644 --- a/Protocol/LogicMessageFactory.py +++ b/Protocol/LogicMessageFactory.py @@ -1,4 +1,4 @@ -from Protocol.EndClientTurnMessage import EndClientTurnMessage +from Protocol.Messages.EndClientTurnMessage import EndClientTurnMessage from Protocol.Messages.Client.Login.LoginMessage import LoginMessage from Protocol.Messages.Client.KeepAliveMessage import KeepAliveMessage diff --git a/Protocol/EndClientTurnMessage.py b/Protocol/Messages/EndClientTurnMessage.py similarity index 99% rename from Protocol/EndClientTurnMessage.py rename to Protocol/Messages/EndClientTurnMessage.py index 44767eb..b50768c 100644 --- a/Protocol/EndClientTurnMessage.py +++ b/Protocol/Messages/EndClientTurnMessage.py @@ -26,6 +26,5 @@ def process(self): command.process(self) except AttributeError: command(self.client, self.player).send() # Exception for OutOfSyncMessage - else: print(f'[INFO] Command not handled! ({self.commandID})') \ No newline at end of file