From 5b5bc9f9d6f4976f484627b9bce4941470ccb7d3 Mon Sep 17 00:00:00 2001 From: JDM170 Date: Mon, 17 Feb 2020 17:19:28 +0700 Subject: [PATCH] Update * Code improvements * Changes in file structure Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com> --- README.md | 6 + __init__.py | 2 +- convert_main_form_ui_to_py.bat | 1 - convert_second_form_ui_to_py.bat | 1 - convert_ui_to_py.bat | 13 ++ funcs.py | 98 --------- main/__init__.py | 1 + main_form.ui => main/form.ui | 18 +- main/script.py | 210 +++++++++++++++++++ main_script.py | 277 -------------------------- second/__init__.py | 1 + second_form.ui => second/form.ui | 10 +- second/script.py | 278 ++++++++++++++++++++++++++ second_script.py | 332 ------------------------------- setup.py | 24 +-- util.py | 101 ++++++++++ 16 files changed, 634 insertions(+), 739 deletions(-) delete mode 100644 convert_main_form_ui_to_py.bat delete mode 100644 convert_second_form_ui_to_py.bat create mode 100644 convert_ui_to_py.bat delete mode 100644 funcs.py create mode 100644 main/__init__.py rename main_form.ui => main/form.ui (96%) create mode 100644 main/script.py delete mode 100644 main_script.py create mode 100644 second/__init__.py rename second_form.ui => second/form.ui (97%) create mode 100644 second/script.py delete mode 100644 second_script.py create mode 100644 util.py diff --git a/README.md b/README.md index 4b5c49a..7291ec7 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,10 @@ This program allows: *** +Requirments: +Python 3.5.4 +PyQt 5.6.0 + +*** + #### Since the program is in development, I won't give up help and guidance on my errors in the code. diff --git a/__init__.py b/__init__.py index 1b35540..cf8ba66 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ if __name__ == '__main__': from sys import argv, exit from PyQt5.QtWidgets import QApplication - from main_script import MainWindow + from main.script import MainWindow app = QApplication(argv) win = MainWindow() win.show() diff --git a/convert_main_form_ui_to_py.bat b/convert_main_form_ui_to_py.bat deleted file mode 100644 index fd8baac..0000000 --- a/convert_main_form_ui_to_py.bat +++ /dev/null @@ -1 +0,0 @@ -pyuic5 main_form.ui -o main_form.py \ No newline at end of file diff --git a/convert_second_form_ui_to_py.bat b/convert_second_form_ui_to_py.bat deleted file mode 100644 index 235cd72..0000000 --- a/convert_second_form_ui_to_py.bat +++ /dev/null @@ -1 +0,0 @@ -pyuic5 second_form.ui -o second_form.py \ No newline at end of file diff --git a/convert_ui_to_py.bat b/convert_ui_to_py.bat new file mode 100644 index 0000000..a6d28b5 --- /dev/null +++ b/convert_ui_to_py.bat @@ -0,0 +1,13 @@ +cls +@echo off +title Form converter + +:SETUP +echo Enter form name to convert into .py (without .ui): +echo Type 'exit' to exit +set/p "name=> " +if %name%==exit goto EXIT +pyuic5 %name%.ui -o %name%.py +goto SETUP + +:EXIT \ No newline at end of file diff --git a/funcs.py b/funcs.py deleted file mode 100644 index 5d9304c..0000000 --- a/funcs.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- - -from re import search, match, sub - - -class Functions: - # TODO: Custom functions - @staticmethod - def showMsgBox(title: str, text: str): - from PyQt5.QtWidgets import QMessageBox - box = QMessageBox() - box.setWindowTitle(title) - box.setText(text) - box.exec_() - - # TODO: Default functions - @staticmethod - def searchline(lines, term, start=0, cancel=r"thisstringmustnotexist"): - if search(term, lines[start]): - return start - start += 1 - while start <= len(lines) - 1: - if search(term, lines[start]): - return start - if search(cancel, lines[start]): - return None - start += 1 - return None - - def searchlineinunit(self, lines, term, unit): - line = self.searchline(lines, " : " + unit + " {") - return self.searchline(lines, term, start=line, cancel="}") - - def searchalllines(self, lines, term): - matches = [] - start = 0 - while self.searchline(lines, term, start=start + 1): - start = self.searchline(lines, term, start=start + 1) - matches.append(start) - if matches is None: - return None - return matches - - @staticmethod - def getvalue(lines, line): - return search(r": (.+)$", lines[line]).group(1) - - @staticmethod - def setvalue(lines, line, value): - name = match(r"(.+):", lines[line]).group(1) - lines[line] = name + ": " + value - - @staticmethod - def getunitname(lines, line): - return search(r" : (.+) {$", lines[line]).group(1) - - @staticmethod - def getarraylength(lines, line): - return int(search(r": ([0-9]+)$", lines[line]).group(1)) - - @staticmethod - def getarrayvaluebyindex(lines, line, index): - return search(r": (.+)$", lines[line + index + 1]).group(1) - - def getarrayindexbyvalue(self, lines, line, value): - count = 0 - for i in range(self.getarraylength(lines, line)): - if self.getvalue(lines, line + count + 1) == value: - return count - count += 1 - return None - - def getarrayitems(self, lines, line): - items = [] - count = self.getarraylength(lines, line) - for i in range(count): - items.append(search(r": (.+)$", lines[line + i + 1]).group(1)) - if items is None: - return None - return items - - def addarrayvalue(self, lines, line, value): - count = self.getarraylength(lines, line) - name = match(r"(.+):", lines[line]).group(1) - lines[line] = name + ": " + str(count + 1) - lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value) - - def removearrayvalue(self, lines, line, value): - name = match(r"(.+):", lines[line]).group(1) - del lines[line + 1 + self.getarrayindexbyvalue(lines, line, value)] - lines[line] = name + ": " + str(self.getarraylength(lines, line) - 1) - for i in range(self.getarraylength(lines, line)): - lines[line + i + 1] = sub(r"\[[0-9]+\]", "[" + str(i) + "]", lines[line + i + 1]) - - def changearrayvalue(self, lines, line, index, value): - line += index + 1 - self.setvalue(lines, line, value) diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..f1ccd87 --- /dev/null +++ b/main/__init__.py @@ -0,0 +1 @@ +# initialize module 'main' for compile program \ No newline at end of file diff --git a/main_form.ui b/main/form.ui similarity index 96% rename from main_form.ui rename to main/form.ui index 713d9db..9eb27ab 100644 --- a/main_form.ui +++ b/main/form.ui @@ -103,7 +103,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -149,7 +149,7 @@ - + @@ -184,7 +184,7 @@ - + @@ -207,10 +207,10 @@ - + - + @@ -220,7 +220,7 @@ - + @@ -230,7 +230,7 @@ - + @@ -247,7 +247,7 @@ - + diff --git a/main/script.py b/main/script.py new file mode 100644 index 0000000..52c33cd --- /dev/null +++ b/main/script.py @@ -0,0 +1,210 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import QMainWindow +from .form import Ui_MainWindow +from util import * + + +class MainWindow(QMainWindow, Ui_MainWindow): + def __init__(self, parent=None): + from PyQt5.QtCore import Qt + QMainWindow.__init__(self, parent, flags=Qt.Window) + Ui_MainWindow.__init__(self) + self.ui = Ui_MainWindow() + self.ui.setupUi(self) + + self.file_path = "" + self.old_file = "" + self.lines = "" + self.owns_sc = False + self.owns_fr = False + self.owns_it = False + self.owns_ats = False + + self.ui.path_button.clicked.connect(self.open_save) + self.ui.apply.clicked.connect(self.apply_changes) + self.ui.backup.clicked.connect(self.recover_backup) + self.ui.second_window.clicked.connect(self.open_second_win) + + self.basic_edits = { + self.ui.money_edit: [self.ui.money_dont_change, "money_account:"], + self.ui.xp_edit: [self.ui.xp_dont_change, "experience_points:"], + self.ui.loan_limit_edit: [self.ui.loan_limit_dont_change, "loan_limit:"], + } + self.skill_edits = { + self.ui.long_distance_edit: [self.ui.long_distance_dont_change, "long_dist:"], + self.ui.high_value_cargo_edit: [self.ui.high_value_cargo_dont_change, "heavy:"], + self.ui.fragile_cargo_edit: [self.ui.fragile_cargo_dont_change, "fragile:"], + self.ui.urgent_delivery_edit: [self.ui.urgent_delivery_dont_change, "urgent:"], + self.ui.ecodriving_edit: [self.ui.ecodriving_dont_change, "mechanical:"], + } + + from PyQt5.QtCore import QRegExp + from PyQt5.QtGui import QRegExpValidator + # Money, exp, loan limit validators + rx_inf = QRegExp("[0-9]{1,9}") + validator_inf = QRegExpValidator(rx_inf) + for key in self.basic_edits.keys(): + key.setValidator(validator_inf) + # Skill validators + rx_skill = QRegExp("[0-6]{1,1}") + validator_skill = QRegExpValidator(rx_skill) + for key in self.skill_edits.keys(): + key.setValidator(validator_skill) + + @staticmethod + def get_adr(value): + bin_code = bin(int(value))[2:] + bin_code = "0" * (6 - len(bin_code)) + bin_code + r = [] + for i in bin_code: + r.append(i) + return r + + def open_second_win(self): + from second.script import SecondWindow + second_win = SecondWindow(self.lines, self.owns_sc, self.owns_fr, self.owns_it, self.owns_ats, self) + second_win.setModal(True) + second_win.show() + + def get_adr_from_line(self): + adr_list = list(self.ui.adr_edit.text()) + for i in adr_list: + if (i == " ") or (i == ",") or (i == "."): + adr_list.remove(i) + return adr_list + + def return_lines(self, lines): + self.lines = lines + return + + def open_save(self): + from PyQt5.QtWidgets import QFileDialog + file, _ = QFileDialog.getOpenFileName(parent=self, + caption=self.tr("Choose your save file..."), + filter=self.tr("game.sii"), # ;;Save file (*.sii) + initialFilter=self.tr("game.sii")) + self.reopen_file() + if file != "": + self.file_path = file + self.check_save_file(self.file_path) + else: + return + + def check_save_file(self, file): + try: + with open(file, "r") as f: + self.old_file = f.read() + except UnicodeDecodeError: + try: + from os import system + system("SII_Decrypt.exe --on_file -i \"{}\"".format(file)) + with open(file, "r") as f: + self.old_file = f.read() + show_message("Success", "File successfully decrypted.") + except UnicodeDecodeError: + show_message("Error", "Error to decrypt and open file. Try again.") + return + self.lines = self.old_file.split("\n") + for i in self.lines: + if "company.volatile.sag_tre.oslo" in i: + self.owns_sc = True + self.ui.owns_sc.setChecked(True) + if "company.volatile.lisette_log.roscoff" in i: + self.owns_fr = True + self.ui.owns_fr.setChecked(True) + if "company.volatile.marina_it.ancona" in i: + self.owns_it = True + self.ui.owns_it.setChecked(True) + if "company.volatile.gal_oil_gst.oakland" in i: + self.owns_ats = True + + for key, value in self.basic_edits.items(): + key.setText(str(getvalue(self.lines, searchline(self.lines, value[1])))) + + adr = self.get_adr(getvalue(self.lines, searchline(self.lines, "adr:"))) + adr_list = "" + for i in range(6): + if i != 5: + elem = adr[i] + "," + else: + elem = adr[i] + adr_list += elem + self.ui.adr_edit.setText(adr_list) + + for key, value in self.skill_edits.items(): + key.setText(str(getvalue(self.lines, searchline(self.lines, value[1])))) + + self.ui.apply.setEnabled(True) + self.ui.backup.setEnabled(True) + self.ui.second_window.setEnabled(True) + + def apply_changes(self): + if not self.ui.dont_change_all_inf.isChecked(): + for key, value in self.basic_edits.items(): + if not value[0].isChecked(): + setvalue(self.lines, searchline(self.lines, value[1]), str(key.text())) + value[1].setChecked(False) + if not self.ui.adr_dont_change.isChecked(): + adr_set = self.get_adr_from_line() + if len(adr_set) < 6: + show_message("Error", "ADR can't have less than 6 elements.") + elif len(adr_set) > 6: + show_message("Error", "ADR can't have more than 6 elements.") + else: + adr_new = int("".join(adr_set), 2) + setvalue(self.lines, searchline(self.lines, "adr:"), str(adr_new)) + for key, value in self.skill_edits.items(): + if not value[0].isChecked(): + setvalue(self.lines, searchline(self.lines, value[1]), str(key.text())) + value[1].setChecked(False) + backup = self.file_path + ".swbak" + with open(backup, "w") as f: + f.write(self.old_file) + with open(self.file_path, "w") as f: + f.write("\n".join(self.lines)) + show_message("Success", "Changes successfully applied!") + self.check_save_file(self.file_path) + return + + def recover_backup(self): + try: + backup = self.file_path + ".swbak" + f = open(backup, "r") + with open(self.file_path, "w") as g: + g.write(f.read()) + f.close() + from os import remove + remove(backup) + show_message("Success", "Backup successfully recovered.") + self.check_save_file(self.file_path) + except IOError: + show_message("Error", "Backup not found.") + return + + def reopen_file(self): + self.file_path = "" + self.old_file = "" + self.lines = "" + + self.owns_sc = False + self.owns_fr = False + self.owns_it = False + self.ui.owns_sc.setChecked(False) + self.ui.owns_fr.setChecked(False) + self.ui.owns_it.setChecked(False) + self.owns_ats = False + + for key, value in self.basic_edits.items(): + key.setText("") + value[0].setChecked(False) + + for key, value in self.skill_edits.items(): + key.setText("") + value[0].setChecked(False) + + self.ui.apply.setEnabled(False) + self.ui.backup.setEnabled(False) + self.ui.second_window.setEnabled(False) + return diff --git a/main_script.py b/main_script.py deleted file mode 100644 index 1cb20ab..0000000 --- a/main_script.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- - -from PyQt5.QtWidgets import QMainWindow -from main_form import * -from funcs import * - - -class MainWindow(QMainWindow, Ui_MainWindow): - # TODO: Constructor - def __init__(self, parent=None): - QMainWindow.__init__(self, parent) - Ui_MainWindow.__init__(self) - self.ui = Ui_MainWindow() - self.ui.setupUi(self) - self.funcs = Functions() - # - self.file_path = "" - self.oldfile = "" - self.lines = "" - self.ownsSC = False - self.ownsFR = False - self.ownsIT = False - self.ownsATS = False - # - self.ui.path_button.clicked.connect(self.openSave) - self.ui.apply.clicked.connect(self.applyChanges) - self.ui.backup.clicked.connect(self.recoverBackup) - self.ui.second_window.clicked.connect(self.openSecondWin) - # - from PyQt5.QtCore import QRegExp - from PyQt5.QtGui import QRegExpValidator - from wsgiref.validate import validator - rx_inf = QRegExp("[0-9]{1,9}") - validator_inf = QRegExpValidator(rx_inf) - self.ui.money_lineedit.setValidator(validator_inf) - self.ui.xp_lineedit.setValidator(validator_inf) - self.ui.loan_limit_lineedit.setValidator(validator_inf) - # - rx_skill = QRegExp("[0-6]{1,1}") - validator_skill = QRegExpValidator(rx_skill) - self.ui.long_distance_lineedit.setValidator(validator_skill) - self.ui.high_value_cargo_lineedit.setValidator(validator_skill) - self.ui.fragile_cargo_lineedit.setValidator(validator_skill) - self.ui.urgent_delivery_lineedit.setValidator(validator_skill) - self.ui.ecodriving_lineedit.setValidator(validator_skill) - - # TODO: Default functions - @staticmethod - def getADR(value): - bincode = bin(int(value))[2:] - bincode = "0" * (6 - len(bincode)) + bincode - r = [] - for i in bincode: - r.append(i) - return r - - # TODO: Custom functions - def openSecondWin(self): - from second_script import SecondWindow - sec_win = SecondWindow(self.lines, self.ownsSC, self.ownsFR, self.ownsIT, self.ownsATS, self) - sec_win.setModal(True) - sec_win.show() - - def getADRfromLineedit(self): - adr_list = list(self.ui.adr_lineedit.text()) - for i in adr_list: - if (i == " ") or (i == ",") or (i == "."): - adr_list.remove(i) - return adr_list - - def returnLines(self, lines): - self.lines = lines - return - - # TODO: Program functions - def openSave(self): - from PyQt5.QtWidgets import QFileDialog - file, _ = QFileDialog.getOpenFileName(parent=self, - caption=self.tr("Choose your save file..."), - filter=self.tr("game.sii"), # ;;Save file (*.sii) - initialFilter=self.tr("game.sii")) - self.reopen_file() - if file == "": - return - self.file_path = file - self.checkSaveFile(self.file_path) - - def checkSaveFile(self, file): - try: - with open(file, "r") as f: - self.oldfile = f.read() - except UnicodeDecodeError: - try: - from os import system - system("SII_Decrypt.exe --on_file -i \"{}\"".format(file)) - with open(file, "r") as f: - self.oldfile = f.read() - self.funcs.showMsgBox("Success", "File successfully decrypted.") - except UnicodeDecodeError: - self.funcs.showMsgBox("Error", "Error to decrypt and open file. Try again.") - return - self.lines = self.oldfile.split("\n") - for i in self.lines: - if "company.volatile.sag_tre.oslo" in i: - self.ownsSC = True - self.ui.owns_sc.setChecked(True) - if "company.volatile.lisette_log.roscoff" in i: - self.ownsFR = True - self.ui.owns_fr.setChecked(True) - if "company.volatile.marina_it.ancona" in i: - self.ownsIT = True - self.ui.owns_it.setChecked(True) - if "company.volatile.gal_oil_gst.oakland" in i: - self.ownsATS = True - self.checkAcc() - self.ui.apply.setEnabled(True) - self.ui.backup.setEnabled(True) - self.ui.second_window.setEnabled(True) - - def checkAcc(self): - self.ui.money_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "money_account:")))) - self.ui.xp_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "experience_points:")))) - self.ui.loan_limit_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "loan_limit:")))) - # - adr = self.getADR(self.funcs.getvalue(self.lines, self.funcs.searchline(self.lines, "adr:"))) - adr_list = "" - for i in range(6): - if i != 5: - elem = adr[i] + "," - else: - elem = adr[i] - adr_list += elem - self.ui.adr_lineedit.setText(adr_list) - # - self.ui.long_distance_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "long_dist:")))) - self.ui.high_value_cargo_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "heavy:")))) - self.ui.fragile_cargo_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "fragile:")))) - self.ui.urgent_delivery_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "urgent:")))) - self.ui.ecodriving_lineedit.setText(str(self.funcs.getvalue(self.lines, - self.funcs.searchline(self.lines, "mechanical:")))) - - def applyChanges(self): - if not self.ui.dont_change_all_inf.isChecked(): - self.applyChanges_1() - self.applyChanges_2() - backup = self.file_path + ".swbak" - with open(backup, "w") as f: - f.write(self.oldfile) - with open(self.file_path, "w") as f: - f.write("\n".join(self.lines)) - self.funcs.showMsgBox("Success", "Changes successfully applied!") - self.checkSaveFile(self.file_path) - return - - def applyChanges_1(self): - if not self.ui.money_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "money_account:"), - str(self.ui.money_lineedit.text())) - # - if not self.ui.xp_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "experience_points:"), - str(self.ui.xp_lineedit.text())) - # - if not self.ui.loan_limit_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "loan_limit:"), - str(self.ui.loan_limit_lineedit.text())) - # - self.ui.money_dont_change.setChecked(False) - self.ui.xp_dont_change.setChecked(False) - self.ui.loan_limit_dont_change.setChecked(False) - - def applyChanges_2(self): - if not self.ui.adr_dont_change.isChecked(): - adrset = self.getADRfromLineedit() - if len(adrset) > 6: - self.funcs.showMsgBox("Error", "ADR can't have more than 6 elements.") - else: - adrnew = int("".join(adrset), 2) - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "adr:"), - str(adrnew)) - # - if not self.ui.long_distance_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "long_dist:"), - str(self.ui.long_distance_lineedit.text())) - # - if not self.ui.high_value_cargo_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "heavy:"), - str(self.ui.high_value_cargo_lineedit.text())) - # - if not self.ui.fragile_cargo_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "fragile:"), - str(self.ui.fragile_cargo_lineedit.text())) - # - if not self.ui.urgent_delivery_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "urgent:"), - str(self.ui.urgent_delivery_lineedit.text())) - # - if not self.ui.ecodriving_dont_change.isChecked(): - self.funcs.setvalue(self.lines, - self.funcs.searchline(self.lines, "mechanical:"), - str(self.ui.ecodriving_lineedit.text())) - # - self.ui.adr_dont_change.setChecked(False) - self.ui.long_distance_dont_change.setChecked(False) - self.ui.high_value_cargo_dont_change.setChecked(False) - self.ui.fragile_cargo_dont_change.setChecked(False) - self.ui.urgent_delivery_dont_change.setChecked(False) - self.ui.ecodriving_dont_change.setChecked(False) - - def recoverBackup(self): - backup = self.file_path + ".swbak" - try: - f = open(backup, "r") - with open(self.file_path, "w") as g: - g.write(f.read()) - f.close() - from os import remove - remove(backup) - self.funcs.showMsgBox("Success", "Backup successfully recovered.") - self.checkSaveFile(self.file_path) - except IOError: - self.funcs.showMsgBox("Error", "Backup not found.") - return - - def reopen_file(self): - self.file_path = "" - self.oldfile = "" - self.lines = "" - # - self.ownsSC = False - self.ownsFR = False - self.ownsIT = False - self.ui.owns_sc.setChecked(False) - self.ui.owns_fr.setChecked(False) - self.ui.owns_it.setChecked(False) - self.ownsATS = False - # - self.ui.money_lineedit.setText("") - self.ui.money_dont_change.setChecked(False) - self.ui.xp_lineedit.setText("") - self.ui.xp_dont_change.setChecked(False) - self.ui.loan_limit_lineedit.setText("") - self.ui.loan_limit_dont_change.setChecked(False) - # - self.ui.adr_lineedit.setText("") - self.ui.adr_dont_change.setChecked(False) - self.ui.long_distance_lineedit.setText("") - self.ui.long_distance_dont_change.setChecked(False) - self.ui.high_value_cargo_lineedit.setText("") - self.ui.high_value_cargo_dont_change.setChecked(False) - self.ui.fragile_cargo_lineedit.setText("") - self.ui.fragile_cargo_dont_change.setChecked(False) - self.ui.urgent_delivery_lineedit.setText("") - self.ui.urgent_delivery_dont_change.setChecked(False) - self.ui.ecodriving_lineedit.setText("") - self.ui.ecodriving_dont_change.setChecked(False) - # - self.ui.apply.setEnabled(False) - self.ui.backup.setEnabled(False) - self.ui.second_window.setEnabled(False) - return diff --git a/second/__init__.py b/second/__init__.py new file mode 100644 index 0000000..4f5ab04 --- /dev/null +++ b/second/__init__.py @@ -0,0 +1 @@ +# initialize module 'second' for compile program \ No newline at end of file diff --git a/second_form.ui b/second/form.ui similarity index 97% rename from second_form.ui rename to second/form.ui index dc4923e..2fca2c5 100644 --- a/second_form.ui +++ b/second/form.ui @@ -261,7 +261,7 @@ - + @@ -318,7 +318,7 @@ - + @@ -372,7 +372,7 @@ - + @@ -426,7 +426,7 @@ - + @@ -480,7 +480,7 @@ - + diff --git a/second/script.py b/second/script.py new file mode 100644 index 0000000..6a67ae7 --- /dev/null +++ b/second/script.py @@ -0,0 +1,278 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import QDialog +from .form import Ui_SecondWindow +from util import * + + +class SecondWindow(QDialog, Ui_SecondWindow): + def __init__(self, lines, owns_sc, owns_fr, owns_it, owns_ats, parent=None): + from PyQt5.QtCore import Qt + QDialog.__init__(self, parent, flags=Qt.Window) + Ui_SecondWindow.__init__(self) + self.ui = Ui_SecondWindow() + self.ui.setupUi(self) + + self.lines = lines + self.owns_sc = owns_sc + self.owns_fr = owns_fr + self.owns_it = owns_it + self.owns_ats = owns_ats + + # Default dealers + self.dealers_ets2 = ["aberdeen", "amsterdam", "berlin", "bern", "birmingham", "bratislava", "bremen", "brussel", + "budapest", "calais", "cardiff", "dortmund", "dortmund", "dresden", "dusseldorf", + "edinburgh", "felixstowe", "frankfurt", "gdansk", "glasgow", "graz", "grimsby", "hamburg", + "hannover", "krakow", "leipzig", "lille", "london", "luxembourg", "manchester", "munchen", + "newcastle", "nurnberg", "osnabruck", "plymouth", "prague", "rostock", "rotterdam", + "salzburg", "strasbourg", "stuttgart", "szczecin", "szeged", "warszawa", "wien", "wroclaw", + "zurich"] + # SC dealers + self.dealers_ets2_sc = ["bergen", "goteborg", "kalmar", "kobenhavn", "linkoping", "oslo", "stockholm"] + # FR dealers + self.dealers_ets2_fr = ["bordeaux", "bourges", "brest", "geneve", "lemans", "limoges", "lyon", "marseille", + "nantes", "paris", "toulouse"] + # IT dealers + self.dealers_ets2_it = ["bologna", "catania", "firenze", "milano", "napoli", "palermo", "roma", "taranto", + "torino", "verona"] + # Default agnecies + self.agencies_ets2 = ["aberdeen", "berlin", "bialystok", "birmingham", "bremen", "brno", + "brussel", "budapest", "calais", "debrecen", "dortmund", "dover", "dresden", "edinburgh", + "frankfurt", "gdansk", "glasgow", "graz", "grohningen", "hamburg", "hannover", + "innsbruck", "kassel", "klagenfurt", "koln", "kosice", "krakow", "leipzig", "liege", + "linz", "liverpool", "lodz", "london", "luxembourg", "manchester", "mannheim", "munchen", + "newcastle", "nurnberg", "ostrava", "pecs", "plymouth", "poznan", "prague", "sheffield", + "southampton", "stuttgart", "swansea", "szczecin", "szeged", "warszava", "wien", "zurich"] + # SC agencies + self.agencies_ets2_sc = ["aalborg", "bergen", "helsingborg", "kobenhavn", "malmo", "odense", "oslo", + "stavanger", "stockholm"] + # FR agencies + self.agencies_ets2_fr = ["bordeaux", "clermont", "geneve", "larochelle", "lyon", "marseille", "metz", "paris", + "reims", "rennes", "toulouse"] + # IT agencies + self.agencies_ets2_it = ["bologna", "catania", "milano", "napoli", "pescara", "roma", "taranto", "venezia"] + # ATS dealers + self.dealers_ats = ["elko", "reno", "bakersfield", "phoenix", "flagstaff", "los_angeles", "albuquerque", + "hobbs"] + # ATS agencies + self.agencies_ats = ["redding", "san_rafael", "stockton", "fresno", "santa_cruz", "bakersfield", "oxnard", + "los_angeles", "san_diego", "carson_city", "las_vegas", "phoenix", "tucson", + "sierra_vista", "farmington", "santa_fe", "roswell", "carlsbad_nm"] + + self.ui.garage_size.addItem("Small") + self.ui.garage_size.addItem("Medium") + self.ui.garage_size.addItem("Big") + + self.ui.garages_analyze.clicked.connect(self.check_garages) + self.ui.garage_add.clicked.connect(self.add_garage) + self.ui.garage_unlock_all.clicked.connect(self.add_all_garages) + self.ui.headquarter_change.clicked.connect(self.change_headquarter) + self.ui.cities_analyze.clicked.connect(self.check_cities) + self.ui.city_add.clicked.connect(self.add_city) + self.ui.city_unlock_all.clicked.connect(self.add_all_cities) + self.ui.dealerships_analyze.clicked.connect(self.check_dealers) + self.ui.dealership_add.clicked.connect(self.add_dealer) + self.ui.dealership_unlock_all.clicked.connect(self.add_all_dealers) + self.ui.agencies_analyze.clicked.connect(self.check_agencies) + self.ui.agency_add.clicked.connect(self.add_agency) + self.ui.agency_unlock_all.clicked.connect(self.add_all_agencies) + + def check_garage_size(self): + text = str(self.ui.garage_size.currentText()) + garage_size = 0 + garage_status = 0 + if text == "Small": + garage_size = 1 + garage_status = 1 + elif text == "Medium": + garage_size = 3 + garage_status = 2 + elif text == "Big": + garage_size = 5 + garage_status = 3 + return garage_size, garage_status + + def purchased_garages(self): + garages = [] + i = 0 + try: + while True: + while "garage : " not in self.lines[i]: + i += 1 + city = match(r"garage : garage.(.+) {$", self.lines[i]).group(1) + while "status:" not in self.lines[i]: + i += 1 + if "0" not in self.lines[i]: + garages.append(city) + except: + pass + return garages + + def cities(self): + cities = [] + line = searchline(self.lines, "companies\[") + while "companies[" in self.lines[line]: + city = match(r" companies\[[0-9]+\]: company.volatile.[a-z0-9_]+[.]([a-z_]+)", self.lines[line]).group(1) + if city not in cities: + cities.append(city) + line += 1 + return cities + + def check_garages(self): + self.ui.garages_text.clear() + for e in self.purchased_garages(): + self.ui.garages_text.append(e) + hq = getvalue(self.lines, searchline(self.lines, "hq_city:")) + self.ui.headquarter_edit.setText(hq) + + def check_cities(self): + self.ui.cities_text.clear() + for i in getarrayitems(self.lines, searchline(self.lines, "visited_cities:")): + self.ui.cities_text.append(i) + if not getarrayitems(self.lines, searchline(self.lines, "visited_cities:")): + self.ui.cities_text.append("No cities visited yet.") + + def check_dealers(self): + self.dealers_ets2 = self.dealers_ets2 + self.dealers_ets2_sc if self.owns_sc else self.dealers_ets2 + self.dealers_ets2 = self.dealers_ets2 + self.dealers_ets2_fr if self.owns_fr else self.dealers_ets2 + self.dealers_ets2 = self.dealers_ets2 + self.dealers_ets2_it if self.owns_it else self.dealers_ets2 + self.ui.dealerships_text.clear() + for i in getarrayitems(self.lines, searchline(self.lines, "unlocked_dealers:")): + self.ui.dealerships_text.append(i) + if not getarrayitems(self.lines, searchline(self.lines, "unlocked_dealers:")): + self.ui.dealerships_text.append("No dealerships unlocked yet.") + + def check_agencies(self): + self.agencies_ets2 = self.agencies_ets2 + self.agencies_ets2_sc if self.owns_sc else self.agencies_ets2 + self.agencies_ets2 = self.agencies_ets2 + self.agencies_ets2_fr if self.owns_fr else self.agencies_ets2 + self.agencies_ets2 = self.agencies_ets2 + self.agencies_ets2_it if self.owns_it else self.agencies_ets2 + self.ui.agencies_text.clear() + for i in getarrayitems(self.lines, searchline(self.lines, "unlocked_recruitments:")): + self.ui.agencies_text.append(i) + if not getarrayitems(self.lines, searchline(self.lines, "unlocked_recruitments:")): + self.ui.agencies_text.append("No recruitment agencies unlocked yet.") + + def add_garage(self): + garage = str(self.ui.garage_edit.text()).lower() + if garage is "": + show_message("Error", "Enter a name for the city.") + return + garage_size, garage_status = self.check_garage_size() + self.ui.garage_edit.setText("") + if getvalue(self.lines, searchlineinunit(self.lines, "status:", "garage." + garage)) != "0": + show_message("Error", "Garage in \"{}\" already unlocked.".format(garage)) + else: + setvalue(self.lines, searchlineinunit(self.lines, "status:", "garage." + garage), str(garage_status)) + for i in range(garage_size): + addarrayvalue(self.lines, searchlineinunit(self.lines, "vehicles:", "garage." + garage), "null") + addarrayvalue(self.lines, searchlineinunit(self.lines, "drivers:", "garage." + garage), "null") + show_message("Success", "Garage in \"{}\" successfully unlocked.".format(garage)) + self.check_garages() + + def add_all_garages(self): + garage_size, garage_status = self.check_garage_size() + line = 0 + try: + while True: + line = searchline(self.lines, "garage : garage.", start=line) + if getvalue(self.lines, searchlineinunit(self.lines, "status:", getunitname(self.lines, line))) == "0": + setvalue(self.lines, searchlineinunit(self.lines, "status:", getunitname(self.lines, line)), + str(garage_status)) + for i in range(garage_size): + addarrayvalue(self.lines, searchlineinunit(self.lines, "vehicles:", + getunitname(self.lines, line)), "null") + addarrayvalue(self.lines, searchlineinunit(self.lines, "drivers:", + getunitname(self.lines, line)), "null") + line += 1 + except: + pass + show_message("Success", "All garages successfully unlocked.") + self.check_garages() + + def add_city(self): + city = str(self.ui.city_edit.text()).lower() + if city is "": + show_message("Error", "Enter a name for the city.") + return + self.ui.city_edit.setText("") + if city not in getarrayitems(self.lines, searchline(self.lines, "visited_cities:")): + addarrayvalue(self.lines, searchline(self.lines, "visited_cities:"), city) + addarrayvalue(self.lines, searchline(self.lines, "visited_cities_count:"), "1") + show_message("Success", "City \"{}\" successfully visited.".format(city)) + self.check_cities() + else: + show_message("Error", "You already visited \"{}\"".format(city)) + + def add_all_cities(self): + for city in self.cities(): + if city not in getarrayitems(self.lines, searchline(self.lines, "visited_cities:")): + addarrayvalue(self.lines, searchline(self.lines, "visited_cities:"), city) + addarrayvalue(self.lines, searchline(self.lines, "visited_cities_count:"), "1") + show_message("Success", "All cities successfully visited.") + self.check_cities() + + def add_dealer(self): + dealer = str(self.ui.dealership_edit.text()).lower() + if dealer is "": + show_message("Error", "Enter a name for the city.") + return + self.ui.dealership_edit.setText("") + if (not self.owns_ats and dealer not in self.dealers_ets2) or ( + self.owns_ats and dealer not in self.dealers_ats): + show_message("Error", "There is no dealership in that city.") + elif dealer in getarrayitems(self.lines, searchline(self.lines, "unlocked_dealers:")): + show_message("Error", "Dealership is already unlocked.") + else: + addarrayvalue(self.lines, searchline(self.lines, "unlocked_dealers:"), dealer) + show_message("Success", "Dealership in \"{}\" successfully unlocked.".format(dealer)) + self.check_dealers() + + def add_all_dealers(self): + for dealer in (self.dealers_ets2 if not self.owns_ats else self.dealers_ats): + if dealer in self.cities() and dealer not in getarrayitems(self.lines, + searchline(self.lines, "unlocked_dealers:")): + addarrayvalue(self.lines, searchline(self.lines, "unlocked_dealers:"), dealer) + show_message("Success", "All dealerships unlocked.") + self.check_dealers() + + def add_agency(self): + agency = str(self.ui.agency_edit.text()).lower() + if agency is "": + show_message("Error", "Enter a name for the city.") + return + self.ui.agency_edit.setText("") + if (not self.owns_ats and agency not in self.agencies_ets2) or ( + self.owns_ats and agency not in self.agencies_ats): + show_message("Error", "There is no recruitment agency in that city.") + elif agency in getarrayitems(self.lines, searchline(self.lines, "unlocked_recruitments:")): + show_message("Error", "Recruitment agency is already unlocked.") + else: + addarrayvalue(self.lines, searchline(self.lines, "unlocked_recruitments:"), agency) + show_message("Success", "Recruitment agency in \"{}\" successfully unlocked.".format(agency)) + self.check_agencies() + + def add_all_agencies(self): + for agency in (self.agencies_ets2 if not self.owns_ats else self.agencies_ats): + if agency in self.cities() and agency not in getarrayitems( + self.lines, searchline(self.lines, "unlocked_recruitments:")): + addarrayvalue(self.lines, searchline(self.lines, "unlocked_recruitments:"), agency) + show_message("Success", "All recruitment agencies unlocked.") + self.check_agencies() + + def change_headquarter(self): + hq = str(self.ui.headquarter_edit.text()).lower() + if hq is "": + show_message("Error", "Enter a name for the city.") + return + if getvalue(self.lines, searchline(self.lines, "hq_city:")) == hq: + show_message("Error", "Your headquarter is already in this city") + elif hq not in self.purchased_garages(): + show_message("Error", "You need to own the garage in this city.") + else: + setvalue(self.lines, searchline(self.lines, "hq_city:"), hq) + show_message("Success", "Headquarter successfully set to \"{}\".".format(hq)) + + def closeEvent(self, event): + from main.script import MainWindow + MainWindow().return_lines(self.lines) diff --git a/second_script.py b/second_script.py deleted file mode 100644 index 410a738..0000000 --- a/second_script.py +++ /dev/null @@ -1,332 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- - -from PyQt5.QtWidgets import QDialog -from second_form import * -from funcs import * - - -class SecondWindow(QDialog, Ui_SecondWindow): - # TODO: Constructor - def __init__(self, lines, ownsSC, ownsFR, ownsIT, ownsATS, parent=None): - QDialog.__init__(self, parent) - Ui_SecondWindow.__init__(self) - self.ui = Ui_SecondWindow() - self.ui.setupUi(self) - self.funcs = Functions() - # - self.lines = lines - self.ownsSC = ownsSC - self.ownsFR = ownsFR - self.ownsIT = ownsIT - self.ownsATS = ownsATS - # - self.dealersets2 = ["aberdeen", "amsterdam", "berlin", "bern", "birmingham", "bratislava", "bremen", "brussel", - "budapest", "calais", "cardiff", "dortmund", "dortmund", "dresden", "dusseldorf", "edinburgh", - "felixstowe", "frankfurt", "gdansk", "glasgow", "graz", "grimsby", "hamburg", "hannover", "krakow", - "leipzig", "lille", "london", "luxembourg", "manchester", "munchen", "newcastle", "nurnberg", - "osnabruck", "plymouth", "prague", "rostock", "rotterdam", "salzburg", "strasbourg", "stuttgart", - "szczecin", "szeged", "warszawa", "wien", "wroclaw", "zurich"] # Default dealers - self.dealersets2_sc = ["bergen", "goteborg", "kalmar", "kobenhavn", "linkoping", "oslo", "stockholm"] # SC dealers - self.dealersets2_fr = ["bordeaux", "bourges", "brest", "geneve", "lemans", "limoges", "lyon", "marseille", "nantes", - "paris", "toulouse"] # FR dealers - self.dealersets2_it = ["bologna", "catania", "firenze", "milano", "napoli", "palermo", "roma", "taranto", "torino", - "verona"] # IT dealers - # - self.agenciesets2 = ["aberdeen", "berlin", "bialystok", "birmingham", "bremen", "brno", - "brussel", "budapest", "calais", "debrecen", "dortmund", "dover", "dresden", "edinburgh", - "frankfurt", "gdansk", "glasgow", "graz", "grohningen", "hamburg", "hannover", "innsbruck", "kassel", - "klagenfurt", "koln", "kosice", "krakow", "leipzig", "liege", "linz", "liverpool", "lodz", "london", - "luxembourg", "manchester", "mannheim", "munchen", "newcastle", "nurnberg", "ostrava", "pecs", - "plymouth", "poznan", "prague", "sheffield", "southampton", "stuttgart", "swansea", "szczecin", - "szeged", "warszava", "wien", "zurich"] # Default agnecies - self.agenciesets2_sc = ["aalborg", "bergen", "helsingborg", "kobenhavn", "malmo", "odense", "oslo", "stavanger", - "stockholm"] # SC agencies - self.agenciesets2_fr = ["bordeaux", "clermont", "geneve", "larochelle", "lyon", "marseille", "metz", "paris", "reims", - "rennes", "toulouse"] # FR agencies - self.agenciesets2_it = ["bologna", "catania", "milano", "napoli", "pescara", "roma", "taranto", "venezia"] # IT agencies - # - self.dealersats = ["elko", "reno", "bakersfield", "phoenix", "flagstaff", "los_angeles", "albuquerque", "hobbs"] - self.agenciesats = ["redding", "san_rafael", "stockton", "fresno", "santa_cruz", "bakersfield", "oxnard", - "los_angeles", "san_diego", "carson_city", "las_vegas", "phoenix", "tucson", "sierra_vista", - "farmington", "santa_fe", "roswell", "carlsbad_nm"] - # - self.ui.garage_size.addItem("Small") - self.ui.garage_size.addItem("Medium") - self.ui.garage_size.addItem("Big") - # - self.ui.garages_analyze.clicked.connect(self.checkGarages) - self.ui.garage_add.clicked.connect(self.addGarage) - self.ui.garage_unlock_all.clicked.connect(self.addAllGarages) - self.ui.headquarter_change.clicked.connect(self.changeHQ) - self.ui.cities_analyze.clicked.connect(self.checkCities) - self.ui.city_add.clicked.connect(self.addCity) - self.ui.city_unlock_all.clicked.connect(self.addAllCities) - self.ui.dealerships_analyze.clicked.connect(self.checkDealers) - self.ui.dealership_add.clicked.connect(self.addDealership) - self.ui.dealership_unlock_all.clicked.connect(self.addAllDealership) - self.ui.agencies_analyze.clicked.connect(self.checkAgencies) - self.ui.agency_add.clicked.connect(self.addAgency) - self.ui.agency_unlock_all.clicked.connect(self.addAllAgency) - - # TODO: Custom functions - def check_gsize(self): - text = str(self.ui.garage_size.currentText()) - gsize = 0 - gstatus = 0 - if text == "Small": - gsize = 1 - gstatus = 1 - elif text == "Medium": - gsize = 3 - gstatus = 2 - elif text == "Big": - gsize = 5 - gstatus = 3 - return gsize, gstatus - - # TODO: Default functions - def purchasedgarages(self): - purchased_garages = [] - i = 0 - try: - while True: - while "garage : " not in self.lines[i]: - i += 1 - city = match(r"garage : garage.(.+) {$", self.lines[i]).group(1) - while "status:" not in self.lines[i]: - i += 1 - if "0" not in self.lines[i]: - purchased_garages.append(city) - except: - pass - return purchased_garages - - def cities(self): - cities = [] - line = self.funcs.searchline(self.lines, "companies\[") - while "companies[" in self.lines[line]: - city = match(r" companies\[[0-9]+\]: company.volatile.[a-z0-9_]+[.]([a-z_]+)", self.lines[line]).group(1) - if city not in cities: - cities.append(city) - line += 1 - return cities - - # TODO: Program functions - def checkGarages(self): - self.ui.garages_text.clear() - for e in self.purchasedgarages(): - self.ui.garages_text.append(e) - hq = self.funcs.getvalue(self.lines, self.funcs.searchline(self.lines, "hq_city:")) - self.ui.headquarter_lineedit.setText(hq) - - def checkCities(self): - self.ui.cities_text.clear() - for i in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "visited_cities:")): - self.ui.cities_text.append(i) - if not self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "visited_cities:")): - self.ui.cities_text.append("No cities visited yet.") - - def checkDealers(self): - if self.ownsSC: - self.dealersets2 += self.dealersets2_sc - if self.ownsFR: - self.dealersets2 += self.dealersets2_fr - if self.ownsIT: - self.dealersets2 += self.dealersets2_it - self.ui.dealerships_text.clear() - for i in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "unlocked_dealers:")): - self.ui.dealerships_text.append(i) - if not self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "unlocked_dealers:")): - self.ui.dealerships_text.append("No dealerships unlocked yet.") - - def checkAgencies(self): - if self.ownsSC: - self.agenciesets2 += self.agenciesets2_sc - if self.ownsFR: - self.agenciesets2 += self.agenciesets2_fr - if self.ownsIT: - self.agenciesets2 += self.agenciesets2_it - self.ui.agencies_text.clear() - for i in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:")): - self.ui.agencies_text.append(i) - if not self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:")): - self.ui.agencies_text.append("No recruitment agencies unlocked yet.") - - def addGarage(self): - garage = str(self.ui.garage_lineedit.text()).lower() - if garage is "": - self.funcs.showMsgBox("Error", "Enter a name for the city.") - return - gsize, gstatus = self.check_gsize() - self.ui.garage_lineedit.setText("") - if self.funcs.getvalue(self.lines, self.funcs.searchlineinunit(self.lines, "status:", "garage." + garage)) != "0": - self.funcs.showMsgBox("Error", "Garage in \"{}\" already unlocked.".format(garage)) - else: - self.funcs.setvalue(self.lines, - self.funcs.searchlineinunit(self.lines, "status:", "garage." + garage), - str(gstatus)) - for i in range(gsize): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchlineinunit(self.lines, "vehicles:", "garage." + garage), - "null") - self.funcs.addarrayvalue(self.lines, - self.funcs.searchlineinunit(self.lines, "drivers:", "garage." + garage), - "null") - self.funcs.showMsgBox("Success", "Garage in \"{}\" successfully unlocked.".format(garage)) - self.checkGarages() - - def addAllGarages(self): - gsize, gstatus = self.check_gsize() - line = 0 - try: - while True: - line = self.funcs.searchline(self.lines, "garage : garage.", start=line) - if self.funcs.getvalue(self.lines, - self.funcs.searchlineinunit(self.lines, "status:", - self.funcs.getunitname(self.lines, line))) == "0": - self.funcs.setvalue(self.lines, - self.funcs.searchlineinunit(self.lines, - "status:", self.funcs.getunitname(self.lines, line)), - str(gstatus)) - for i in range(gsize): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchlineinunit(self.lines, - "vehicles:", self.funcs.getunitname(self.lines, line)), - "null") - self.funcs.addarrayvalue(self.lines, - self.funcs.searchlineinunit(self.lines, - "drivers:", self.funcs.getunitname(self.lines, line)), - "null") - line += 1 - except: - pass - self.funcs.showMsgBox("Success", "All garages successfully unlocked.") - self.checkGarages() - - def addCity(self): - city = str(self.ui.city_lineedit.text()).lower() - if city is "": - self.funcs.showMsgBox("Error", "Enter a name for the city.") - return - self.ui.city_lineedit.setText("") - if city in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "visited_cities:")): - self.funcs.showMsgBox("Error", "You already visited \"{}\"".format(city)) - else: - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "visited_cities:"), - city) - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "visited_cities_count:"), - "1") - self.funcs.showMsgBox("Success", "City \"{}\" successfully visited.".format(city)) - self.checkCities() - - def addAllCities(self): - for city in self.cities(): - if city not in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "visited_cities:")): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "visited_cities:"), - city) - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "visited_cities_count:"), - "1") - self.funcs.showMsgBox("Success", "All cities successfully visited.") - self.checkCities() - - def addDealership(self): - dealer = str(self.ui.dealership_lineedit.text()).lower() - if dealer is "": - self.funcs.showMsgBox("Error", "Enter a name for the city.") - return - self.ui.dealership_lineedit.setText("") - if (not self.ownsATS and dealer not in self.dealersets2) or (self.ownsATS and dealer not in self.dealersats): - self.funcs.showMsgBox("Error", "There is no dealership in that city.") - elif dealer in self.funcs.getarrayitems(self.lines, self.funcs.searchline(self.lines, "unlocked_dealers:")): - self.funcs.showMsgBox("Error", "Dealership is already unlocked.") - else: - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_dealers:"), - dealer) - self.funcs.showMsgBox("Success", "Dealership in \"{}\" successfully unlocked.".format(dealer)) - self.checkDealers() - - def addAllDealership(self): - if not self.ownsATS: - for dealer in self.dealersets2: - if dealer in self.cities() and dealer not in self.funcs.getarrayitems( - self.lines, self.funcs.searchline(self.lines, "unlocked_dealers:")): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_dealers:"), - dealer) - else: - for dealer in self.dealersats: - if dealer in self.cities() and dealer not in self.funcs.getarrayitems( - self.lines, self.funcs.searchline(self.lines, "unlocked_dealers:")): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_dealers:"), - dealer) - self.funcs.showMsgBox("Success", "All dealerships unlocked.") - self.checkDealers() - - def addAgency(self): - agency = str(self.ui.agency_lineedit.text()).lower() - if agency is "": - self.funcs.showMsgBox("Error", "Enter a name for the city.") - return - self.ui.agency_lineedit.setText("") - if (not self.ownsATS and agency not in self.agenciesets2) or (self.ownsATS and agency not in self.agenciesats): - self.funcs.showMsgBox("Error", "There is no recruitment agency in that city.") - elif agency in self.funcs.getarrayitems(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:")): - self.funcs.showMsgBox("Error", "Recruitment agency is already unlocked.") - else: - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:"), - agency) - self.funcs.showMsgBox("Success", "Recruitment agency in \"{}\" successfully unlocked.".format(agency)) - self.checkAgencies() - - def addAllAgency(self): - if not self.ownsATS: - for agency in self.agenciesets2: - if agency in self.cities() and agency not in self.funcs.getarrayitems( - self.lines, self.funcs.searchline(self.lines, "unlocked_recruitments:")): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:"), - agency) - else: - for agency in self.agenciesats: - if agency in self.cities() and agency not in self.funcs.getarrayitems( - self.lines, self.funcs.searchline(self.lines, "unlocked_recruitments:")): - self.funcs.addarrayvalue(self.lines, - self.funcs.searchline(self.lines, "unlocked_recruitments:"), - agency) - self.funcs.showMsgBox("Success", "All recruitment agencies unlocked.") - self.checkAgencies() - - def changeHQ(self): - hq = str(self.ui.headquarter_lineedit.text()).lower() - if hq is "": - self.funcs.showMsgBox("Error", "Enter a name for the city.") - return - if self.funcs.getvalue(self.lines, self.funcs.searchline(self.lines, "hq_city:")) == hq: - self.funcs.showMsgBox("Error", "Your headquarter is already in this city") - elif hq not in self.purchasedgarages(): - self.funcs.showMsgBox("Error", "You need to own the garage in this city.") - else: - self.funcs.setvalue(self.lines, self.funcs.searchline(self.lines, "hq_city:"), hq) - self.funcs.showMsgBox("Success", "Headquarter successfully set to \"{}\".".format(hq)) - - # TODO: send self.lines to MainWindow() - def closeEvent(self, event): - from main_script import MainWindow - MainWindow().returnLines(self.lines) diff --git a/setup.py b/setup.py index f0d9314..b6244c7 100644 --- a/setup.py +++ b/setup.py @@ -3,26 +3,20 @@ from cx_Freeze import setup, Executable -executables = [Executable('__init__.py', - targetName="SaveWizard.exe", - base="Win32GUI")] - -excludes = ['email', 'html', 'http', 'logging', 'pydoc_data', 'unittest', 'urllib', 'xml', 'tempfile', 'select', 'datetime', - 'hashlib', 'shlex', 'shutil', 'socket', 'platform', 'webbrowser', 'pydoc', 'selectors', 'tty', 'inspect', 'doctest', - 'plistlib', 'calendar', 'subprocess', 'copy', 'bz2', 'stringprep', 'unicodedata', 'posixpath', 'dummy_threading', - '_strptime', 'pwd'] - -zip_include_packages = ['collections', 'encodings', 'importlib', 'PyQt5', 'sip', 'wsgiref'] - +executables = [Executable('__init__.py', targetName="SaveWizard.exe", base="Win32GUI")] +excludes = ['email', 'html', 'http', 'logging', 'pydoc_data', 'unittest', 'urllib', 'xml', 'tempfile', 'select', + 'datetime', 'hashlib', 'shlex', 'shutil', 'socket', 'platform', 'webbrowser', 'pydoc', 'selectors', 'tty', + 'inspect', 'doctest', 'plistlib', 'calendar', 'subprocess', 'copy', 'bz2', 'stringprep', 'posixpath', + 'dummy_threading', '_strptime', 'pwd'] +zip_include_packages = ['collections', 'encodings', 'importlib', 'PyQt5', 'sip', 'main', 'second'] include_files = ['SII_Decrypt.exe'] - options = { 'build_exe': { - 'include_msvcr': True, 'excludes': excludes, - 'zip_include_packages': zip_include_packages, + 'include_msvcr': True, + 'build_exe': 'stable_build', 'include_files': include_files, - 'build_exe': 'stable_build' + 'zip_include_packages': zip_include_packages, } } diff --git a/util.py b/util.py new file mode 100644 index 0000000..1e9527c --- /dev/null +++ b/util.py @@ -0,0 +1,101 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import QMessageBox +from re import search, match, sub + + +def show_message(title: str, text: str): + box = QMessageBox() + box.setWindowTitle(title) + box.setText(text) + box.exec_() + + +def searchline(lines, term, start=0, cancel=r"thisstringmustnotexist"): + if search(term, lines[start]): + return start + start += 1 + while start <= len(lines) - 1: + if search(term, lines[start]): + return start + if search(cancel, lines[start]): + return None + start += 1 + return None + + +def searchlineinunit(lines, term, unit): + line = searchline(lines, " : " + unit + " {") + return searchline(lines, term, start=line, cancel="}") + + +def searchalllines(lines, term): + matches = [] + start = 0 + while searchline(lines, term, start=start + 1): + start = searchline(lines, term, start=start + 1) + matches.append(start) + if matches is None: + return None + return matches + + +def getvalue(lines, line): + return search(r": (.+)$", lines[line]).group(1) + + +def setvalue(lines, line, value): + name = match(r"(.+):", lines[line]).group(1) + lines[line] = name + ": " + value + + +def getunitname(lines, line): + return search(r" : (.+) {$", lines[line]).group(1) + + +def getarraylength(lines, line): + return int(search(r": ([0-9]+)$", lines[line]).group(1)) + + +def getarrayvaluebyindex(lines, line, index): + return search(r": (.+)$", lines[line + index + 1]).group(1) + + +def getarrayindexbyvalue(lines, line, value): + count = 0 + for i in range(getarraylength(lines, line)): + if getvalue(lines, line + count + 1) == value: + return count + count += 1 + return None + + +def getarrayitems(lines, line): + items = [] + count = getarraylength(lines, line) + for i in range(count): + items.append(search(r": (.+)$", lines[line + i + 1]).group(1)) + if items is None: + return None + return items + + +def addarrayvalue(lines, line, value): + count = getarraylength(lines, line) + name = match(r"(.+):", lines[line]).group(1) + lines[line] = name + ": " + str(count + 1) + lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value) + + +def removearrayvalue(lines, line, value): + name = match(r"(.+):", lines[line]).group(1) + del lines[line + 1 + getarrayindexbyvalue(lines, line, value)] + lines[line] = name + ": " + str(getarraylength(lines, line) - 1) + for i in range(getarraylength(lines, line)): + lines[line + i + 1] = sub(r"\[[0-9]+\]", "[" + str(i) + "]", lines[line + i + 1]) + + +def changearrayvalue(lines, line, index, value): + line += index + 1 + setvalue(lines, line, value)