Skip to content

Commit

Permalink
prepare for release build
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth-Revz committed Nov 10, 2024
1 parent 0d703cf commit 90a6a61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__pycache__
atlas/
.venv
.venv

pokatlas.spec
build/
dist/
27 changes: 22 additions & 5 deletions pokatlas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import pathlib
import shutil
import sys
import zipfile
from collections import Counter
from textwrap import dedent
Expand Down Expand Up @@ -116,7 +117,7 @@ def rebuild(atlas: Atlas):

canvas.save(output_dir / atlas.img_name)

def export_mod_full(atlas: Atlas):
def export_mod_full(atlas: Atlas, icon_path: pathlib.Path):
rebuild(atlas)

atlas_dir = atlas.atlas_path.parent
Expand Down Expand Up @@ -162,15 +163,15 @@ def export_mod_full(atlas: Atlas):
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<resource author="Me" description="Created with Pokatlas" name="MyAtlas" version="1" weblink=""/>"""
)

shutil.copy('ui/icon.png', str(pathlib.Path(mod_dir / 'icon.png')))
shutil.copy(icon_path, str(pathlib.Path(mod_dir / 'icon.png')))

with zipfile.ZipFile(str(output_dir / 'FullAtlas.mod'), 'w') as zipf:
for file_path in mod_dir.rglob('*'):
if file_path.is_file():
zipf.write(file_path, arcname=file_path.relative_to(mod_dir))


def export_mod_modified(atlas: Atlas):
def export_mod_modified(atlas: Atlas, icon_path: pathlib.Path):
atlas_dir = atlas.atlas_path.parent
sprites_dir = atlas_dir / 'sprites'
output_dir = atlas.atlas_path.parent / 'output'
Expand Down Expand Up @@ -235,20 +236,36 @@ def export_mod_modified(atlas: Atlas):
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<resource author="Me" description="Created with Pokatlas" name="MyAtlas" version="1" weblink=""/>"""
)

shutil.copy('ui/icon.png', str(pathlib.Path(mod_dir / 'icon.png')))
shutil.copy(icon_path, str(pathlib.Path(mod_dir / 'icon.png')))

with zipfile.ZipFile(str(output_dir / 'PartialAtlas.mod'), 'w') as zipf:
for file_path in mod_dir.rglob('*'):
if file_path.is_file():
zipf.write(file_path, arcname=file_path.relative_to(mod_dir))

def resource_path(relative: pathlib.Path):
try:
base_path = pathlib.Path(sys._MEIPASS)
except Exception:
base_path = pathlib.Path('.')

return base_path / relative

if __name__ == '__main__':
from ui.mainwindow import MainWindow
from PySide6.QtWidgets import QApplication
import qdarktheme

try:
from ctypes import windll
windll.shell32.SetCurrentProcessExplicitAppUserModelID('com.revz.pokatlas')
except ImportError:
pass

icon_path = resource_path(pathlib.Path('ui/icon.png'))

app = QApplication()
qdarktheme.setup_theme('dark')
mainwindow = MainWindow()
mainwindow = MainWindow(icon_path=icon_path)
mainwindow.show()
app.exec()
11 changes: 6 additions & 5 deletions ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@ def icon(self, _):
return QIcon()

class MainWindow(QMainWindow):
def __init__(self):
def __init__(self, icon_path: pathlib.Path):
super().__init__()
self.atlas_dir = None
self.sprites_dir = None
self.output_dir = None
self.atlas = None
self.icon_path = icon_path

self.selected_sprite_filename = None

self.setupUI()

def setupUI(self):
self.setWindowIcon(QIcon('./ui/icon.png'))
self.setWindowIcon(QIcon(str(self.icon_path)))
self.setWindowTitle('Pokatlas')
self.setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT)

Expand Down Expand Up @@ -305,11 +306,11 @@ def saveAtlas(self):

def saveFullMod(self):
check_duplicates(self.atlas)
export_mod_full(self.atlas)
export_mod_full(self.atlas, self.icon_path)
self.openDirectory(self.output_dir)

def saveModifiedMod(self):
export_mod_modified(self.atlas)
export_mod_modified(self.atlas, self.icon_path)
self.openDirectory(self.output_dir)

def searchList(self, text):
Expand Down Expand Up @@ -372,7 +373,7 @@ def openSpriteFolder(self):

def replaceMultipleSprites(self):
msgbox = QMessageBox()
msgbox.setWindowIcon(QIcon('./ui/icon.png'))
msgbox.setWindowIcon(QIcon(str(self.icon_path)))
msgbox.setWindowTitle('Warning')
msgbox.setText('Matching Sprite File Names' + ' '*30)
msgbox.setInformativeText('Only files in the selected folder with names matching the dumped sprites will be replaced.')
Expand Down

0 comments on commit 90a6a61

Please sign in to comment.