RuneOptimizer.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/usr/bin/env python
  2. """
  3. This file is part of RuneOptimizer.
  4. RuneOptimizer is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the Free
  6. Software Foundation, either version 3 of the License, or (at your option)
  7. any later version.
  8. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. You should have received a copy of the GNU General Public License along with
  13. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  14. """
  15. import wx
  16. import wx.grid
  17. import wx.adv
  18. import sqlite3
  19. import math
  20. import subprocess
  21. from subprocess import Popen, PIPE
  22. import json
  23. import os
  24. import pipes
  25. import appdirs
  26. import multiprocessing
  27. from types import SimpleNamespace
  28. from time import sleep
  29. # Include files
  30. classes_to_include = [
  31. '/gui/PanelUnits.py',
  32. '/gui/PanelTeams.py',
  33. '/gui/PanelOptimizer.py',
  34. '/gui/PanelResults.py',
  35. '/gui/PanelInfo.py',
  36. '/gui/RuneOptimizerFrame.py',
  37. '/gui/TabList.py',
  38. '/gui/DialogConfirm.py',
  39. '/gui/DialogUpdateJson.py',
  40. '/gui/DialogNewTeam.py',
  41. '/entity/RuneStat.py',
  42. '/entity/Rune.py',
  43. '/entity/StatSet.py',
  44. '/entity/UnitTeam.py',
  45. '/entity/Unit.py',
  46. '/entity/Team.py',
  47. ]
  48. for cls in classes_to_include:
  49. exec(
  50. compile(
  51. source=open(os.path.dirname(os.path.realpath(__file__)) + cls).read(),
  52. filename=os.path.dirname(os.path.realpath(__file__)) + cls,
  53. mode='exec'
  54. )
  55. )
  56. # The path to the RuneOptimizer executable. Different in Windows.
  57. executable_path = \
  58. os.path.dirname(os.path.realpath(__file__)) + '/../RuneOptimizer'
  59. if os.name == 'nt':
  60. executable_path = \
  61. os.path.dirname(os.path.realpath(__file__)) + '\..\RuneOptimizer.exe'
  62. # App information
  63. app_info = {
  64. "name": "Rune Optimizer",
  65. "app_version": "UNKNOWN",
  66. "gui_version": "0.1-RC1",
  67. "author": "Iñigo Valentin",
  68. "author_mail": "i@inigovalentin.com",
  69. "url": {
  70. "Home page": "https://inigovalentin.com/projects/RuneOptimizer/",
  71. "Source code": "https://github.com/InigoValentin/RuneOptimizer/"
  72. }
  73. }
  74. # Global database connection
  75. conn = None
  76. RUNE_STATS = {
  77. "HP": 1, "HP_P": 2, "ATK": 3, "ATK_P": 4, "DEF": 5, "DEF_P": 6,
  78. "SPD": 8, "CRR": 9, "CRD": 10, "RES": 11, "ACC": 12
  79. }
  80. # Unit stat names, indexed with Com2Us values.
  81. STAT_NAMES = [
  82. "NULL", "HP ", "HP% ", "ATK ", "ATK%", "DEF ",
  83. "DEF%", "NULL", "SPD ", "CRR ", "CRD ", "RES ", "ACC "
  84. ]
  85. # Rune set names, indexed with Com2Us values.
  86. SET_NAMES = [
  87. "NULL", "ENERGY", "GUARD", "SWIFT", "BLADE", "RAGE", # 0- 5
  88. "FOCUS", "ENDURE", "FATAL", "NULL", "DESPAIR", "VAMPIRE", # 6-11
  89. "NULL", "VIOLENT", "NEMESIS", "WILL", "SHIELD", "REVENGE", # 12-17
  90. "DESTROY", "FIGHT", "DETERMIN", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23
  91. ]
  92. # TODO: Work in progress...
  93. """
  94. # Rune set names, indexed with Com2Us values.
  95. SET_SYMBOLS = [
  96. "NULL", "ENERGY", "GUARD", "SWIFT", "ᚬ", "ᛟ", # 0- 5
  97. "FOCUS", "ENDURE", "FATAL", "NULL", "ᛃ", "VAMPIRE", # 6-11
  98. "NULL", "ᛒ", "NEMESIS", "WILL", "SHIELD", "ᛝ", # 12-17
  99. "DESTROY", "FIGHT", "ᛗ", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23
  100. ]
  101. SET_SYMBOLS_UNICODE = [
  102. "NULL", "ENERGY", "GUARD", "SWIFT", "\u16AC", "\u16DF", # 0- 5
  103. "FOCUS", "ENDURE", "FATAL", "NULL", "\u16C3", "VAMPIRE", # 6-11
  104. "NULL", "\u16D2", "NEMESIS", "WILL", "SHIELD", "\u16DD", # 12-17
  105. "DESTROY", "FIGHT", "\u16D7", "ENHANCE", "ACCURACY", "TOLERANCE" # 18-23
  106. ]
  107. """
  108. QUALITY_NAMES = [
  109. "NULL",
  110. "NORMAL", "MAGIC", "RARE", "HERO", "LEGEND"
  111. "NULL", "NULL", "NULL", "NULL", "NULL", "NULL",
  112. "A.NORMAL", "A.MAGIC", "A.RARE", "A.HERO", "A.LEGEND"
  113. ]
  114. units = {}
  115. teams = {}
  116. def reload_units():
  117. # Get all the units, sorted by priority desc
  118. global units
  119. global conn
  120. units = {}
  121. cursor = conn.execute("""
  122. SELECT
  123. id,
  124. (
  125. SELECT sum(priority)
  126. FROM teams
  127. WHERE id IN (SELECT team FROM units_teams WHERE unit = units.id)
  128. ) AS prio
  129. FROM units
  130. ORDER BY prio DESC;
  131. """)
  132. rows = cursor.fetchall()
  133. for row in rows:
  134. units[str(row[0])] = Unit(str(row[0]))
  135. def reload_teams():
  136. # Get all the teams, sorted by priority desc
  137. global teams
  138. global conn
  139. teams = {}
  140. cursor = conn.execute("SELECT id FROM teams ORDER BY priority DESC;")
  141. rows = cursor.fetchall()
  142. for row in rows:
  143. teams[str(row[0])] = Team(str(row[0]))
  144. if __name__ == '__main__':
  145. """
  146. Main function.
  147. Conects to the database and shows the initial frame.
  148. """
  149. #Get CLI app version
  150. # TODO: Change executable name for windows
  151. #if os.name == 'nt':
  152. app_info["app_version"] = subprocess.check_output(
  153. ['RuneOptimizer', 'version']
  154. )
  155. # TODO: Test for executable to exist
  156. # TODO: Test for database to exist
  157. # Open the database
  158. conn = sqlite3.connect(
  159. appdirs.user_data_dir("RuneOptimizer") + "/data.sqlite"
  160. )
  161. reload_units()
  162. reload_teams()
  163. # Start the GUI
  164. app = wx.App()
  165. frm = RuneOptimizerFrame(
  166. parent=None, title='Rune Optimizer', pos=(100, 100), size=(1000, 650)
  167. )
  168. frm.Show()
  169. app.MainLoop()