From 574cc65c59e5689bc4f2ca2a4da6ded0d9e2d6a5 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 10:06:34 +0300 Subject: [PATCH] d --- v5/desktop.py | 42 +++++++++++++++++++++++++++++++++++ v5/desktop_Platform.py | 1 + v5/desktop_SequentialTimer.py | 10 +++++++++ v5/desktop_aux.py | 5 +++-- v5/main-gui.py | 10 ++++++--- v5/memory_Context.py | 1 + 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 v5/desktop_SequentialTimer.py diff --git a/v5/desktop.py b/v5/desktop.py index efd21bb..4c8b9ad 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -50,3 +50,45 @@ def desktop_createSelectedTiles(p): tile.visible = False #} #} + +# Hide deselected tile and show selected one +# +# Conditions: +# 1. tile has just been selected +def desktop_displaySelectedTile(p): + if ( + p.c.recentField == "selectedId" + ): + id = p.c.selectedId + p.deselectedTiles[id].visible = False + p.selectedTiles[id].visible = True + #} +#} + +# Postpone hiding of matching tiles for better UX +# +# Conditions: +# 1. a pair of tiles has been matched +def desktop_scheduleHidingOfMatchingTiles(p): + if ( + p.c.recentField == "hiddenItems" + ): + p.sequentialTimer.schedule("hideMatchingTiles", True, 500) + #} +#} + +# Hide matching tiles +# TODO: Rearrange the position of the func +# +# Conditions: +# 1. ... +#def desktop_hideMatchingTiles(p): +# if ( +# p.c.recentField == "hiddenItems" +# ): +# for id in p.c.hiddenItems: +# p.deselectedTiles[id].visible = False +# p.selectedTiles[id].visible = False +# #} +# #} +##} diff --git a/v5/desktop_Platform.py b/v5/desktop_Platform.py index e4f6143..ab81b5a 100644 --- a/v5/desktop_Platform.py +++ b/v5/desktop_Platform.py @@ -7,5 +7,6 @@ class desktop_Platform: self.deselectedTiles = [] self.mousePosition = [] self.selectedTiles = [] + self.sequentialTimer = None self.sprites = arcade.SpriteList() self.textures = [] diff --git a/v5/desktop_SequentialTimer.py b/v5/desktop_SequentialTimer.py new file mode 100644 index 0000000..9a5eb02 --- /dev/null +++ b/v5/desktop_SequentialTimer.py @@ -0,0 +1,10 @@ +class desktop_SequentialTimer(): + def __init__(self): + self.queue = [] + + def update(self): + pass + + def schedule(self, key, value, timeout): + pass + diff --git a/v5/desktop_aux.py b/v5/desktop_aux.py index 17bbe97..83d9ad9 100644 --- a/v5/desktop_aux.py +++ b/v5/desktop_aux.py @@ -1,10 +1,11 @@ import arcade -# Find tile id at the specified location +# Find a visible tile id at the specified location def desktop_aux_tileIdAt(p, x, y): sprites = arcade.get_sprites_at_point([x, y], p.sprites) if ( - len(sprites) != 0 + len(sprites) != 0 and + sprites[0].visible ): return sprites[0].guid #} diff --git a/v5/main-gui.py b/v5/main-gui.py index 310776a..08cd009 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -5,6 +5,7 @@ from ctx import * from ctx_test2 import * from desktop import * from desktop_Platform import * +from desktop_SequentialTimer import * from desktop_Window import * from gui import * from gui_aux_test import * @@ -81,13 +82,16 @@ ctrl.registerCallback(printOutput) ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) p = desktop_Platform() -# Keep copy of ctrl in platform, too. p.ctrl = ctrl +p.sequentialTimer = desktop_SequentialTimer() # Copy context to platform. -def copyContext(c): +# And process lots of functions that are interested in changes. +def process(c): p.c = c -ctrl.registerCallback(copyContext) + desktop_displaySelectedTile(p) + desktop_scheduleHidingOfMatchingTiles(p) +ctrl.registerCallback(process) ctrl.set("didLaunch", True) ctrl.set("playfieldSize", 2) diff --git a/v5/memory_Context.py b/v5/memory_Context.py index db806cc..982c874 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -4,6 +4,7 @@ class memory_Context: self.didLaunch = False self.exit = False self.hiddenItems = [] + self.hideMatchingTiles = False self.input = "" self.mismatchedItems = [] self.outputGoOn = ""