outfits_convert.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env python3
  2. import os
  3. from glob import glob
  4. import fileinput
  5. import re
  6. import sys
  7. varTranslates = {
  8. 'CoatQuality': 'quality',
  9. 'CoatWarm':'warm',
  10. 'coat_description': 'description',
  11. "CloQuality": 'quality',
  12. "CloThinness": 'thinness',
  13. "CloTopCut": 'topcut',
  14. 'CloBra': 'includesBra',
  15. "CloPanties": 'includesPanties',
  16. "CloOnePiece": 'isOnepiece',
  17. "CloInhibit": 'inhibition',
  18. "CloPantsShortness": "pantsShortness",
  19. "CloSkirtShortness": 'skirtShortness',
  20. "CloDress": 'isDress',
  21. "CloBimbo":'bimbo',
  22. "CloStyle": 'style',
  23. "CloStyle2":'style2',
  24. "CloStyle3":'style3',
  25. "CloCoverTop":"coverTop",
  26. "CloCoverBack": "coverBack",
  27. "CloCoverFront": "coverFront",
  28. "CloCoverfront": "coverFront",
  29. "swimwear_description": 'description',
  30. "ShoStyle": "style",
  31. "ShoQuality": 'quality',
  32. "ShoCut": 'cut',
  33. "ShoHeels": 'heels',
  34. "BraQuality": 'quality',
  35. "BraType": 'subtype',
  36. "BraFun": 'fun',
  37. "BraCover": 'cover',
  38. "BraThinness": 'thinness',
  39. "BraMaterial": 'material',
  40. "PanType": 'subtype',
  41. "PanFun": 'fun',
  42. "PanMaterial": 'material',
  43. "PanQuality": 'quality',
  44. "PanThinness": 'thinness',
  45. 'PanCoverBack':'coverBack',
  46. 'PanCoverFront':'coverFront'
  47. }
  48. def file_convert(filename):
  49. global tw_sources_path, tw_destination_path
  50. source_filepath= os.path.join(tw_sources_path,filename)+'.tw'
  51. destination_filepath= os.path.join(tw_destination_path,filename)+'compiled.js'
  52. with open(source_filepath, 'r') as file:
  53. lines = [line.rstrip() for line in file]
  54. with open(destination_filepath, 'w') as file:
  55. file.write("if(!setup.outfits)\n\tsetup.outfits = {};\n")
  56. identifier = 'none'
  57. counter = 0
  58. for line in lines:
  59. if match := re.match(r"""^\s*::.*attributes_(.*?)\s*$""",line):
  60. identifier = match.group(1)
  61. #file.write("setup.outfits['"+identifier+"'] = {\n")
  62. file.write("Object.assign(setup.outfits,{\n")
  63. continue
  64. if match := re.match(r"""^\s*<<set\s+\$(.*?)\s*=\s*(.*?)>>\s*$""",line):
  65. varname = match.group(1)
  66. if(varname in varTranslates):
  67. varname = varTranslates[varname]
  68. val = match.group(2)
  69. if submatch := re.match(r"""\s*ERROR: FAILED TO CONVERT LITERAL: "{3}'(.*)"{3}\s*""",val):
  70. val = f"'{submatch.group(1)}'"
  71. if len(val) > 2 and val.startswith("'") and val.endswith("'"):
  72. #It's a string
  73. val = val[1:-1]
  74. val = val.replace("'",r"\'")
  75. val = f"'{val}'"
  76. if counter > 0:
  77. file.write(f"""\t\t"{varname}": {val},\n""")
  78. continue
  79. if match := re.match(r"""^\s*<<(?:else)?if\s+\$location_var\[\$here\]\[1\]\s*==\s*(\d+)\s*>>\s*$""",line):
  80. id = identifier+'_'+match.group(1)
  81. idParts = identifier.split('_')
  82. vendor = idParts[0]
  83. index = match.group(1)
  84. subtype = None
  85. if vendor == 'school' or vendor == 'office':
  86. subtype = vendor
  87. vendor = 'gm'
  88. itemtype = 'clothes'
  89. elif vendor == 'fashionista':
  90. subtype = 'gown'
  91. itemtype = 'clothes'
  92. else:
  93. if(len(idParts) < 2):
  94. print("Error: "+destination_filepath)
  95. else:
  96. itemtype = idParts[1]
  97. if itemtype == 'coats':
  98. itemtype = 'coat'
  99. id = id.replace('coats','coat')
  100. elif itemtype == 'swim':
  101. itemtype = 'clothes'
  102. if idParts[2] == 'one':
  103. subtype = 'swimsuit'
  104. else:
  105. subtype = 'bikini'
  106. elif itemtype == 'maid':
  107. itemtype = 'clothes'
  108. subtype = 'maid'
  109. elif itemtype in ['outfits']:
  110. subtype = itemtype[:-1]
  111. id = id.replace(itemtype,itemtype[:-1])
  112. itemtype = 'clothes'
  113. elif itemtype in ['dress','strip','burlesque']:
  114. subtype = itemtype
  115. itemtype = 'clothes'
  116. if counter > 0:
  117. file.write("\t},\n")
  118. pass
  119. file.write("\t'"+id+"':{\n")
  120. file.write("\t\t'vendor':'"+vendor+"',\n")
  121. file.write("\t\t'type':'"+itemtype+"',\n")
  122. if subtype:
  123. file.write("\t\t'subtype':'"+subtype+"',\n")
  124. file.write("\t\t'index':'"+index+"',\n")
  125. counter += 1
  126. file.write("\t}\n});")
  127. tw_sources_path = os.path.join("sugarcube","src","autogenerated","outfits")
  128. tw_destination_path = os.path.join(tw_sources_path,"compiled")
  129. os.makedirs(tw_destination_path,exist_ok=True)
  130. filesNames = [y for x in os.walk(tw_sources_path) for y in glob(os.path.join(x[0], '*.tw'))]
  131. #print(filesNames)
  132. for file in filesNames:
  133. #print(file)
  134. file_convert(os.path.basename(file).split('.')[0])