Михаил Капелько před 5 měsíci
rodič
revize
df259c1511
8 změnil soubory, kde provedl 124 přidání a 47 odebrání
  1. +0
    -8
      v5/desktop.py
  2. +0
    -6
      v5/desktop_Platform.py
  3. +5
    -5
      v5/desktop_Window.py
  4. +43
    -27
      v5/gui.py
  5. +46
    -0
      v5/gui_aux.py
  6. +15
    -0
      v5/gui_aux_test.py
  7. +10
    -1
      v5/main-gui.py
  8. +5
    -0
      v5/memory_Context.py

+ 0
- 8
v5/desktop.py Zobrazit soubor

@@ -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):


+ 0
- 6
v5/desktop_Platform.py Zobrazit soubor

@@ -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

+ 5
- 5
v5/desktop_Window.py Zobrazit soubor

@@ -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):


+ 43
- 27
v5/gui.py Zobrazit soubor

@@ -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
#}


+ 46
- 0
v5/gui_aux.py Zobrazit soubor

@@ -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
- 0
v5/gui_aux_test.py Zobrazit soubor

@@ -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"
#}

+ 10
- 1
v5/main-gui.py Zobrazit soubor

@@ -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)


+ 5
- 0
v5/memory_Context.py Zobrazit soubor

@@ -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):


Načítá se…
Zrušit
Uložit