From 42b97cf1ede527c46b31a6b4a5f676e3b1fecb1f Mon Sep 17 00:00:00 2001 From: Joe R Date: Sun, 6 Feb 2022 18:20:14 -0500 Subject: [PATCH] Fix for preview bottoms and undo in Cruel. --- pysollib/games/bakersdozen.py | 22 ++++++++----- pysollib/images.py | 58 +++++++++++++++++------------------ pysollib/ui/tktile/tkutil.py | 12 ++++++++ 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/pysollib/games/bakersdozen.py b/pysollib/games/bakersdozen.py index 0bd44140..6875dd8a 100644 --- a/pysollib/games/bakersdozen.py +++ b/pysollib/games/bakersdozen.py @@ -31,6 +31,7 @@ from pysollib.stack import \ AC_FoundationStack, \ AC_RowStack, \ InitialDealTalonStack, \ + InvisibleStack, \ RK_RowStack, \ SS_FoundationStack, \ SS_RowStack, \ @@ -55,6 +56,8 @@ class CastlesInSpain(Game): Hint_Class = CautiousDefaultHint Solver_Class = FreeCellSolverWrapper() + GAME_VERSION = 2 + # # game layout # @@ -73,6 +76,7 @@ class CastlesInSpain(Game): for r in l.s.rows: s.rows.append(self.RowStack_Class(r.x, r.y, self)) # default + self.s.internals.append(InvisibleStack(self)) l.defaultAll() return l @@ -218,18 +222,20 @@ class Cruel_Talon(TalonStack): for r in rows: for i in range(len(r.cards)): num_cards = num_cards + 1 - self.game.moveMove(1, r, self, frames=0) - assert len(self.cards) == num_cards + self.game.moveMove(1, r, self.game.s.internals[0], frames=0) - temp_cards = [] - while len(self.cards) > 0: - temp = self.cards[:4] - temp_cards = temp + temp_cards - del self.cards[:4] - self.cards = temp_cards.copy() + if len(self.game.s.internals[0].cards) % 4 != 0: + self.game.moveMove(len(self.game.s.internals[0].cards) % 4, + self.game.s.internals[0], self, frames=0) + + while len(self.game.s.internals[0].cards) > 0: + self.game.moveMove(4, self.game.s.internals[0], self, frames=0) + + assert len(self.cards) == num_cards if num_cards == 0: # game already finished return 0 + # redeal in packs of 4 cards self.game.nextRoundMove(self) n, i = num_cards, 0 diff --git a/pysollib/images.py b/pysollib/images.py index 7a3c2790..2b2b1245 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -189,35 +189,35 @@ class Images: if progress: progress.update(step=1) - if not USE_PIL: - # load bottoms - for i in range(self.cs.nbottoms): - name = "bottom%02d" % (i + 1) - bottom = self.__loadBottom(name, color='black') - if bottom is not None: - self._bottom_positive.append(bottom) - if progress: - progress.update(step=pstep) - # load negative bottoms - name = "bottom%02d-n" % (i + 1) - bottom = self.__loadBottom(name, color='white') - if bottom is not None: - self._bottom_negative.append(bottom) - if progress: - progress.update(step=pstep) - # load letters - for rank in range(self.cs.nletters): - name = "l%02d" % (rank + 1) - self._letter_positive.append( - self.__loadBottom(name, color='black')) - if progress: - progress.update(step=pstep) - # load negative letters - name = "l%02d-n" % (rank + 1) - self._letter_negative.append( - self.__loadBottom(name, color='white')) - if progress: - progress.update(step=pstep) + # todo - fix duplication of loading bottoms + # load bottoms + for i in range(self.cs.nbottoms): + name = "bottom%02d" % (i + 1) + bottom = self.__loadBottom(name, color='black') + if bottom is not None: + self._bottom_positive.append(bottom) + if progress: + progress.update(step=pstep) + # load negative bottoms + name = "bottom%02d-n" % (i + 1) + bottom = self.__loadBottom(name, color='white') + if bottom is not None: + self._bottom_negative.append(bottom) + if progress: + progress.update(step=pstep) + # load letters + for rank in range(self.cs.nletters): + name = "l%02d" % (rank + 1) + self._letter_positive.append( + self.__loadBottom(name, color='black')) + if progress: + progress.update(step=pstep) + # load negative letters + name = "l%02d-n" % (rank + 1) + self._letter_negative.append( + self.__loadBottom(name, color='white')) + if progress: + progress.update(step=pstep) # shadow if not USE_PIL: diff --git a/pysollib/ui/tktile/tkutil.py b/pysollib/ui/tktile/tkutil.py index efdcd580..9d904f12 100644 --- a/pysollib/ui/tktile/tkutil.py +++ b/pysollib/ui/tktile/tkutil.py @@ -289,6 +289,18 @@ def masking(image): image = image.convert("RGBA") # make sure it has alphachannel mask = image.copy() + + # calculate median transparency value + # this will determine if the masking will have a significant + # effect on performance. + transparency = [row[3] for row in image.getdata()] + n = len(transparency) + s = sorted(transparency) + median = (s[n // 2 - 1] / 2.0 + s[n // 2] / 2.0, s[n // 2])[n % 2] + + if median > 0: + return image + # important alpha must be bigger than 0 mask.putalpha(1) mask.paste(image, (0, 0), image)