Skip to content

Commit

Permalink
fix up freeplay icons
Browse files Browse the repository at this point in the history
  • Loading branch information
tposejank committed May 26, 2024
1 parent ac53ca7 commit 530ef67
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
39 changes: 28 additions & 11 deletions psychtobase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# Main

charts = []
characterMap = {
# 'charactr': 'Name In English'
}
vocalSplitMasterToggle = True

def folderMake(folder_path):
Expand Down Expand Up @@ -197,6 +200,10 @@ def convert(psych_mod_folder, result_folder, options):

converted_char.convert()
converted_char.save()
# For THOSE
fileBasename = converted_char.iconID.replace('icon-', '')
characterMap[fileBasename] = converted_char.characterName
logging.info(f'Saved {converted_char.characterName} to character map using their icon id: {fileBasename}.')
else:
logging.warn(f'{character} is a directory, or not a json! Skipped')

Expand Down Expand Up @@ -225,17 +232,27 @@ def convert(psych_mod_folder, result_folder, options):

destination = f'{result_folder}/{modFoldername}{bgCharacterAssets}{filename}'
fileCopy(character, destination)
# Woah, freeplay icons
logging.getLogger('PIL').setLevel(logging.INFO)
with Image.open(character) as img:
# Get the winning/normal half of icons
normal_half = img.crop((0, 0, 150, 150))
# Scale to 50x50, same size as BF and GF pixel icons
pixel_img = normal_half.resize((50, 50), Image.Resampling.NEAREST)
pixel_name = filename[5:-4] + 'pixel' + filename[-4:]
freeplay_destination = f'{result_folder}/{modFoldername}{freeplayDir}/{pixel_name}'
pixel_img.save(freeplay_destination)
logging.info(f'Saving converted freeplay icon to {freeplay_destination}')
keyForThisIcon = filename.replace('icon-', '').replace('.png', '')
logging.info('Checking if ' + keyForThisIcon + ' is in the characterMap')

if characterMap.get(keyForThisIcon, None) != None:
try:
# Woah, freeplay icons
logging.getLogger('PIL').setLevel(logging.INFO)
with Image.open(character) as img:
# Get the winning/normal half of icons
normal_half = img.crop((0, 0, 150, 150))
# Scale to 50x50, same size as BF and GF pixel icons
pixel_img = normal_half.resize((50, 50), Image.Resampling.NEAREST)


pixel_name = characterMap.get(keyForThisIcon) + 'pixel.png'

freeplay_destination = f'{result_folder}/{modFoldername}{freeplayDir}/{pixel_name}'
pixel_img.save(freeplay_destination)
logging.info(f'Saving converted freeplay icon to {freeplay_destination}')
except Exception as ___exc:
logging.error(f"Failed to create character {keyForThisIcon}'s freeplay icon: {___exc}")
except Exception as e:
logging.error(f'Could not copy asset {character}: {e}')
else:
Expand Down
3 changes: 3 additions & 0 deletions psychtobase/src/tools/CharacterTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def __init__(self, path: str, resultPath) -> None:
self.character:dict = copy.deepcopy(Constants.CHARACTER)
self.characterName:str = None

self.iconID:str = None

self.loadCharacter()

def loadCharacter(self):
Expand All @@ -34,6 +36,7 @@ def convert(self):
# self.character['scale'] = char['scale']
self.character['isPixel'] = char['scale'] >= 6
self.character['healthIcon']['id'] = char['healthicon']
self.iconID = char['healthicon']
self.character['healthIcon']['isPixel'] = char['scale'] >= 6
self.character['flipX'] = char.get('flip_x', False)

Expand Down
4 changes: 3 additions & 1 deletion psychtobase/src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def __init__(self):

self.icons = QCheckBox("Health Icons", self)
self.icons.move(sSX, _currentYPos)
self.icons.setToolTip("Copies over all of your character icon .png files from the \"/images/icons/\" directory of your mod. This also generates Freeplay Icons.")
self.icons.setToolTip("Copies over all of your character icon .png files from the \"/images/icons/\" directory of your mod. This also generates Freeplay Icons (These require characters enabled).")

_currentYPos += 20

self.jsons = QCheckBox(".json files", self)
self.jsons.move(sSX, _currentYPos)
Expand Down

0 comments on commit 530ef67

Please sign in to comment.