This commit is contained in:
2024-07-14 23:00:09 +03:00
parent a91bc3fffd
commit 9a638979d5
6 changed files with 59 additions and 8 deletions

View File

@@ -8,7 +8,19 @@ windowWidth = 900
[static "s-floor1"] [static "s-floor1"]
left = 0 left = 0
texture = t-floor1 texture = t-floor1
top = 100 top = 25
visible = true
[static "s-floor2"]
left = 0
texture = t-floor1
top = 225
visible = true
[static "s-floor3"]
left = 0
texture = t-floor1
top = 425
visible = true visible = true
[texture "t-floor1"] [texture "t-floor1"]

View File

@@ -1,12 +1,22 @@
from cld import * from cld import *
# Extract static sprite name from config section
def cfg_aux_staticSpriteName(
sectionName: str
) -> str:
prefix = f"static \""
postfix = f"\""
start = cld_len(prefix)
end = cld_len(postfix)
return sectionName[start:-end]
# Extract texture name from config section # Extract texture name from config section
def cfg_aux_textureName( def cfg_aux_textureName(
sectionName: str sectionName: str
) -> str: ) -> str:
prefix = "texture \"" prefix = f"texture \""
postfix = "\"" postfix = f"\""
start = cld_len(prefix) + 1 start = cld_len(prefix)
end = cld_len(postfix) end = cld_len(postfix)
return sectionName[start:-end] return sectionName[start:-end]

View File

@@ -1,8 +1,18 @@
from cfg_aux import * from cfg_aux import *
def test_cfg_aux_staticSpriteName(
) -> str:
section = f"static \"s-floor1\""
name = cfg_aux_staticSpriteName(section)
if (
name == "s-floor1"
):
return "OK: cfg_aux_staticSpriteName"
return "ERR: cfg_aux_staticSpriteName"
def test_cfg_aux_textureName( def test_cfg_aux_textureName(
) -> str: ) -> str:
section = "textures \"t-floor1\"" section = f"texture \"t-floor1\""
tex = cfg_aux_textureName(section) tex = cfg_aux_textureName(section)
if ( if (
tex == "t-floor1" tex == "t-floor1"

View File

@@ -32,9 +32,10 @@ def desktop_createConfigStaticSprites(p):
if ( if (
cld_startswith(key, "static ") cld_startswith(key, "static ")
): ):
name = cfg_aux_spriteName(key) name = cfg_aux_staticSpriteName(key)
sprite = desktop_aux_createSprite(p.c.cfgTree[key]) sprite = desktop_aux_createStaticSprite(p, name, p.c.cfgTree[key])
p.statics[name] = sprite p.statics[name] = sprite
p.staticSprites.append(sprite)
# Report finish. # Report finish.
p.ctrl.set("didCreateConfigStaticSprites", True) p.ctrl.set("didCreateConfigStaticSprites", True)

View File

@@ -1,5 +1,6 @@
import arcade import arcade
from cld import * from cld import *
from desktop_Platform import *
# Convert String config value to Bool or Float if possible # Convert String config value to Bool or Float if possible
def desktop_aux_convertValue( def desktop_aux_convertValue(
@@ -22,7 +23,23 @@ def desktop_aux_convertValue(
# String. # String.
return value return value
# Load texture def desktop_aux_createStaticSprite(
p: desktop_Platform,
name: str,
desc: dict[str, str]
):
sp = arcade.Sprite()
sp.guid = name
texName = desc["texture"]
sp.texture = p.textures[texName]
# Position.
sp.left = float(desc["left"])
sp.top = float(desc["top"])
# Visibility.
sp.visible = True if desc["visible"] == "true" else False
return sp
def desktop_aux_loadTexture( def desktop_aux_loadTexture(
resDir: str, resDir: str,
desc: dict[str, str] desc: dict[str, str]

View File

@@ -11,6 +11,7 @@ from cfg_test import *
functions = [ functions = [
test_cfg_parseConfigTree, test_cfg_parseConfigTree,
test_cfg_aux_staticSpriteName,
test_cfg_aux_textureName, test_cfg_aux_textureName,
test_cfg_aux_tree, test_cfg_aux_tree,
test_cfg_aux_treeCreateSection, test_cfg_aux_treeCreateSection,