@@ -1,14 +1,6 @@ | |||||
import arcade | import arcade | ||||
from desktop_Platform import * | 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): | def desktop_loadTextures(p): | ||||
texs = [] | texs = [] | ||||
for (id, td) in enumerate(p.c.textureDescriptions): | for (id, td) in enumerate(p.c.textureDescriptions): | ||||
@@ -3,11 +3,5 @@ import arcade | |||||
class desktop_Platform: | class desktop_Platform: | ||||
def __init__(self): | def __init__(self): | ||||
self.c = None | self.c = None | ||||
self.cell = 0 | |||||
self.sprites = arcade.SpriteList() | self.sprites = arcade.SpriteList() | ||||
self.textures = [] | self.textures = [] | ||||
self.windowAntialiasing = False | |||||
self.windowBackgroundColor = arcade.color.WHITE | |||||
self.windowHeight = 0 | |||||
self.windowTitle = "" | |||||
self.windowWidth = 0 |
@@ -3,12 +3,12 @@ import arcade | |||||
class desktop_Window(arcade.Window): | class desktop_Window(arcade.Window): | ||||
def __init__(self, p): | def __init__(self, p): | ||||
super().__init__( | 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 | self.p = p | ||||
def on_draw(self): | def on_draw(self): | ||||
@@ -1,18 +1,22 @@ | |||||
from memory_Context import * | |||||
from gui_aux import * | |||||
from gui_TextureDescription import * | from gui_TextureDescription import * | ||||
from llm import * | from llm import * | ||||
from memory_Context import * | |||||
# Generate tile position | |||||
# Generate textures descriptions | |||||
# | # | ||||
# Conditions: | # Conditions: | ||||
# 1. | |||||
# 1. tileImage or tileImageCount or tileImageHeight or tileImageWidth has just changed | |||||
# 2. tileImage, tileImageCount, tileImageHeight, tileImageWidth are not empty | |||||
@llm_by_value | @llm_by_value | ||||
def gui_generateTilePositions( | |||||
def gui_generateTextureDescriptions( | |||||
c: memory_Context | c: memory_Context | ||||
) -> memory_Context: | ) -> memory_Context: | ||||
if ( | 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] = [] | tds: list[gui_TextureDescription] = [] | ||||
for id in range(0, c.tileImageCount): | for id in range(0, c.tileImageCount): | ||||
@@ -33,36 +37,48 @@ def gui_generateTilePositions( | |||||
return c | return c | ||||
#} | #} | ||||
# Generate textures descriptions | |||||
# Generate tile positions | |||||
# | # | ||||
# Conditions: | # 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 | @llm_by_value | ||||
def gui_generateTextureDescriptions( | |||||
def gui_generateTilePositions( | |||||
c: memory_Context | c: memory_Context | ||||
) -> memory_Context: | ) -> memory_Context: | ||||
if ( | 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 | 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 | return c | ||||
#} | #} | ||||
@@ -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], | |||||
] | |||||
#} | |||||
#} |
@@ -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" | |||||
#} |
@@ -7,6 +7,7 @@ from desktop import * | |||||
from desktop_Platform import * | from desktop_Platform import * | ||||
from desktop_Window import * | from desktop_Window import * | ||||
from gui import * | from gui import * | ||||
from gui_aux_test import * | |||||
from gui_test import * | from gui_test import * | ||||
from llm_test import * | from llm_test import * | ||||
from llm_test_Python import * | from llm_test_Python import * | ||||
@@ -49,6 +50,7 @@ print(cli_test_reportMatchedItems()) | |||||
print(cli_test_reportMismatchedItems()) | print(cli_test_reportMismatchedItems()) | ||||
print(cli_test_reportVictory()) | print(cli_test_reportVictory()) | ||||
print(test_gui_aux_cellPositions()) | |||||
print(test_gui_generateTextureDescriptions()) | print(test_gui_generateTextureDescriptions()) | ||||
ctrl = ctx_Controller(memory_createContext()) | ctrl = ctx_Controller(memory_createContext()) | ||||
@@ -63,6 +65,7 @@ ctrl.registerFunctions([ | |||||
# cli_selectItem, | # cli_selectItem, | ||||
# cli_showHelp, | # cli_showHelp, | ||||
gui_generateTextureDescriptions, | gui_generateTextureDescriptions, | ||||
gui_generateTilePositions, | |||||
memory_detectMismatchedItems, | memory_detectMismatchedItems, | ||||
memory_detectVictory, | memory_detectVictory, | ||||
memory_generateConstPlayfield, | memory_generateConstPlayfield, | ||||
@@ -85,12 +88,18 @@ ctrl.registerCallback(copyContext) | |||||
ctrl.set("didLaunch", True) | ctrl.set("didLaunch", True) | ||||
ctrl.set("playfieldSize", 2) | ctrl.set("playfieldSize", 2) | ||||
ctrl.set("cellSize", 25) | |||||
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) | ||||
ctrl.set("tileImageWidth", 75) | 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) | desktop_loadTextures(p) | ||||
wnd = desktop_Window(p) | wnd = desktop_Window(p) | ||||
@@ -1,5 +1,6 @@ | |||||
class memory_Context: | class memory_Context: | ||||
def __init__(self): | def __init__(self): | ||||
self.cellSize = 0 | |||||
self.didLaunch = False | self.didLaunch = False | ||||
self.exit = False | self.exit = False | ||||
self.hiddenItems = [] | self.hiddenItems = [] | ||||
@@ -23,6 +24,10 @@ class memory_Context: | |||||
self.tileImageHeight = 0 | self.tileImageHeight = 0 | ||||
self.tileImageWidth = 0 | self.tileImageWidth = 0 | ||||
self.tilePositions = [] | self.tilePositions = [] | ||||
self.windowBackgroundColor = "#000000" | |||||
self.windowHeight = 0 | |||||
self.windowTitle = "" | |||||
self.windowWidth = 0 | |||||
self.victory = False | self.victory = False | ||||
def field(self, fieldName): | def field(self, fieldName): | ||||