Проверка шаблона шины для iOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generateWorldFields.py 2.4KB

11 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from generation.worldFieldTypeInit import *
  2. from generation.worldFieldTypePS import *
  3. def generateWorldFields(c):
  4. fileName = f"{c.dir}/templates/world-field"
  5. lines = c.readFile(fileName)
  6. fmtInitType = lines[0]
  7. fmtCVS = lines[1]
  8. fmtInit = lines[2]
  9. fmtModel = lines[3]
  10. fmtNet = lines[4]
  11. fmtPS = lines[5]
  12. fmtVar = lines[6]
  13. fields = []
  14. for key in c.structure.world.fields:
  15. values = c.structure.world.fields[key]
  16. # [TYPE, DEFAULT, cvs] -> CurrentValueSubject
  17. if "cvs" in values:
  18. type = values[0]
  19. default = values[1]
  20. ln = fmtCVS \
  21. .replace("%NAME%", key) \
  22. .replace("%TYPE%", type) \
  23. .replace("%DEFAULT%", default)
  24. fields.append(ln)
  25. # [escape, init], [TYPE, escape, init] -> let TYPE
  26. elif "escape" in values and "init" in values:
  27. type = worldFieldTypeInit(key, c.structure)
  28. fmt = fmtInit
  29. if len(values) == 3:
  30. fmt = fmtInitType
  31. ln = fmt \
  32. .replace("%NAME%", key) \
  33. .replace("%TYPE%", type)
  34. fields.append(ln)
  35. # [init], [TYPE, init] -> let TYPE
  36. elif "init" in values:
  37. type = worldFieldTypeInit(key, c.structure)
  38. fmt = fmtInit
  39. if len(values) == 2:
  40. fmt = fmtInitType
  41. ln = fmt \
  42. .replace("%NAME%", key) \
  43. .replace("%TYPE%", type)
  44. fields.append(ln)
  45. # model -> PassthroughSubject<Model>
  46. elif key == "model":
  47. fields.append(fmtModel)
  48. # net -> Net.Publisher
  49. elif key == "net":
  50. fields.append(fmtNet)
  51. # [ps], [TYPE, ps] -> PassthroughSubject
  52. elif "ps" in values:
  53. type = worldFieldTypePS(key, c.structure)
  54. ln = fmtPS \
  55. .replace("%NAME%", key) \
  56. .replace("%TYPE%", type)
  57. fields.append(ln)
  58. # [TYPE, DEFAULT, var] -> var TYPE
  59. elif "var" in values:
  60. type = values[0]
  61. default = values[1]
  62. ln = fmtVar \
  63. .replace("%NAME%", key) \
  64. .replace("%TYPE%", type) \
  65. .replace("%DEFAULT%", default)
  66. fields.append(ln)
  67. c.worldFields = "\n".join(fields)