| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #!/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 <https://www.gnu.org/licenses/>.
- """
- 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()
|