PageRenderTime 30ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Script/t.lua

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