import arcade
from cli import *
from cli_test import *
from ctx import *
from ctx_test2 import *
from desktop import *
from desktop_Platform import *
from desktop_SequentialTimer import *
from desktop_Window import *
from gui import *
from gui_aux import *
from gui_aux_test import *
from gui_test import *
from llm_test import *
from llm_test_Python import *
from memory_test import *
import sys

print(ctx_test_Controller_executeFunctions_registerFunction_set())
print(ctx_test_Controller_processQueue())
print(ctx_test_Controller_registerFieldCallback_match())
print(ctx_test_Controller_registerFieldCallback_mismatch())
print(ctx_test_memoryContext_field())
print(ctx_test_memoryContext_setField())

print(llm_test_Python_copyByValue())
print(llm_test_isDigit_digit())
print(llm_test_isDigit_notDigit())
print(llm_test_strToInt())

print(memory_test_detectMismatchedItems())
print(memory_test_detectMismatchedItems_itemTwice())
print(memory_test_detectVictory())
print(memory_test_generateConstPlayfield())
print(memory_test_hideMatchingItems())
print(memory_test_selectItem_1x())
print(memory_test_selectItem_2x())
print(memory_test_selectItem_3x())

print(cli_test_exit_e())
print(cli_test_exit_exit())
print(cli_test_exit_victory())
print(cli_test_exit_q())
print(cli_test_exit_quit())
print(cli_test_goOn())
print(cli_test_greetUser())
print(cli_test_showHelp_h())
print(cli_test_showHelp_help())
print(cli_test_selectItem())
print(cli_test_promptSecondItemSelection())
print(cli_test_reportMatchedItems())
print(cli_test_reportMismatchedItems())
print(cli_test_reportVictory())

print(test_gui_aux_cellGridPositions())
print(test_gui_generateTextureDescriptions())
print(test_gui_generateTilePositions())

ctrl = ctx_Controller(memory_createContext())
ctrl.registerFunctions([
#  cli_exit,
#  cli_goOn,
#  cli_greetUser,
#  cli_promptSecondItemSelection,
#  cli_reportMatchedItems,
#  cli_reportMismatchedItems,
#  cli_reportVictory,
#  cli_selectItem,
#  cli_showHelp,
  gui_generateTextureDescriptions,
  gui_generateTilePositions,
  gui_generateTitleTextureDescriptions,
  memory_detectMismatchedItems,
  memory_detectVictory,
  memory_generateConstPlayfield,
  memory_hideMatchingItems,
  memory_selectItem,
])

def printDbg(c):
  print(f"Dbg key/value: '{c.recentField}'/'{c.field(c.recentField)}'")
ctrl.registerCallback(printDbg)
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))

p = desktop_Platform()
p.ctrl = ctrl
p.sequentialTimer = desktop_SequentialTimer()
p.sequentialTimer.callback = lambda key, value: ctrl.set(key, value)

# Bind platform to context changes.
def process(c):
  # Copy context to platform.
  p.c = c
  # Perform context dependent calls of desktop functions.
  # Similar to context functions, but no platform is returned.
  desktop_deselectMismatchedTiles(p)
  desktop_displaySelectedTile(p)
  desktop_displayTitle(p)
  desktop_hideMatchingTiles(p)
  desktop_scheduleHidingOfMatchingTiles(p)
  desktop_scheduleDeselectionOfMismatchedTiles(p)
ctrl.registerCallback(process)

ctrl.set("didLaunch", True)
ctrl.set("playfieldSize", 6)

ctrl.set("cellPositions", gui_aux_cellHarmPositions())
ctrl.set("cellSize", 25)
ctrl.set("deselectMismatchedTilesDelay", 500)
ctrl.set("hideMatchingTilesDelay", 500)
ctrl.set("tileImage", "res/harmful-tiles.png")
ctrl.set("tileImageCount", 8)
ctrl.set("tileImageHeight", 100)
ctrl.set("tileImageWidth", 75)
ctrl.set("titleImage", "res/harmful-titles.png")
ctrl.set("titleImageCount", 6)
ctrl.set("titleImageHeight", 100)
ctrl.set("titleImageWidth", 700)
ctrl.set("titlePosition", [4, 1])
ctrl.set("windowWidth", 900)
ctrl.set("windowHeight", 600)
ctrl.set("windowAntialiasing", False)
ctrl.set("windowBackgroundColor", "#ffffff")
ctrl.set("windowTitle", "OGS Memory")

desktop_loadTextures(p)
desktop_createDeselectedTiles(p)
desktop_createSelectedTiles(p)

desktop_loadTitleTextures(p)
desktop_createTitle(p)

wnd = desktop_Window(p)
arcade.run()
