From 0299882a6871a6b99e223a635f970c343d25d91c 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, 22 Jun 2024 22:53:34 +0300 Subject: [PATCH] d --- v5/Window.py | 6 +++--- v5/gui.py | 37 ++++++++++++++++++++++++++++++++++++ v5/gui_TextureDescription.py | 15 +++++++++++++++ v5/gui_test.py | 27 ++++++++++++++++++++++++++ v5/main-gui.py | 11 +++++++++-- v5/memory_Context.py | 5 +++++ 6 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 v5/gui.py create mode 100644 v5/gui_TextureDescription.py create mode 100644 v5/gui_test.py diff --git a/v5/Window.py b/v5/Window.py index 802d80c..fbe0c1d 100644 --- a/v5/Window.py +++ b/v5/Window.py @@ -7,9 +7,9 @@ WIDTH = 900 class Context: def __init__(self): self.images = [ - ["res/tiles_0.png", 0, 0, 75, 100], - ["res/tiles_0.png", 75, 0, 75, 100], - ["res/tiles_1.png", 0, 0, 75, 100], + ["res/tiles.png", 0, 0, 75, 100], + ["res/tiles.png", 75, 0, 75, 100], + ["res/tiles.png", 150, 0, 75, 100], ] self.positions = [ diff --git a/v5/gui.py b/v5/gui.py new file mode 100644 index 0000000..35c9e24 --- /dev/null +++ b/v5/gui.py @@ -0,0 +1,37 @@ +from memory_Context import * +from gui_TextureDescription import * +from llm import * + +# Generate textures descriptions +# +# Conditions: +# 1. tileImage or tileImageCount or tileImageHeight or tileImageWidth has just changed +# 2. tileImage, tileImageCount, tileImageHeight, tileImageWidth are not empty +@llm_by_value +def gui_generateTextureDescriptions( + c: memory_Context +) -> memory_Context: + if ( + 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): + 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" + return c + #} + + c.recentField = "none" + return c +#} diff --git a/v5/gui_TextureDescription.py b/v5/gui_TextureDescription.py new file mode 100644 index 0000000..ea15a43 --- /dev/null +++ b/v5/gui_TextureDescription.py @@ -0,0 +1,15 @@ +class gui_TextureDescription: + def __init__(self): + self.fileName = "" + self.height = 0 + self.width = 0 + self.x = 0 + self.y = 0 + def __repr__(self): + return self.__str__() + + def __str__(self): + return f"gui_TextureD(fileN/height/width/x/y: '{self.fileName}'/'{self.height}'/'{self.width}'/'{self.x}'/'{self.y}')" + +def gui_createTextureDescription(): + return gui_TextureDescription() diff --git a/v5/gui_test.py b/v5/gui_test.py new file mode 100644 index 0000000..9fd268c --- /dev/null +++ b/v5/gui_test.py @@ -0,0 +1,27 @@ +from gui import * +from gui_TextureDescription import * +from memory_Context import * + +def test_gui_generateTextureDescriptions( +) -> str: + c = memory_createContext() + c.tileImage = "res/img.png" + c.tileImageCount = 3 + c.tileImageHeight = 35 + c.tileImageWidth = 20 + c.recentField = "tileImageWidth" + c = gui_generateTextureDescriptions(c) + if ( + c.recentField == "textureDescriptions" and + len(c.textureDescriptions) == 3 and + c.textureDescriptions[0].fileName == "res/img.png" and + c.textureDescriptions[0].height == 35 and + c.textureDescriptions[0].width == 20 and + c.textureDescriptions[0].x == 0 and + c.textureDescriptions[1].x == 20 and + c.textureDescriptions[2].x == 40 + ): + return "OK: gui_generateTextureDescriptions" + #} + return "ERR: gui_generateTextureDescriptions" +#} diff --git a/v5/main-gui.py b/v5/main-gui.py index 8b17205..0234209 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -3,8 +3,8 @@ from cli import * from cli_test import * from ctx import * from ctx_test2 import * -#from ctx_test import * -#from ctx_test_Python import * +from gui import * +from gui_test import * from llm_test import * from llm_test_Python import * from memory_test import * @@ -47,6 +47,8 @@ print(cli_test_reportMatchedItems()) print(cli_test_reportMismatchedItems()) print(cli_test_reportVictory()) +print(test_gui_generateTextureDescriptions()) + ctrl = ctx_Controller(memory_createContext()) ctrl.registerFunctions([ # cli_exit, @@ -58,6 +60,7 @@ ctrl.registerFunctions([ # cli_reportVictory, # cli_selectItem, # cli_showHelp, + gui_generateTextureDescriptions, memory_detectMismatchedItems, memory_detectVictory, memory_generateConstPlayfield, @@ -73,6 +76,10 @@ ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) ctrl.set("didLaunch", True) ctrl.set("playfieldSize", 2) +ctrl.set("tileImage", "res/tiles.png") +ctrl.set("tileImageCount", 3) +ctrl.set("tileImageHeight", 100) +ctrl.set("tileImageWidth", 75) wnd = Window() arcade.run() diff --git a/v5/memory_Context.py b/v5/memory_Context.py index 1eeed0d..e79b148 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -17,6 +17,11 @@ class memory_Context: self.recentField = "none" self.selectedId = -1 self.selectedItems = [] + self.textureDescriptions = [] + self.tileImage = "" + self.tileImageCount = 0 + self.tileImageHeight = 0 + self.tileImageWidth = 0 self.victory = False def field(self, fieldName):