From 4f5f16fc75ab820d666c2ce5aac0ba9aba6f5e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sat, 29 Jun 2024 17:21:22 +0300 Subject: [PATCH] d --- v5/desktop.py | 59 ++++++++++++++++++++++++++++++++------------ v5/main-gui.py | 9 +++++-- v5/memory_Context.py | 2 ++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/v5/desktop.py b/v5/desktop.py index 505088c..bbfcfdd 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -1,21 +1,6 @@ import arcade from desktop_Platform import * -def desktop_loadTextures(p): - texs = [] - for (id, td) in enumerate(p.c.textureDescriptions): - tex = arcade.load_texture( - td.fileName, - x = td.x, - y = td.y, - width = td.width, - height = td.height - ) - texs.append(tex) - #} - p.textures = texs -#} - def desktop_createDeselectedTiles(p): for (id, pos) in enumerate(p.c.tilePositions): tile = arcade.AnimatedTimeBasedSprite() @@ -51,6 +36,21 @@ def desktop_createSelectedTiles(p): #} #} +# Deselect mismatched tiles +# +# Conditions: +# 1. Time to deselect mismatched items +def desktop_deselectMismatchedTiles(p): + if ( + p.c.recentField == "deselectMismatchedTiles" + ): + for id in p.c.mismatchedItems: + p.deselectedTiles[id].visible = True + p.selectedTiles[id].visible = False + #} + #} +#} + # Hide deselected tile and show selected one # # Conditions: @@ -73,13 +73,40 @@ def desktop_hideMatchingTiles(p): if ( p.c.recentField == "hideMatchingTiles" ): - for id in p.c.hiddenItems: + for id in p.c.selectedItems: p.deselectedTiles[id].visible = False p.selectedTiles[id].visible = False #} #} #} +def desktop_loadTextures(p): + texs = [] + for (id, td) in enumerate(p.c.textureDescriptions): + tex = arcade.load_texture( + td.fileName, + x = td.x, + y = td.y, + width = td.width, + height = td.height + ) + texs.append(tex) + #} + p.textures = texs +#} + +# Postpone deselection of mismatched tiles for better UX +# +# Conditions: +# 1. a pair of tiles has been mismatched +def desktop_scheduleDeselectionOfMismatchedTiles(p): + if ( + p.c.recentField == "mismatchedItems" + ): + p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay) + #} +#} + # Postpone hiding of matching tiles for better UX # # Conditions: diff --git a/v5/main-gui.py b/v5/main-gui.py index 4df07a1..2887b41 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -85,19 +85,24 @@ p.ctrl = ctrl p.sequentialTimer = desktop_SequentialTimer() p.sequentialTimer.callback = lambda key, value: ctrl.set(key, value) -# Copy context to platform. -# And process lots of functions that are interested in changes. +# Bind platform to context changes. def process(c): + # Copy context to platform. p.c = c + # Perform context dependent calls of desktop functions. + # Similar to context functions, but no platform is returned. + desktop_deselectMismatchedTiles(p) desktop_displaySelectedTile(p) desktop_hideMatchingTiles(p) desktop_scheduleHidingOfMatchingTiles(p) + desktop_scheduleDeselectionOfMismatchedTiles(p) ctrl.registerCallback(process) ctrl.set("didLaunch", True) ctrl.set("playfieldSize", 2) ctrl.set("cellSize", 25) +ctrl.set("deselectMismatchedTilesDelay", 500) ctrl.set("hideMatchingTilesDelay", 500) ctrl.set("tileImage", "res/tiles.png") ctrl.set("tileImageCount", 3) diff --git a/v5/memory_Context.py b/v5/memory_Context.py index 8c4dead..6db7343 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -1,6 +1,8 @@ class memory_Context: def __init__(self): self.cellSize = 0 + self.deselectMismatchedTiles = False + self.deselectMismatchedTilesDelay = 0 self.didLaunch = False self.exit = False self.hiddenItems = []