d
This commit is contained in:
@@ -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.c.windowWidth,
|
||||||
p.windowHeight,
|
p.c.windowHeight,
|
||||||
p.windowTitle,
|
p.c.windowTitle,
|
||||||
)
|
)
|
||||||
self.antialiasing = p.windowAntialiasing
|
self.antialiasing = p.c.windowAntialiasing
|
||||||
arcade.set_background_color(p.windowBackgroundColor)
|
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):
|
||||||
|
|||||||
80
v5/gui.py
80
v5/gui.py
@@ -1,37 +1,7 @@
|
|||||||
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
|
|
||||||
#
|
|
||||||
# Conditions:
|
|
||||||
# 1.
|
|
||||||
@llm_by_value
|
|
||||||
def gui_generateTilePositions(
|
|
||||||
c: memory_Context
|
|
||||||
) -> memory_Context:
|
|
||||||
if (
|
|
||||||
c.recentField == "windowHeight" or
|
|
||||||
c.recentField == "windowWidth"
|
|
||||||
):
|
|
||||||
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
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Generate textures descriptions
|
# Generate textures descriptions
|
||||||
#
|
#
|
||||||
@@ -66,3 +36,49 @@ def gui_generateTextureDescriptions(
|
|||||||
c.recentField = "none"
|
c.recentField = "none"
|
||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# Generate tile positions
|
||||||
|
#
|
||||||
|
# Conditions:
|
||||||
|
# 1. cellSize, playField, windowHeight, or windowWidth has changed and none of them is zero
|
||||||
|
@llm_by_value
|
||||||
|
def gui_generateTilePositions(
|
||||||
|
c: memory_Context
|
||||||
|
) -> memory_Context:
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
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
|
||||||
|
)
|
||||||
|
):
|
||||||
|
c.recentField = "none"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
#}
|
||||||
|
|
||||||
|
|||||||
46
v5/gui_aux.py
Normal file
46
v5/gui_aux.py
Normal file
@@ -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],
|
||||||
|
]
|
||||||
|
#}
|
||||||
|
#}
|
||||||
15
v5/gui_aux_test.py
Normal file
15
v5/gui_aux_test.py
Normal file
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user