/Script/t.lua

http://awoe.googlecode.com/ · Lua · 159 lines · 144 code · 15 blank · 0 comment · 0 complexity · b9a79c914501f4efb0dc4ffad181f8f1 MD5 · raw file

  1. require 'table'
  2. source = [[
  3. {
  4. VERSION 0001
  5. IMAGE 0x0001 ".\country_zhao_select.png" TRANSP 0x00FF00FF // 0 size: 201 x 83 palettes: 1
  6. IMAGE 0x0000 ".\country_zhao.png" TRANSP 0x00FF00FF // 1 size: 480 x 640 palettes: 1
  7. MODULES
  8. {
  9. MD 0x1000 MD_IMAGE 0 0 0 69 52
  10. MD 0x1001 MD_IMAGE 0 70 1 48 35
  11. MD 0x1002 MD_IMAGE 0 120 1 35 35
  12. MD 0x1003 MD_IMAGE 0 161 0 36 45
  13. MD 0x1004 MD_IMAGE 0 72 38 39 38
  14. MD 0x1005 MD_IMAGE 0 112 37 40 38
  15. MD 0x1006 MD_IMAGE 0 153 46 48 30
  16. MD 0x1007 MD_IMAGE 0 0 52 46 31
  17. MD 0x1020 MD_IMAGE 1 0 0 480 640
  18. }
  19. FRAME "country_zhao" // Index = 0, FModules = 1
  20. {
  21. 0x2000
  22. FM 0x1020 0 0
  23. }
  24. FRAME "wuyang" // Index = 13, FModules = 2
  25. {
  26. 0x2013
  27. FM 0x1020 0 0
  28. FM 0x1005 403 60
  29. }
  30. FRAME "taiyuan" // Index = 14, FModules = 2
  31. {
  32. 0x200D
  33. FM 0x1020 0 0
  34. FM 0x1006 203 397
  35. }
  36. SPRITE_END
  37. } // SPRITE
  38. ////////////////////////////////////////////////////////////////////////////////
  39. ]]
  40. --print(source)
  41. sprite = {}
  42. sprite.version = "0000"
  43. for v in source:gfind([[VERSION%s+(%d+)]]) do
  44. sprite.version = v
  45. end
  46. sprite.images = {}
  47. for id, file, typ, color in source:gfind([[IMAGE%s+(%w+)%s+(".-")%s+(%a+)%s+(%w+)]]) do
  48. local image = {}
  49. image.id = id
  50. image.file = file
  51. image.type = typ
  52. image.color = color
  53. table.insert(sprite.images, image)
  54. end
  55. sprite.modules = {}
  56. for mstr in source:gfind([[MODULES%s+%{(.-)%}]]) do
  57. for mid, idx, x, y, w, h in mstr:gfind([[MD%s+(%w+)%s+MD_IMAGE%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)]]) do
  58. local module = {}
  59. module.id = mid
  60. module.idx = idx
  61. module.x = x
  62. module.y = y
  63. module.w = w
  64. module.h = h
  65. table.insert(sprite.modules, module)
  66. end
  67. end
  68. sprite.frames = {}
  69. for n,fstr in source:gfind([[FRAME.-"(.-)".-%{(.-)%}]]) do
  70. --print(n,fstr)
  71. local _,_, fid = fstr:find([[(0x%w+)]])
  72. if not fid then
  73. break
  74. end
  75. local frame = {}
  76. frame.id = fid
  77. frame.name = n
  78. for mid, posx, posy in fstr:gfind([[FM%s+(0x%w+)%s+(%d+)%s+(%d+)]]) do
  79. --print("##", mid, "x=", posx,"y=", posy)
  80. local module = {}
  81. module.id = mid
  82. module.x = posx
  83. module.y = posy
  84. table.insert(frame, module)
  85. end
  86. table.insert(sprite.frames, frame)
  87. end
  88. function output_images(imgs)
  89. for _, img in ipairs(imgs) do
  90. print("\tIMAGE", img.id, img.file, img.type, img.color)
  91. end
  92. end
  93. function output_modules(ms)
  94. print("\tMODULES")
  95. print("\t{")
  96. for _, m in ipairs(ms) do
  97. print("\t\tMD", m.id, "MD_IMAGE", m.idx, m.x, m.y, m.w, m.h)
  98. end
  99. print("\t}")
  100. end
  101. function output_sprite(s)
  102. print("\tVERSION", s.version)
  103. if s.images then
  104. output_images(s.images)
  105. else
  106. print("No images in sprite")
  107. end
  108. if s.modules then
  109. output_modules(s.modules)
  110. else
  111. print("No modules in sprite")
  112. end
  113. if s.frames then
  114. for _, f in ipairs(s.frames) do
  115. print("\tFRAME", "\""..f.name.."\"")
  116. print("\t{")
  117. print("\t",f.id)
  118. for _, m in ipairs(f) do
  119. print("\t\tFM", m.id, m.x, m.y)
  120. end
  121. print("\t}")
  122. end
  123. else
  124. print("No frames in sprite")
  125. end
  126. end
  127. output_sprite(sprite)