1
0

iconsmooth_lib.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2022 Space Wizards Federation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in all
  12. # copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. # SOFTWARE.
  21. class ConversionMode:
  22. def __init__(self, tw, th, states):
  23. self.tw = tw
  24. self.th = th
  25. self.states = states
  26. conversion_modes = {
  27. # TG
  28. "tg": ConversionMode(
  29. 7, 7,
  30. [
  31. # Each output state gives a source quadrant for BR, TL, TR, BL.
  32. # The idea is that each of the 4 directions is a different rotation of the same state.
  33. # These states are associated by a bitfield indicating occupance relative to the indicated corner:
  34. # 1: Tile anti-clockwise of indicated diagonal occupied.
  35. # 2: Tile in indicated diagonal occupied.
  36. # 4: Tile clockwise of indicated diagonal occupied.
  37. # BR, TL, TR, BL
  38. [ 0, 0, 0, 0], # 0 : Standing / Outer corners
  39. [ 12, 12, 3, 3], # 1 : Straight line ; top half horizontal bottom half vertical
  40. [ 0, 0, 0, 0], # 2 : Standing / Outer corners diagonal
  41. [ 12, 12, 3, 3], # 3 : Seems to match 1
  42. [ 3, 3, 12, 12], # 4 : Straight line ; top half vertical bottom half horizontal
  43. [ 15, 15, 15, 15], # 5 : Inner corners
  44. [ 3, 3, 12, 12], # 6 : Seems to match 4
  45. [ 46, 46, 46, 46], # 7 : Full
  46. ]
  47. ),
  48. # TG
  49. "tg_shuttle": ConversionMode(
  50. 7, 9,
  51. [
  52. # BR, TL, TR, BL
  53. [ 0, 0, 0, 0],
  54. [ 16, 16, 3, 3],
  55. [ 0, 0, 0, 0],
  56. [ 16, 16, 3, 3],
  57. [ 3, 3, 16, 16],
  58. [ 19, 19, 19, 19],
  59. [ 3, 3, 16, 16],
  60. [ 54, 54, 54, 54],
  61. ]
  62. ),
  63. # Citadel Station
  64. "citadel": ConversionMode(
  65. 7, 3,
  66. [
  67. # BR, TL, TR, BL
  68. [ 3, 0, 1, 2],
  69. [ 11, 8, 5, 6],
  70. [ 3, 0, 1, 2],
  71. [ 11, 8, 5, 6],
  72. [ 7, 4, 9, 10],
  73. [ 15, 12, 13, 14],
  74. [ 7, 4, 9, 10],
  75. [ 19, 16, 17, 18],
  76. ]
  77. ),
  78. # TauCeti Station
  79. "tau": ConversionMode(
  80. 3, 2,
  81. [
  82. # BR, TL, TR, BL
  83. [ 0, 0, 0, 0],
  84. [ 2, 2, 1, 1],
  85. [ 0, 0, 0, 0],
  86. [ 2, 2, 1, 1],
  87. [ 1, 1, 2, 2],
  88. [ 3, 3, 3, 3],
  89. [ 1, 1, 2, 2],
  90. [ 4, 4, 4, 4],
  91. ]
  92. ),
  93. # VXA
  94. "vxa": ConversionMode(
  95. 2, 3,
  96. [
  97. # 01 # 1: Tile anti-clockwise of indicated diagonal occupied.
  98. # 23 # 2: Tile in indicated diagonal occupied.
  99. # 45 # 4: Tile clockwise of indicated diagonal occupied.
  100. # BR, TL, TR, BL
  101. [ 5, 2, 3, 4], # 0 X (ST)
  102. [ 4, 3, 5, 2], # 1
  103. [ 5, 2, 3, 4], # 2 X (ST)
  104. [ 4, 3, 5, 2], # 3
  105. [ 3, 4, 2, 5], # 4
  106. [ 1, 1, 1, 1], # 5 X (IC)
  107. [ 3, 4, 2, 5], # 6
  108. [ 2, 5, 4, 3], # 7 X (F)
  109. ]
  110. ),
  111. # VXA+ - custom extensions to the VXA AT field format to make it map 1:1 with RT subtiles
  112. "vxap": ConversionMode(
  113. 2, 4,
  114. [
  115. # BR, TL, TR, BL
  116. [ 5, 2, 3, 4], # 0 X (ST)
  117. [ 4, 3, 5, 2], # 1
  118. [ 0, 0, 0, 0], # 2 - diagdup of 0
  119. [ 6, 6, 7, 7], # 3 - diagdup of 1
  120. [ 3, 4, 2, 5], # 4
  121. [ 1, 1, 1, 1], # 5 X (IC)
  122. [ 7, 7, 6, 6], # 6 - diagdup of 4
  123. [ 2, 5, 4, 3], # 7 X (F)
  124. ]
  125. ),
  126. # rt_states - debugging!
  127. "rt_states": ConversionMode(
  128. 8, 1,
  129. [
  130. [ 0, 0, 0, 0],
  131. [ 1, 1, 1, 1],
  132. [ 2, 2, 2, 2],
  133. [ 3, 3, 3, 3],
  134. [ 4, 4, 4, 4],
  135. [ 5, 5, 5, 5],
  136. [ 6, 6, 6, 6],
  137. [ 7, 7, 7, 7],
  138. ]
  139. ),
  140. }
  141. all_conv = "tg/citadel/tau/vxa/vxap/rt_states"
  142. def parse_size(sz):
  143. if sz.find("x") == -1:
  144. szi = int(sz)
  145. return szi, szi
  146. sp = sz.split("x")
  147. return int(sp[0]), int(sp[1])
  148. def parse_metric_mode_base(mm):
  149. if mm.find(".") == -1:
  150. # infer point as being in the centre
  151. tile_w, tile_h = parse_size(mm)
  152. return tile_w, tile_h, tile_w // 2, tile_h // 2
  153. sp = mm.split(".")
  154. tile_w, tile_h = parse_size(sp[0])
  155. subtile_w, subtile_h = parse_size(sp[1])
  156. return tile_w, tile_h, subtile_w, subtile_h
  157. def parse_metric_mode(mm):
  158. tile_w, tile_h, subtile_w, subtile_h = parse_metric_mode_base(mm)
  159. # Infer remainder from subtile
  160. # This is for uneven geometries
  161. #
  162. # SUB |
  163. # ----+----
  164. # | REM
  165. #
  166. remtile_w = tile_w - subtile_w
  167. remtile_h = tile_h - subtile_h
  168. return tile_w, tile_h, subtile_w, subtile_h, remtile_w, remtile_h
  169. explain_mm = """
  170. - Metrics -
  171. METRICS is of one of the following forms:
  172. TILESIZE
  173. TILEWxTILEH
  174. TILESIZE.SUBTILEWxSUBTILEH
  175. These metrics define the tile's size and divide it up as so:
  176. SUB |
  177. ----+----
  178. | REM
  179. SUB is either specified as the subtile width/height, or defaults to being half of the tile size.
  180. REM is computed from subtracting the subtile size from the tile size.
  181. """
  182. explain_prefix = "Resources/Textures/Structures/catwalk.rsi/catwalk_"