父节点
当前提交
0a0b82551a
共有 7 个文件被更改,包括 85 次插入22 次删除
  1. +1
    -2
      main.py
  2. +10
    -0
      py/cfg_aux.py
  3. +10
    -0
      py/cfg_aux_test.py
  4. +26
    -19
      py/desktop.py
  5. +0
    -1
      py/desktop_Platform.py
  6. +37
    -0
      py/desktop_aux.py
  7. +1
    -0
      py/do-test.py

+ 1
- 2
main.py 查看文件

@@ -44,13 +44,12 @@ def process(c):
# Perform context dependent calls of desktop functions.
# Similar to context functions, but no platform is returned.
desktop_applyConfigInit(p)
desktop_loadConfigTextures(p)
ctrl.registerCallback(process)

ctrl.set("cfgPath", CFG)
ctrl.set("scriptDir", SCRIPT_DIR)

#desktop_loadTextures(p)

wnd = desktop_Window(p)
ctrl.set("didLaunch", True)
arcade.run()

+ 10
- 0
py/cfg_aux.py 查看文件

@@ -1,5 +1,15 @@
from cld import *

# Extract texture name from config section
def cfg_aux_textureName(
sectionName: str
) -> str:
prefix = "texture \""
postfix = "\""
start = cld_len(prefix) + 1
end = cld_len(postfix)
return sectionName[start:-end]

# Convert config contents to tree: sections -> keys -> values
def cfg_aux_tree(
cfgContents: [str]


+ 10
- 0
py/cfg_aux_test.py 查看文件

@@ -1,5 +1,15 @@
from cfg_aux import *

def test_cfg_aux_textureName(
) -> str:
section = "textures \"t-floor1\""
tex = cfg_aux_textureName(section)
if (
tex == "t-floor1"
):
return "OK: cfg_aux_textureName"
return "ERR: cfg_aux_textureName"

def test_cfg_aux_tree(
) -> str:
lines = [


+ 26
- 19
py/desktop.py 查看文件

@@ -1,5 +1,6 @@
import arcade
from cfg_aux import *
from cld import *
from desktop_aux import *
from desktop_Platform import *

# Pass config init key-value pairs to context controller
@@ -8,23 +9,29 @@ from desktop_Platform import *
# 1. Config tree has just been parsed
def desktop_applyConfigInit(p):
if (
p.c.recentField == "cfgTree"
p.c.recentField != "cfgTree"
):
for key in p.c.cfgTree["init"]:
value = p.c.cfgTree["init"][key]
# Boolean.
if (
value == "false"
):
value = False
elif (
value == "true"
):
value = True
# Float.
elif (
cld_isdigit(value)
):
value = float(value)
return

p.ctrl.set(key, value)
for key in p.c.cfgTree["init"]:
val = p.c.cfgTree["init"][key]
value = desktop_aux_convertValue(val)
p.ctrl.set(key, value)

# Load textures
#
# Conditions:
# 1. Config tree has just been parsed
def desktop_loadConfigTextures(p):
if (
p.c.recentField != "cfgTree"
):
return

for key in p.c.cfgTree:
if (
cld_startswith(key, "texture ")
):
name = cfg_aux_textureName(key)
tex = desktop_aux_loadTexture(p.c.cfgDir, p.c.cfgTree[key])
p.textures[name] = tex

+ 0
- 1
py/desktop_Platform.py 查看文件

@@ -5,5 +5,4 @@ class desktop_Platform:
self.c = None
self.ctrl = None
self.staticSprites = arcade.SpriteList()
self.textureDescriptions = {}
self.textures = {}

+ 37
- 0
py/desktop_aux.py 查看文件

@@ -0,0 +1,37 @@
import arcade
from cld import *

# Convert String config value to Bool or Float if possible
def desktop_aux_convertValue(
value: str
) -> any:
# Bool.
if (
value == "false"
):
return False
elif (
value == "true"
):
return True
# Float.
elif (
cld_isdigit(value)
):
return float(value)
# String.
return value

# Load texture
def desktop_aux_loadTexture(
resDir: str,
desc: dict[str, str]
):
path = resDir + "/" + desc["file"]
return arcade.load_texture(
path,
x = float(desc["x"]),
y = float(desc["y"]),
width = float(desc["width"]),
height = float(desc["height"])
)

+ 1
- 0
py/do-test.py 查看文件

@@ -11,6 +11,7 @@ from cfg_test import *

functions = [
test_cfg_parseConfigTree,
test_cfg_aux_textureName,
test_cfg_aux_tree,
test_cfg_aux_treeCreateSection,
test_cfg_aux_treeSetKeyValue,


正在加载...
取消
保存