No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

cfg_aux.py 1.4KB

hace 3 meses
hace 3 meses
hace 3 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from cld import *
  2. # Extract texture name from config section
  3. def cfg_aux_textureName(
  4. sectionName: str
  5. ) -> str:
  6. prefix = "texture \""
  7. postfix = "\""
  8. start = cld_len(prefix) + 1
  9. end = cld_len(postfix)
  10. return sectionName[start:-end]
  11. # Convert config contents to tree: sections -> keys -> values
  12. def cfg_aux_tree(
  13. cfgContents: [str]
  14. ) -> dict[str, dict[str, str]]:
  15. tree: dict[str, dict[str, str]] = {}
  16. currentSection = None
  17. n = cld_len(cfgContents)
  18. for i in range(0, n):
  19. line = cfgContents[i]
  20. # Section.
  21. if (
  22. cld_startswith(line, "[")
  23. ):
  24. currentSection = cfg_aux_treeCreateSection(tree, line)
  25. # Key = Value.
  26. else:
  27. cfg_aux_treeSetKeyValue(tree, currentSection, line)
  28. return tree
  29. # Create new section in the tree
  30. def cfg_aux_treeCreateSection(
  31. tree: dict[str, dict[str, str]],
  32. line: str
  33. ) -> str:
  34. # Strip characters `[` and `]` at both ends.
  35. sectionName = line[1:-1]
  36. tree[sectionName] = {}
  37. return sectionName
  38. # Register key-value pair in the tree
  39. def cfg_aux_treeSetKeyValue(
  40. tree: dict[str, dict[str, str]],
  41. sectionName: str,
  42. line: str
  43. ):
  44. parts = line.split(" = ")
  45. # Ignore invalid key-value pairs.
  46. if (
  47. cld_len(parts) != 2
  48. ):
  49. return
  50. key = parts[0]
  51. value = parts[1]
  52. tree[sectionName][key] = value