Skip to content

Commit

Permalink
Improve character id search
Browse files Browse the repository at this point in the history
  • Loading branch information
joaorb64 committed Oct 25, 2023
1 parent 9306950 commit 3b65cde
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/TSHGameAssetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, parent=None) -> None:

self.skinLoaderLock = QMutex()

self.startgg_id_to_character = {}

def UiMounted(self):
self.DownloadStartGGCharacters()
self.LoadGames()
Expand All @@ -57,7 +59,8 @@ def run(self):
r_json = json.loads(r.text)
r_json = json.dumps(r_json, indent=2)

open('./assets/characters.json.tmp', 'wt', encoding="utf-8").write(r_json)
open('./assets/characters.json.tmp',
'wt', encoding="utf-8").write(r_json)

try:
# Test if downloaded JSON is valid
Expand All @@ -74,7 +77,8 @@ def run(self):
except:
logger.error("Characters file download failed")
except Exception as e:
logger.error("Could not update /assets/characters.json: "+str(e))
logger.error(
"Could not update /assets/characters.json: "+str(e))
thread = DownloaderThread(self)
thread.start()

Expand Down Expand Up @@ -121,7 +125,8 @@ def run(self):
self.parent().games[game]["assets"][dir] = \
json.load(f)
else:
logger.error("No config file for "+game+" - "+dir)
logger.error(
"No config file for "+game+" - "+dir)

# Load translated names
# Translate game name
Expand Down Expand Up @@ -301,7 +306,7 @@ def run(self):
heights[assetsKey].append(
size.height())
logger.info("Character "+c+" has " +
str(len(self.parent().skins[c]))+" skins")
str(len(self.parent().skins[c]))+" skins")

# Set average size
for assetsKey in list(gameObj.get("assets", {}).keys()):
Expand Down Expand Up @@ -568,6 +573,14 @@ def UpdateCharacterModel(self):
self.characterModel.appendRow(item)

self.characterModel.sort(0)

# Setup startgg chacter id to character name
sggcharacters = json.loads(
open('./assets/characters.json', 'r').read())
self.startgg_id_to_character = {}

for c in sggcharacters.get("entities", {}).get("character", []):
self.startgg_id_to_character[str(c.get("id"))] = c
except:
logger.error(traceback.format_exc())

Expand Down Expand Up @@ -960,11 +973,7 @@ def GetCharacterAssets(self, characterCodename: str, skin: int, assetpack: str =
return (charFiles)

def GetCharacterFromStartGGId(self, smashgg_id: int):
sggcharacters = json.loads(
open('./assets/characters.json', 'r').read())

startggcharacter = next((c for c in sggcharacters.get("entities", {}).get(
"character", []) if str(c.get("id")) == str(smashgg_id)), None)
startggcharacter = self.startgg_id_to_character.get(str(smashgg_id))

if startggcharacter:
character = next((c for c in self.characters.items() if c[1].get(
Expand Down

0 comments on commit 3b65cde

Please sign in to comment.