outfits_convert.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. itemtype = 'error'
  84. index = match.group(1)
  85. subtype = None
  86. if vendor == 'school' or vendor == 'office':
  87. subtype = vendor
  88. vendor = 'gm'
  89. itemtype = 'clothes'
  90. elif vendor == 'market':
  91. itemtype = 'clothes'
  92. subtype = 'outfit'
  93. else:
  94. if(len(idParts) < 2):
  95. print("Error: "+destination_filepath)
  96. else:
  97. itemtype = idParts[1]
  98. if itemtype == 'coats':
  99. itemtype = 'coat'
  100. id = id.replace('coats','coat')
  101. elif itemtype == 'swim':
  102. itemtype = 'clothes'
  103. if idParts[2] == 'one':
  104. subtype = 'swimsuit'
  105. else:
  106. subtype = 'bikini'
  107. elif itemtype == 'maid':
  108. itemtype = 'clothes'
  109. subtype = 'maid'
  110. elif itemtype in ['outfits']:
  111. subtype = itemtype[:-1]
  112. id = id.replace(itemtype,itemtype[:-1])
  113. itemtype = 'clothes'
  114. elif itemtype in ['dress','strip','burlesque','cosplay']:
  115. subtype = itemtype
  116. itemtype = 'clothes'
  117. if counter > 0:
  118. file.write("\t},\n")
  119. pass
  120. file.write("\t'"+id+"':{\n")
  121. file.write("\t\t'vendor':'"+vendor+"',\n")
  122. file.write("\t\t'type':'"+itemtype+"',\n")
  123. if subtype:
  124. file.write("\t\t'subtype':'"+subtype+"',\n")
  125. file.write("\t\t'index':'"+index+"',\n")
  126. counter += 1
  127. file.write("\t}\n});")
  128. tw_sources_path = os.path.join("sugarcube","src","outfits")
  129. tw_destination_path = os.path.join(tw_sources_path,"compiled")
  130. os.makedirs(tw_destination_path,exist_ok=True)
  131. filesNames = [y for x in os.walk(tw_sources_path) for y in glob(os.path.join(x[0], '*.tw'))]
  132. #print(filesNames)
  133. for file in filesNames:
  134. print(file)
  135. file_convert(os.path.basename(file).split('.')[0])