From df259c151116319ffb1700f4e054b495a6159fcb 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: Wed, 26 Jun 2024 23:40:33 +0300 Subject: [PATCH] d --- v5/desktop.py | 8 ----- v5/desktop_Platform.py | 6 ---- v5/desktop_Window.py | 10 +++--- v5/gui.py | 70 ++++++++++++++++++++++++++---------------- v5/gui_aux.py | 46 +++++++++++++++++++++++++++ v5/gui_aux_test.py | 15 +++++++++ v5/main-gui.py | 11 ++++++- v5/memory_Context.py | 5 +++ 8 files changed, 124 insertions(+), 47 deletions(-) create mode 100644 v5/gui_aux.py create mode 100644 v5/gui_aux_test.py diff --git a/v5/desktop.py b/v5/desktop.py index 5e1ddc2..7172dff 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -1,14 +1,6 @@ import arcade from desktop_Platform import * -def desktop_configureFixedWindow(p): - p.cell = 25 - p.windowAntialiasing = False - p.windowHeight = 600 - p.windowTitle = "OGS Memory" - p.windowWidth = 900 -#} - def desktop_loadTextures(p): texs = [] for (id, td) in enumerate(p.c.textureDescriptions): diff --git a/v5/desktop_Platform.py b/v5/desktop_Platform.py index e20374b..327f55a 100644 --- a/v5/desktop_Platform.py +++ b/v5/desktop_Platform.py @@ -3,11 +3,5 @@ import arcade class desktop_Platform: def __init__(self): self.c = None - self.cell = 0 self.sprites = arcade.SpriteList() self.textures = [] - self.windowAntialiasing = False - self.windowBackgroundColor = arcade.color.WHITE - self.windowHeight = 0 - self.windowTitle = "" - self.windowWidth = 0 diff --git a/v5/desktop_Window.py b/v5/desktop_Window.py index 9112cc9..238f08e 100644 --- a/v5/desktop_Window.py +++ b/v5/desktop_Window.py @@ -3,12 +3,12 @@ import arcade class desktop_Window(arcade.Window): def __init__(self, p): super().__init__( - p.windowWidth, - p.windowHeight, - p.windowTitle, + p.c.windowWidth, + p.c.windowHeight, + p.c.windowTitle, ) - self.antialiasing = p.windowAntialiasing - arcade.set_background_color(p.windowBackgroundColor) + self.antialiasing = p.c.windowAntialiasing + self.background_color = arcade.color_from_hex_string(p.c.windowBackgroundColor) self.p = p def on_draw(self): diff --git a/v5/gui.py b/v5/gui.py index 0caa118..dc7e8d5 100644 --- a/v5/gui.py +++ b/v5/gui.py @@ -1,18 +1,22 @@ -from memory_Context import * +from gui_aux import * from gui_TextureDescription import * from llm import * +from memory_Context import * -# Generate tile position +# Generate textures descriptions # # Conditions: -# 1. +# 1. tileImage or tileImageCount or tileImageHeight or tileImageWidth has just changed +# 2. tileImage, tileImageCount, tileImageHeight, tileImageWidth are not empty @llm_by_value -def gui_generateTilePositions( +def gui_generateTextureDescriptions( c: memory_Context ) -> memory_Context: if ( - c.recentField == "windowHeight" or - c.recentField == "windowWidth" + c.recentField == "tileImage" or + c.recentField == "tileImageCount" or + c.recentField == "tileImageHeight" or + c.recentField == "tileImageWidth" ): tds: list[gui_TextureDescription] = [] for id in range(0, c.tileImageCount): @@ -33,36 +37,48 @@ def gui_generateTilePositions( return c #} -# Generate textures descriptions +# Generate tile positions # # Conditions: -# 1. tileImage or tileImageCount or tileImageHeight or tileImageWidth has just changed -# 2. tileImage, tileImageCount, tileImageHeight, tileImageWidth are not empty +# 1. cellSize, playField, windowHeight, or windowWidth has changed and none of them is zero @llm_by_value -def gui_generateTextureDescriptions( +def gui_generateTilePositions( c: memory_Context ) -> memory_Context: if ( - c.recentField == "tileImage" or - c.recentField == "tileImageCount" or - c.recentField == "tileImageHeight" or - c.recentField == "tileImageWidth" + ( + c.recentField != "cellSize" and + c.recentField != "playfieldSize" and + c.recentField != "windowHeight" and + c.recentField != "windowWidth" + ) or + ( + c.cellSize == 0 or + c.playfieldSize == 0 or + c.windowHeight == 0 or + c.windowWidth == 0 + ) ): - tds: list[gui_TextureDescription] = [] - for id in range(0, c.tileImageCount): - td = gui_createTextureDescription() - td.fileName = c.tileImage - td.height = c.tileImageHeight - td.width = c.tileImageWidth - td.x = id * c.tileImageWidth - td.y = 0 - tds.append(td) - #} - c.textureDescriptions = tds - c.recentField = "textureDescriptions" + c.recentField = "none" return c #} - c.recentField = "none" + # Assume window size is an integer multiple of cell size. + widthInCells = c.windowWidth / c.cellSize + heightInCells = c.windowHeight / c.cellSize + positions = gui_aux_cellPositions(c.playfieldSize) + + poss = [] + for i in range(0, len(positions)): + p = positions[i] + pos = [p[0] * c.cellSize, p[1] * c.cellSize] + poss.append(pos) + #} + #tile.center_x = CELL * 2 + p[0] * CELL + #tile.center_y = HEIGHT - CELL * 2 - p[1] * CELL + + c.tilePositions = poss + c.recentField = "tilePositions" return c #} + diff --git a/v5/gui_aux.py b/v5/gui_aux.py new file mode 100644 index 0000000..e16004e --- /dev/null +++ b/v5/gui_aux.py @@ -0,0 +1,46 @@ + +# Generate positions in cell dimensions +# +# Conditions: +# 1. 2x2 grid +# 2. 4x4 grid +def gui_aux_cellPositions( + size: int +) -> [[int]]: + if ( + size == 2 + ): + return [ + [14, 7], + [19, 7], + [14, 13], + [19, 13], + ] + #} + + if ( + size == 4 + ): + return [ + [9, 1], + [14, 1], + [19, 1], + [24, 1], + + [9, 7], + [14, 7], + [19, 7], + [24, 7], + + [9, 13], + [14, 13], + [19, 13], + [24, 13], + + [9, 19], + [14, 19], + [19, 19], + [24, 19], + ] + #} +#} diff --git a/v5/gui_aux_test.py b/v5/gui_aux_test.py new file mode 100644 index 0000000..7ed4fbf --- /dev/null +++ b/v5/gui_aux_test.py @@ -0,0 +1,15 @@ +from gui_aux import * + +def test_gui_aux_cellPositions( +) -> str: + items2x2 = gui_aux_cellPositions(2) + items4x4 = gui_aux_cellPositions(4) + + if ( + len(items2x2) == 4 and + len(items4x4) == 16 + ): + return "OK: gui_aux_cellPositions" + #} + return "ERR: gui_aux_cellPositions" +#} diff --git a/v5/main-gui.py b/v5/main-gui.py index 5682de9..194cc47 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -7,6 +7,7 @@ from desktop import * from desktop_Platform import * from desktop_Window import * from gui import * +from gui_aux_test import * from gui_test import * from llm_test import * from llm_test_Python import * @@ -49,6 +50,7 @@ print(cli_test_reportMatchedItems()) print(cli_test_reportMismatchedItems()) print(cli_test_reportVictory()) +print(test_gui_aux_cellPositions()) print(test_gui_generateTextureDescriptions()) ctrl = ctx_Controller(memory_createContext()) @@ -63,6 +65,7 @@ ctrl.registerFunctions([ # cli_selectItem, # cli_showHelp, gui_generateTextureDescriptions, + gui_generateTilePositions, memory_detectMismatchedItems, memory_detectVictory, memory_generateConstPlayfield, @@ -85,12 +88,18 @@ ctrl.registerCallback(copyContext) ctrl.set("didLaunch", True) ctrl.set("playfieldSize", 2) + +ctrl.set("cellSize", 25) ctrl.set("tileImage", "res/tiles.png") ctrl.set("tileImageCount", 3) ctrl.set("tileImageHeight", 100) ctrl.set("tileImageWidth", 75) +ctrl.set("windowWidth", 900) +ctrl.set("windowHeight", 600) +ctrl.set("windowAntialiasing", False) +ctrl.set("windowBackgroundColor", "#ffffff") +ctrl.set("windowTitle", "OGS Memory") -desktop_configureFixedWindow(p) desktop_loadTextures(p) wnd = desktop_Window(p) diff --git a/v5/memory_Context.py b/v5/memory_Context.py index 3fffb2b..db806cc 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -1,5 +1,6 @@ class memory_Context: def __init__(self): + self.cellSize = 0 self.didLaunch = False self.exit = False self.hiddenItems = [] @@ -23,6 +24,10 @@ class memory_Context: self.tileImageHeight = 0 self.tileImageWidth = 0 self.tilePositions = [] + self.windowBackgroundColor = "#000000" + self.windowHeight = 0 + self.windowTitle = "" + self.windowWidth = 0 self.victory = False def field(self, fieldName):