From 8b084f8737b16af617521e034609975fd290177e 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 13:42:06 +0300 Subject: [PATCH] d --- v5/desktop.py | 34 +++++++++++++++++----------------- v5/desktop_SequentialTimer.py | 31 ++++++++++++++++++++++++++++--- v5/desktop_Window.py | 1 + v5/main-gui.py | 3 +++ v5/memory_Context.py | 1 + 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/v5/desktop.py b/v5/desktop.py index 4c8b9ad..2cd5338 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -65,6 +65,22 @@ def desktop_displaySelectedTile(p): #} #} +# Hide matching tiles +# +# Conditions: +# 1. Time to hide matching items +def desktop_hideMatchingTiles(p): + print(f"desktop_hideMT recentF: '{p.c.recentField}'") + if ( + p.c.recentField == "hideMatchingTiles" + ): + for id in p.c.hiddenItems: + p.deselectedTiles[id].visible = False + p.selectedTiles[id].visible = False + #} + #} +#} + # Postpone hiding of matching tiles for better UX # # Conditions: @@ -73,22 +89,6 @@ def desktop_scheduleHidingOfMatchingTiles(p): if ( p.c.recentField == "hiddenItems" ): - p.sequentialTimer.schedule("hideMatchingTiles", True, 500) + p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay) #} #} - -# 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_SequentialTimer.py b/v5/desktop_SequentialTimer.py index 9a5eb02..ae687c4 100644 --- a/v5/desktop_SequentialTimer.py +++ b/v5/desktop_SequentialTimer.py @@ -1,10 +1,35 @@ +import time + class desktop_SequentialTimer(): def __init__(self): + self.activeTimeout = None + self.ctrl = None self.queue = [] + #} def update(self): - pass + # Get current time in milliseconds. + now = time.time_ns() // 1000000 + + # Schedule an item. + if ( + self.activeTimeout == None and + len(self.queue) > 0 + ): + self.activeTimeout = now + self.queue[0][0] + elif ( + self.activeTimeout != None and + now >= self.activeTimeout + ): + # Report when the time is up. + key = self.queue[0][1] + value = self.queue[0][2] + self.queue.pop(0) + self.activeTimeout = None + self.ctrl.set(key, value) + #} + #} def schedule(self, key, value, timeout): - pass - + self.queue.append([timeout, key, value]) + #} diff --git a/v5/desktop_Window.py b/v5/desktop_Window.py index 7ca0ebd..b44d461 100644 --- a/v5/desktop_Window.py +++ b/v5/desktop_Window.py @@ -25,3 +25,4 @@ class desktop_Window(arcade.Window): def on_update(self, delta): self.p.sprites.update_animation() + self.p.sequentialTimer.update() diff --git a/v5/main-gui.py b/v5/main-gui.py index 08cd009..abc4620 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -84,12 +84,14 @@ ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) p = desktop_Platform() p.ctrl = ctrl p.sequentialTimer = desktop_SequentialTimer() +p.sequentialTimer.ctrl = ctrl # Copy context to platform. # And process lots of functions that are interested in changes. def process(c): p.c = c desktop_displaySelectedTile(p) + desktop_hideMatchingTiles(p) desktop_scheduleHidingOfMatchingTiles(p) ctrl.registerCallback(process) @@ -97,6 +99,7 @@ ctrl.set("didLaunch", True) ctrl.set("playfieldSize", 2) ctrl.set("cellSize", 25) +ctrl.set("hideMatchingTilesDelay", 500) ctrl.set("tileImage", "res/tiles.png") ctrl.set("tileImageCount", 3) ctrl.set("tileImageHeight", 100) diff --git a/v5/memory_Context.py b/v5/memory_Context.py index 982c874..8c4dead 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -5,6 +5,7 @@ class memory_Context: self.exit = False self.hiddenItems = [] self.hideMatchingTiles = False + self.hideMatchingTilesDelay = 0 self.input = "" self.mismatchedItems = [] self.outputGoOn = ""