xml.go 9.7 KB

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