From 6fbf369d3eb94ce2bb040dba402d92d9e439d36d Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Wed, 18 Oct 2023 12:48:35 +0100 Subject: [PATCH] Bug fix * Fixed sorting of numbered doll layers starting with double digits --- game/scripts/doll/clothes.rpy | 4 ++-- game/scripts/utility/common_functions.rpy | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/game/scripts/doll/clothes.rpy b/game/scripts/doll/clothes.rpy index 58453dd6..16be4c1f 100644 --- a/game/scripts/doll/clothes.rpy +++ b/game/scripts/doll/clothes.rpy @@ -69,7 +69,7 @@ init python: salt = str( [self.name, self.char.pose, self.type, self.id, str(self.color), str(self.char.body._hash)] ) return hash(salt) - @functools.cache + @functools.cache # <- TODO: Reevaluate if this function should allow multiple caches (aside from different subpaths) def get_layers(self, hash, subpath=""): path = posixpath.join(self.modpath, "characters", self.name, "poses", self.char.pose, subpath, "clothes", self.type, self.id) @@ -130,7 +130,7 @@ init python: else: layers.setdefault(ltype, [f, zorder]) - return layers + return dict(sorted(layers.items(), key=lambda x: (extract_number(x[0]), x[0]))) @functools.cache def build_image(self, hash, subpath="", matrix=None, maxsize=(1010, 1200)): diff --git a/game/scripts/utility/common_functions.rpy b/game/scripts/utility/common_functions.rpy index 20eefb75..cfe66436 100644 --- a/game/scripts/utility/common_functions.rpy +++ b/game/scripts/utility/common_functions.rpy @@ -224,4 +224,10 @@ init python early: return len(self._callable()) def execute_callbacks(callbacks): - for callback in callbacks: callback() \ No newline at end of file + for callback in callbacks: callback() + + def extract_number(key): + match = re.match(r'^(\d+)', key) + if match: + return int(match.group(1)) + return float('inf') # Return a large number for non-numeric keys