xml.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package main
  2. import "encoding/xml"
  3. type XMLPane struct {
  4. Name string `xml:"name,attr"`
  5. UserData string `xml:"user_data,attr"`
  6. Flag uint8 `xml:"flag"`
  7. Origin Coord2D `xml:"origin"`
  8. Alpha uint8 `xml:"alpha"`
  9. Padding uint8 `xml:"padding"`
  10. Translate Coord3D `xml:"translate"`
  11. Rotate Coord3D `xml:"rotate"`
  12. Scale Coord2D `xml:"scale"`
  13. Width float32 `xml:"width"`
  14. Height float32 `xml:"height"`
  15. }
  16. type XMLBND struct {
  17. Name string `xml:"name,attr"`
  18. UserData string `xml:"user_data,attr"`
  19. Flag uint8 `xml:"flag"`
  20. Origin Coord2D `xml:"origin"`
  21. Alpha uint8 `xml:"alpha"`
  22. Padding uint8 `xml:"padding"`
  23. Translate Coord3D `xml:"translate"`
  24. Rotate Coord3D `xml:"rotate"`
  25. Scale Coord2D `xml:"scale"`
  26. Width float32 `xml:"width"`
  27. Height float32 `xml:"height"`
  28. }
  29. type XMLPIC struct {
  30. Name string `xml:"name,attr"`
  31. UserData string `xml:"user_data,attr"`
  32. Visible uint8 `xml:"visible"`
  33. Widescreen uint8 `xml:"widescreen_affected"`
  34. Flag uint8 `xml:"flag"`
  35. Origin Coord2D `xml:"origin"`
  36. Alpha uint8 `xml:"alpha"`
  37. Padding uint8 `xml:"padding"`
  38. Translate Coord3D `xml:"translate"`
  39. Rotate Coord3D `xml:"rotate"`
  40. Scale Coord2D `xml:"scale"`
  41. Width float32 `xml:"width"`
  42. Height float32 `xml:"height"`
  43. TopLeftColor Color8 `xml:"topLeftColor"`
  44. TopRightColor Color8 `xml:"topRightColor"`
  45. BottomLeftColor Color8 `xml:"bottomLeftColor"`
  46. BottomRightColor Color8 `xml:"bottomRightColor"`
  47. MatIndex uint16 `xml:"matIndex"`
  48. UVSets *XMLUVSets `xml:"uv_sets"`
  49. }
  50. type XMLWindow struct {
  51. Name string `xml:"name,attr"`
  52. UserData string `xml:"user_data,attr"`
  53. Visible uint8 `xml:"visible"`
  54. Widescreen uint8 `xml:"widescreen_affected"`
  55. Flag uint8 `xml:"flag"`
  56. Origin Coord2D `xml:"origin"`
  57. Alpha uint8 `xml:"alpha"`
  58. Padding uint8 `xml:"padding"`
  59. Translate Coord3D `xml:"translate"`
  60. Rotate Coord3D `xml:"rotate"`
  61. Scale Coord2D `xml:"scale"`
  62. Width float32 `xml:"width"`
  63. Height float32 `xml:"height"`
  64. Coordinate1 float32 `xml:"coordinate_1"`
  65. Coordinate2 float32 `xml:"coordinate_2"`
  66. Coordinate3 float32 `xml:"coordinate_3"`
  67. Coordinate4 float32 `xml:"coordinate_4"`
  68. TopLeftColor Color8 `xml:"topLeftColor"`
  69. TopRightColor Color8 `xml:"topRightColor"`
  70. BottomLeftColor Color8 `xml:"bottomLeftColor"`
  71. BottomRightColor Color8 `xml:"bottomRightColor"`
  72. MatIndex uint16 `xml:"matIndex"`
  73. UVSets *XMLUVSets `xml:"uv_sets"`
  74. Materials *XMLWindowMats `xml:"materials"`
  75. }
  76. type XMLGRP struct {
  77. Name string `xml:"name,attr"`
  78. Entries []string `xml:"entries"`
  79. }
  80. type XMLWindowMat struct {
  81. MatIndex uint16 `xml:"matIndex"`
  82. Index uint8 `xml:"index"`
  83. }
  84. type XMLWindowMats struct {
  85. Mats []XMLWindowMat `xml:"mats"`
  86. }
  87. type XMLUVSets struct {
  88. Set []XMLUVSet `xml:"set"`
  89. }
  90. type XMLUVSet struct {
  91. CoordTL STCoordinates `xml:"coordTL"`
  92. CoordTR STCoordinates `xml:"coordTR"`
  93. CoordBL STCoordinates `xml:"coordBL"`
  94. CoordBR STCoordinates `xml:"coordBR"`
  95. }
  96. type STCoordinates struct {
  97. S float32 `xml:"s"`
  98. T float32 `xml:"t"`
  99. }
  100. type XMLTXT struct {
  101. Name string `xml:"name,attr"`
  102. UserData string `xml:"user_data,attr"`
  103. Visible uint8 `xml:"visible"`
  104. Widescreen uint8 `xml:"widescreen_affected"`
  105. Flag uint8 `xml:"flag"`
  106. Origin Coord2D `xml:"origin"`
  107. Alpha uint8 `xml:"alpha"`
  108. Padding uint8 `xml:"padding"`
  109. Translate Coord3D `xml:"translate"`
  110. Rotate Coord3D `xml:"rotate"`
  111. Scale Coord2D `xml:"scale"`
  112. Width float32 `xml:"width"`
  113. Height float32 `xml:"height"`
  114. MaxStringLength uint16 `xml:"max_string_length"`
  115. MatIndex uint16 `xml:"matIndex"`
  116. TextAlignment uint8 `xml:"textAlignment"`
  117. XSize float32 `xml:"x_size"`
  118. YSize float32 `xml:"y_size"`
  119. CharSize float32 `xml:"charsize"`
  120. LineSize float32 `xml:"linesize"`
  121. TopColor Color8 `xml:"top_color"`
  122. BottomColor Color8 `xml:"bottom_color"`
  123. Text string `xml:"text"`
  124. }
  125. type XMLPAS struct{}
  126. type XMLPAE struct{}
  127. type XMLGRS struct{}
  128. type XMLGRE struct{}
  129. // Children contains all the possible children a brlyt can contain.
  130. // This is needed for unmarshalling when we put together a new brlyt.
  131. type Children struct {
  132. Pane *XMLPane `xml:"pan1"`
  133. PAS *XMLPAS `xml:"pas1"`
  134. PAE *XMLPAE `xml:"pae1"`
  135. BND *XMLBND `xml:"bnd1"`
  136. PIC *XMLPIC `xml:"pic1"`
  137. TXT *XMLTXT `xml:"txt1"`
  138. WND *XMLWindow `xml:"wnd1"`
  139. GRP *XMLGRP `xml:"grp1"`
  140. GRS *XMLGRS `xml:"grs1"`
  141. GRE *XMLGRE `xml:"gre1"`
  142. }
  143. // TPLNames represents the structure of the txl1 section.
  144. type TPLNames struct {
  145. TPLName []string `xml:"tpl_name"`
  146. }
  147. type FNLNames struct {
  148. FNLName []string `xml:"font_name"`
  149. }
  150. // LYTNode specifies the values that LYT contains
  151. type LYTNode struct {
  152. XMLName xml.Name `xml:"lyt1"`
  153. Centered uint16 `xml:"is_centered"`
  154. Width float32 `xml:"width"`
  155. Height float32 `xml:"height"`
  156. }
  157. // Root is the main structure of our XML
  158. type Root struct {
  159. XMLName xml.Name `xml:"root"`
  160. LYT LYTNode `xml:"lyt1"`
  161. TXL *TPLNames `xml:"txl1"`
  162. FNL *FNLNames `xml:"fnt1"`
  163. MAT MATNode `xml:"mat1"`
  164. Panes []Children `xml:"children"`
  165. }
  166. type MATNode struct {
  167. Entries []MATEntries `xml:"entries"`
  168. }
  169. type MATEntries struct {
  170. Name string `xml:"name,attr"`
  171. ForeColor Color16 `xml:"foreColor"`
  172. BackColor Color16 `xml:"backColor"`
  173. ColorReg3 Color16 `xml:"colorReg3"`
  174. TevColor1 Color8 `xml:"tevColor1"`
  175. TevColor2 Color8 `xml:"tevColor2"`
  176. TevColor3 Color8 `xml:"tevColor3"`
  177. TevColor4 Color8 `xml:"tevColor4"`
  178. BitFlag uint32 `xml:"bitFlag"`
  179. Textures []MATTexture `xml:"texture"`
  180. SRT []MATSRT `xml:"textureSRT"`
  181. CoordGen []MATCoordGen `xml:"coordGen"`
  182. ChanControl *ChanControlXML `xml:"chanControl"`
  183. MatColor *Color8 `xml:"matColor"`
  184. TevSwapMode *TevSwapModeTableXML `xml:"tevSwapMode"`
  185. IndirectSRT []MATSRT `xml:"indirectSRT"`
  186. IndirectTextureOrder []MATIndirectOrderEntryXML `xml:"indirectTextureOrder"`
  187. TevStageEntry []MATTevStageEntryXML `xml:"tevStageEntry"`
  188. AlphaCompare *MATAlphaCompareXML `xml:"alphaCompare"`
  189. BlendMode *MATBlendMode `xml:"blendMode"`
  190. }
  191. type MATBlendMode struct {
  192. Type uint8 `xml:"type"`
  193. Source uint8 `xml:"source"`
  194. Destination uint8 `xml:"destination"`
  195. Operator uint8 `xml:"operator"`
  196. }
  197. type MATAlphaCompareXML struct {
  198. Comp0 uint8 `xml:"comp0"`
  199. Comp1 uint8 `xml:"comp1"`
  200. AlphaOP uint8 `xml:"alphaOP"`
  201. Ref0 uint8 `xml:"ref0"`
  202. Ref1 uint8 `xml:"ref1"`
  203. }
  204. type MATTevStageEntryXML struct {
  205. TexCoor uint8 `xml:"texCoor"`
  206. Color uint8 `xml:"color"`
  207. TexMap uint16 `xml:"texMap"`
  208. RasSel uint8 `xml:"rasSel"`
  209. TexSel uint8 `xml:"texSel"`
  210. ColorA uint8 `xml:"colorA"`
  211. ColorB uint8 `xml:"colorB"`
  212. ColorC uint8 `xml:"colorC"`
  213. ColorD uint8 `xml:"colorD"`
  214. ColorOP uint8 `xml:"colorOP"`
  215. ColorBias uint8 `xml:"colorBias"`
  216. ColorScale uint8 `xml:"colorScale"`
  217. ColorClamp uint8 `xml:"colorClamp"`
  218. ColorRegID uint8 `xml:"colorRegID"`
  219. ColorConstantSel uint8 `xml:"colorConstantSel"`
  220. AlphaA uint8 `xml:"alphaA"`
  221. AlphaB uint8 `xml:"alphaB"`
  222. AlphaC uint8 `xml:"alphaC"`
  223. AlphaD uint8 `xml:"alphaD"`
  224. AlphaOP uint8 `xml:"alphaOP"`
  225. AlphaBias uint8 `xml:"alphaBias"`
  226. AlphaScale uint8 `xml:"alphaScale"`
  227. AlphaClamp uint8 `xml:"alphaClamp"`
  228. AlphaRegID uint8 `xml:"alphaRegID"`
  229. AlphaConstantSel uint8 `xml:"alphaConstantSel"`
  230. TexID uint8 `xml:"texID"`
  231. Bias uint8 `xml:"bias"`
  232. Matrix uint8 `xml:"matrix"`
  233. WrapS uint8 `xml:"wrapS"`
  234. WrapT uint8 `xml:"wrapT"`
  235. Format uint8 `xml:"format"`
  236. AddPrevious uint8 `xml:"addPrevious"`
  237. UTCLod uint8 `xml:"utcLod"`
  238. Alpha uint8 `xml:"alpha"`
  239. }
  240. type TevSwapModeTableXML struct {
  241. AR uint8
  242. AG uint8
  243. AB uint8
  244. AA uint8
  245. BR uint8
  246. BG uint8
  247. BB uint8
  248. BA uint8
  249. CR uint8
  250. CG uint8
  251. CB uint8
  252. CA uint8
  253. DR uint8
  254. DG uint8
  255. DB uint8
  256. DA uint8
  257. }
  258. type ChanControlXML struct {
  259. ColorMaterialSource uint8
  260. AlphaMaterialSource uint8
  261. }
  262. type MATTexture struct {
  263. Name string `xml:"name,attr"`
  264. SWrap uint8
  265. TWrap uint8
  266. }
  267. type MATSRT struct {
  268. XTrans float32 `xml:"XTrans"`
  269. YTrans float32 `xml:"YTrans"`
  270. Rotation float32 `xml:"Rotation"`
  271. XScale float32 `xml:"XScale"`
  272. YScale float32 `xml:"YScale"`
  273. }
  274. type MATIndirectOrderEntryXML struct {
  275. TexCoord uint8 `xml:"texCoord"`
  276. TexMap uint8 `xml:"texMap"`
  277. ScaleS uint8 `xml:"scaleS"`
  278. ScaleT uint8 `xml:"scaleT"`
  279. }
  280. type MATCoordGen struct {
  281. Type uint8 `xml:"type"`
  282. Source uint8 `xml:"source"`
  283. MatrixSource uint8 `xml:"matrixSource"`
  284. }
  285. type Color8 struct {
  286. R uint8
  287. G uint8
  288. B uint8
  289. A uint8
  290. }
  291. type Color16 struct {
  292. R int16
  293. G int16
  294. B int16
  295. A int16
  296. }
  297. type Coord3D struct {
  298. X float32 `xml:"x"`
  299. Y float32 `xml:"y"`
  300. Z float32 `xml:"z"`
  301. }
  302. type Coord2D struct {
  303. X float32 `xml:"x"`
  304. Y float32 `xml:"y"`
  305. }