#!/usr/bin/env python """ This file is part of RuneOptimizer. RuneOptimizer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RuneOptimizer. If not, see . """ import wx import wx.grid import wx.adv import sqlite3 import math import subprocess from subprocess import Popen, PIPE import json import os import pipes import appdirs import multiprocessing from types import SimpleNamespace from time import sleep # Include files classes_to_include = [ '/gui/PanelUnits.py', '/gui/PanelTeams.py', '/gui/PanelOptimizer.py', '/gui/PanelResults.py', '/gui/PanelInfo.py', '/gui/RuneOptimizerFrame.py', '/gui/TabList.py', '/gui/DialogConfirm.py', '/gui/DialogUpdateJson.py', '/gui/DialogNewTeam.py', '/entity/RuneStat.py', '/entity/Rune.py', '/entity/StatSet.py', '/entity/UnitTeam.py', '/entity/Unit.py', '/entity/Team.py', ] for cls in classes_to_include: exec( compile( source=open(os.path.dirname(os.path.realpath(__file__)) + cls).read(), filename=os.path.dirname(os.path.realpath(__file__)) + cls, mode='exec' ) ) # The path to the RuneOptimizer executable. Different in Windows. executable_path = \ os.path.dirname(os.path.realpath(__file__)) + '/../RuneOptimizer' if os.name == 'nt': executable_path = \ os.path.dirname(os.path.realpath(__file__)) + '\..\RuneOptimizer.exe' # App information app_info = { "name": "Rune Optimizer", "app_version": "UNKNOWN", "gui_version": "0.1-RC1", "author": "Iñigo Valentin", "author_mail": "i@inigovalentin.com", "url": { "Home page": "https://inigovalentin.com/projects/RuneOptimizer/", "Source code": "https://github.com/InigoValentin/RuneOptimizer/" } } # Global database connection conn = None RUNE_STATS = { "HP": 1, "HP_P": 2, "ATK": 3, "ATK_P": 4, "DEF": 5, "DEF_P": 6, "SPD": 8, "CRR": 9, "CRD": 10, "RES": 11, "ACC": 12 } # Unit stat names, indexed with Com2Us values. STAT_NAMES = [ "NULL", "HP ", "HP% ", "ATK ", "ATK%", "DEF ", "DEF%", "NULL", "SPD ", "CRR ", "CRD ", "RES ", "ACC " ] # Rune set names, indexed with Com2Us values. SET_NAMES = [ "NULL", "ENERGY", "GUARD", "SWIFT", "BLADE", "RAGE", # 0- 5 "FOCUS", "ENDURE", "FATAL", "NULL", "DESPAIR", "VAMPIRE", # 6-11 "NULL", "VIOLENT", "NEMESIS", "WILL", "SHIELD", "REVENGE", # 12-17 "DESTROY", "FIGHT", "DETERMIN", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23 ] # TODO: Work in progress... """ # Rune set names, indexed with Com2Us values. SET_SYMBOLS = [ "NULL", "ENERGY", "GUARD", "SWIFT", "ᚬ", "ᛟ", # 0- 5 "FOCUS", "ENDURE", "FATAL", "NULL", "ᛃ", "VAMPIRE", # 6-11 "NULL", "ᛒ", "NEMESIS", "WILL", "SHIELD", "ᛝ", # 12-17 "DESTROY", "FIGHT", "ᛗ", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23 ] SET_SYMBOLS_UNICODE = [ "NULL", "ENERGY", "GUARD", "SWIFT", "\u16AC", "\u16DF", # 0- 5 "FOCUS", "ENDURE", "FATAL", "NULL", "\u16C3", "VAMPIRE", # 6-11 "NULL", "\u16D2", "NEMESIS", "WILL", "SHIELD", "\u16DD", # 12-17 "DESTROY", "FIGHT", "\u16D7", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23 ] """ QUALITY_NAMES = [ "NULL", "NORMAL", "MAGIC", "RARE", "HERO", "LEGEND" "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "A.NORMAL", "A.MAGIC", "A.RARE", "A.HERO", "A.LEGEND" ] units = {} teams = {} def reload_units(): # Get all the units, sorted by priority desc global units global conn units = {} cursor = conn.execute(""" SELECT id, ( SELECT sum(priority) FROM teams WHERE id IN (SELECT team FROM units_teams WHERE unit = units.id) ) AS prio FROM units ORDER BY prio DESC; """) rows = cursor.fetchall() for row in rows: units[str(row[0])] = Unit(str(row[0])) def reload_teams(): # Get all the teams, sorted by priority desc global teams global conn teams = {} cursor = conn.execute("SELECT id FROM teams ORDER BY priority DESC;") rows = cursor.fetchall() for row in rows: teams[str(row[0])] = Team(str(row[0])) if __name__ == '__main__': """ Main function. Conects to the database and shows the initial frame. """ #Get CLI app version # TODO: Change executable name for windows #if os.name == 'nt': app_info["app_version"] = subprocess.check_output( ['RuneOptimizer', 'version'] ) # TODO: Test for executable to exist # TODO: Test for database to exist # Open the database conn = sqlite3.connect( appdirs.user_data_dir("RuneOptimizer") + "/data.sqlite" ) reload_units() reload_teams() # Start the GUI app = wx.App() frm = RuneOptimizerFrame( parent=None, title='Rune Optimizer', pos=(100, 100), size=(1000, 650) ) frm.Show() app.MainLoop()