Михаил Капелько 5 months ago
parent
commit
8b084f8737
5 changed files with 50 additions and 20 deletions
  1. +17
    -17
      v5/desktop.py
  2. +28
    -3
      v5/desktop_SequentialTimer.py
  3. +1
    -0
      v5/desktop_Window.py
  4. +3
    -0
      v5/main-gui.py
  5. +1
    -0
      v5/memory_Context.py

+ 17
- 17
v5/desktop.py View File

@@ -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 # Postpone hiding of matching tiles for better UX
# #
# Conditions: # Conditions:
@@ -73,22 +89,6 @@ def desktop_scheduleHidingOfMatchingTiles(p):
if ( if (
p.c.recentField == "hiddenItems" 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
# #}
# #}
##}

+ 28
- 3
v5/desktop_SequentialTimer.py View File

@@ -1,10 +1,35 @@
import time

class desktop_SequentialTimer(): class desktop_SequentialTimer():
def __init__(self): def __init__(self):
self.activeTimeout = None
self.ctrl = None
self.queue = [] self.queue = []
#}


def update(self): 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): def schedule(self, key, value, timeout):
pass
self.queue.append([timeout, key, value])
#}

+ 1
- 0
v5/desktop_Window.py View File

@@ -25,3 +25,4 @@ class desktop_Window(arcade.Window):


def on_update(self, delta): def on_update(self, delta):
self.p.sprites.update_animation() self.p.sprites.update_animation()
self.p.sequentialTimer.update()

+ 3
- 0
v5/main-gui.py View File

@@ -84,12 +84,14 @@ ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))
p = desktop_Platform() p = desktop_Platform()
p.ctrl = ctrl p.ctrl = ctrl
p.sequentialTimer = desktop_SequentialTimer() p.sequentialTimer = desktop_SequentialTimer()
p.sequentialTimer.ctrl = ctrl


# Copy context to platform. # Copy context to platform.
# And process lots of functions that are interested in changes. # And process lots of functions that are interested in changes.
def process(c): def process(c):
p.c = c p.c = c
desktop_displaySelectedTile(p) desktop_displaySelectedTile(p)
desktop_hideMatchingTiles(p)
desktop_scheduleHidingOfMatchingTiles(p) desktop_scheduleHidingOfMatchingTiles(p)
ctrl.registerCallback(process) ctrl.registerCallback(process)


@@ -97,6 +99,7 @@ ctrl.set("didLaunch", True)
ctrl.set("playfieldSize", 2) ctrl.set("playfieldSize", 2)


ctrl.set("cellSize", 25) ctrl.set("cellSize", 25)
ctrl.set("hideMatchingTilesDelay", 500)
ctrl.set("tileImage", "res/tiles.png") ctrl.set("tileImage", "res/tiles.png")
ctrl.set("tileImageCount", 3) ctrl.set("tileImageCount", 3)
ctrl.set("tileImageHeight", 100) ctrl.set("tileImageHeight", 100)


+ 1
- 0
v5/memory_Context.py View File

@@ -5,6 +5,7 @@ class memory_Context:
self.exit = False self.exit = False
self.hiddenItems = [] self.hiddenItems = []
self.hideMatchingTiles = False self.hideMatchingTiles = False
self.hideMatchingTilesDelay = 0
self.input = "" self.input = ""
self.mismatchedItems = [] self.mismatchedItems = []
self.outputGoOn = "" self.outputGoOn = ""


Loading…
Cancel
Save