Fix some dist issues

This commit is contained in:
Evan Pratten 2022-03-21 13:26:07 -04:00
parent a904dfc451
commit 7843b92418
7 changed files with 158 additions and 7 deletions

2
.gitignore vendored
View File

@ -27,7 +27,7 @@ __pycache__/
.Python .Python
build/ build/
develop-eggs/ develop-eggs/
dist/ /dist/
downloads/ downloads/
eggs/ eggs/
.eggs/ .eggs/

View File

@ -4,6 +4,8 @@ import os
from PIL import Image from PIL import Image
import json import json
import logging import logging
import time
import getpass
from typing import List from typing import List
from project_root import get_project_root from project_root import get_project_root
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -26,12 +28,12 @@ def check_sprite_exists(sprite_type: str, sprite_name: str) -> bool:
# Build the path the sprite should exist in # Build the path the sprite should exist in
sprite_path = os.path.join( sprite_path = os.path.join(
project_root, "game", "dist", "anm", sprite_type, f"{sprite_type}_{sprite_name}") project_root, "game", "dist", "assets", "anm", sprite_type, f"{sprite_type}_{sprite_name}")
return os.path.isdir(sprite_path) return os.path.isdir(sprite_path)
def stitch_images_and_write_to_disk(sprite_type: str, sprite_name: str, images: List[str]) -> None: def stitch_images_and_write_to_disk(sprite_type: str, sprite_name: str, images: List[str], quantize: bool) -> None:
# Load all the images # Load all the images
images_to_stitch = [] images_to_stitch = []
@ -57,14 +59,17 @@ def stitch_images_and_write_to_disk(sprite_type: str, sprite_name: str, images:
# Save the new image # Save the new image
project_root = get_project_root() project_root = get_project_root()
logger.debug(f"Project root: {project_root}") logger.debug(f"Project root: {project_root}")
if quantize:
new_image = new_image.quantize(method=2) new_image = new_image.quantize(method=2)
new_image.save(os.path.join(project_root, "game", "dist", "anm", sprite_type, new_image.save(os.path.join(project_root, "game", "dist", "assets", "anm", sprite_type,
f"{sprite_type}_{sprite_name}", f"{sprite_type}_{sprite_name}.png")) f"{sprite_type}_{sprite_name}", f"{sprite_type}_{sprite_name}.png"))
# Build some JSON metadata # Build some JSON metadata
metadata = { metadata = {
"sheet_height": max_height, "sheet_height": max_height,
"sheet_width": total_width, "sheet_width": total_width,
"published_at": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()),
"published_by": getpass.getuser(),
"frames": [] "frames": []
} }
@ -80,6 +85,6 @@ def stitch_images_and_write_to_disk(sprite_type: str, sprite_name: str, images:
x_offset += image.size[0] x_offset += image.size[0]
# Write the metadata to disk # Write the metadata to disk
with open(os.path.join(project_root, "game", "dist", "anm", sprite_type, with open(os.path.join(project_root, "game", "dist", "assets", "anm", sprite_type,
f"{sprite_type}_{sprite_name}", f"{sprite_type}_{sprite_name}.anim_meta.json"), "w") as f: f"{sprite_type}_{sprite_name}", f"{sprite_type}_{sprite_name}.anim_meta.json"), "w") as f:
json.dump(metadata, f, indent=4) json.dump(metadata, f, indent=4)

View File

@ -74,6 +74,17 @@ class AnimStitcherWindow(QtWidgets.QWidget):
self.sprite_name_layout.addWidget(self.sprite_name_input) self.sprite_name_layout.addWidget(self.sprite_name_input)
self.layout().addLayout(self.sprite_name_layout) self.layout().addLayout(self.sprite_name_layout)
# Add a selection option for the sprite optimization
self.optimization_layout = QtWidgets.QHBoxLayout()
self.optimization_label = QtWidgets.QLabel("Optimize For")
self.optimization_layout.addWidget(self.optimization_label)
self.optimization_dropdown = QtWidgets.QComboBox()
self.optimization_dropdown.addItem("Size")
self.optimization_dropdown.addItem("Quality")
self.optimization_dropdown.setEnabled(False)
self.optimization_layout.addWidget(self.optimization_dropdown)
self.layout().addLayout(self.optimization_layout)
# Add a seperator # Add a seperator
self.layout().addWidget(qt_lines.QHLine()) self.layout().addWidget(qt_lines.QHLine())
@ -110,6 +121,7 @@ class AnimStitcherWindow(QtWidgets.QWidget):
self.sprite_type_dropdown.setEnabled(True) self.sprite_type_dropdown.setEnabled(True)
self.sprite_name_input.setEnabled(True) self.sprite_name_input.setEnabled(True)
self.stitch_button.setEnabled(True) self.stitch_button.setEnabled(True)
self.optimization_dropdown.setEnabled(True)
# Save the selected files # Save the selected files
self.selected_files = file_dialog.selectedFiles() self.selected_files = file_dialog.selectedFiles()
@ -157,7 +169,7 @@ class AnimStitcherWindow(QtWidgets.QWidget):
# Perform the actual stitching action # Perform the actual stitching action
stitcher.stitch_images_and_write_to_disk( stitcher.stitch_images_and_write_to_disk(
sprite_type, sprite_name, self.selected_files) sprite_type, sprite_name, self.selected_files, self.optimization_dropdown.currentText() == "Size")
# Close the window # Close the window
self.close() self.close()

View File

View File

@ -0,0 +1,116 @@
{
"sheet_height": 1080,
"sheet_width": 34560,
"published_at": "2022-03-21 17:25:40",
"published_by": "ewpratten",
"frames": [
{
"x": 0,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 1920,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 3840,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 5760,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 7680,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 9600,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 11520,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 13440,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 15360,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 17280,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 19200,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 21120,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 23040,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 24960,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 26880,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 28800,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 30720,
"y": 0,
"width": 1920,
"height": 1080
},
{
"x": 32640,
"y": 0,
"width": 1920,
"height": 1080
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 KiB

18
game/dist/known-sprite-types.json vendored Normal file
View File

@ -0,0 +1,18 @@
[
{
"short": "chr",
"friendly": "Character"
},
{
"short": "env",
"friendly": "Environment"
},
{
"short": "prp",
"friendly": "Prop"
},
{
"short": "cut",
"friendly": "Cutscene"
}
]