Optimierung der Funktion get_shape_cfg zur Verarbeitung von Offsets und Rotationen für Symbole. Vereinfachung des Codes durch Verwendung von Schleifen zur dynamischen Erfassung von Offset- und Rotationswerten aus der Konfiguration. Rückgabe der Symbole als Liste von Dictionaries mit korrekten Offset- und Rotationswerten.
This commit is contained in:
+18
-24
@@ -27,33 +27,27 @@ def get_shape_cfg(teileart, cfg_path):
|
|||||||
# Blöcke
|
# Blöcke
|
||||||
items = parser.get(section, "items", fallback="").replace('"', '').split(",")
|
items = parser.get(section, "items", fallback="").replace('"', '').split(",")
|
||||||
blocks = [item.strip() for item in items if item.strip()]
|
blocks = [item.strip() for item in items if item.strip()]
|
||||||
# Offsets und Rotationen (optional)
|
|
||||||
offset1 = parser.get(section, "offset_symb1", fallback="0,0")
|
|
||||||
offset2 = parser.get(section, "offset_symb2", fallback="0,0")
|
|
||||||
rot1 = parser.get(section, "rot_symb1", fallback="0.0")
|
|
||||||
rot2 = parser.get(section, "rot_symb2", fallback="0.0")
|
|
||||||
offsets = []
|
|
||||||
for off in (offset1, offset2):
|
|
||||||
try:
|
|
||||||
ox, oy = [float(x) for x in off.split(",")]
|
|
||||||
offsets.append((ox, oy))
|
|
||||||
except Exception:
|
|
||||||
offsets.append((0.0, 0.0))
|
|
||||||
rots = []
|
|
||||||
for rot in (rot1, rot2):
|
|
||||||
try:
|
|
||||||
rots.append(float(rot))
|
|
||||||
except Exception:
|
|
||||||
rots.append(0.0)
|
|
||||||
# Baue Liste von Dicts
|
|
||||||
symbols = []
|
symbols = []
|
||||||
for i, name in enumerate(blocks):
|
for i, name in enumerate(blocks):
|
||||||
sym = {
|
# Offset
|
||||||
|
offset_key = f"offset_symb{i+1}"
|
||||||
|
offset_str = parser.get(section, offset_key, fallback="0,0")
|
||||||
|
try:
|
||||||
|
ox, oy = [float(x) for x in offset_str.split(",")]
|
||||||
|
except Exception:
|
||||||
|
ox, oy = 0.0, 0.0
|
||||||
|
# Rotation
|
||||||
|
rot_key = f"rot_symb{i+1}"
|
||||||
|
rot_str = parser.get(section, rot_key, fallback="0.0")
|
||||||
|
try:
|
||||||
|
rot = float(rot_str)
|
||||||
|
except Exception:
|
||||||
|
rot = 0.0
|
||||||
|
symbols.append({
|
||||||
"name": name,
|
"name": name,
|
||||||
"offset": offsets[i] if i < len(offsets) else (0.0, 0.0),
|
"offset": (ox, oy),
|
||||||
"rotation": rots[i] if i < len(rots) else 0.0
|
"rotation": rot
|
||||||
}
|
})
|
||||||
symbols.append(sym)
|
|
||||||
return symbols
|
return symbols
|
||||||
|
|
||||||
# --------------------------------------------------------- Konstante Parameter
|
# --------------------------------------------------------- Konstante Parameter
|
||||||
|
|||||||
Reference in New Issue
Block a user