Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blocks = {}
- local function tris(x, y, w, h)
- return {
- x, y,
- x+w, y,
- x+w, y+h,
- x, y,
- x, y+h,
- x+w, y+h
- }
- end
- local function append(t, x, y, w, h)
- for k,v in ipairs(tris(x, y, w, h)) do
- t[#t + 1] = v
- end
- end
- local blank = Graphics.loadImage(Misc.resolveFile("graphics/stock-0.png"))
- local swap = setmetatable({}, {__index = function() return blank end})
- local function swapSprites()
- for _,i in ipairs(Block.SIZEABLE) do
- swap[i], Graphics.sprites.block[i].img = Graphics.sprites.block[i].img, swap[i]
- end
- end
- function onDraw()
- for k,v in ipairs(Block.get(Block.SIZEABLE)) do
- if not v.isHidden then
- table.insert(blocks, v)
- local id = v.id
- local img = Graphics.sprites.block[id].img
- local vtx = {add = append}
- local tex = {add = append}
- local x, y = v.x, v.y
- local w, h = v.width, v.height
- -- size of the edges
- local tw = math.min(w/2, 32)
- local th = math.min(h/2, 32)
- -- size of the edges for tex
- local ttw = tw / 96
- local tth = th / 96
- local x2 = x + tw -- end of first corner
- local x3 = x + w - tw -- start of second corner
- local x4 = x + w --end of box
- local y2 = y + th
- local y3 = y + h - th
- local y4 = y + h
- -- top left
- vtx:add(x, y, tw, th)
- tex:add(0, 0, ttw, tth)
- -- top right
- vtx:add(x3, y, tw, th)
- tex:add(1-ttw, 0, ttw, tth)
- -- bottom left
- vtx:add(x, y3, tw, th)
- tex:add(0, 1-tth, ttw, tth)
- -- bottom right
- vtx:add(x3, y3, tw, th)
- tex:add(1-ttw, 1-tth, ttw, tth)
- local maxI
- for i = x2, x3-32, 32 do
- -- top edge
- vtx:add(i, y, 32, th)
- tex:add(1/3, 0, 1/3, tth)
- -- bottom edge
- vtx:add(i, y3, 32, th)
- tex:add(1/3, 1-tth, 1/3, tth)
- maxI = i
- end
- local maxJ
- for j = y2, y3 - 32, 32 do
- -- left edge
- vtx:add(x, j, tw, 32)
- tex:add(0, 1/3, ttw, 1/3)
- -- right edge
- vtx:add(x3, j, tw, 32)
- tex:add(1-ttw, 1/3, ttw, 1/3)
- maxJ = j
- end
- local iw, jh = 0, 0 -- size of extra fill/edge portion
- if maxI then
- iw = x3 - (maxI + 32)
- end
- if maxJ then
- jh = y3 - (maxJ + 32)
- end
- if maxI and maxJ then
- for i = x2, maxI, 32 do
- for j = y2, maxJ, 32 do
- -- fill
- vtx:add(i, j, 32, 32)
- tex:add(1/3, 1/3, 1/3, 1/3)
- end
- end
- end
- if iw > 0 then
- -- end of top edge
- vtx:add(maxI + 32, y, iw, th)
- tex:add(1/3, 0, iw/96, tth)
- -- end of bottom edge
- vtx:add(maxI + 32, y3, iw, th)
- tex:add(1/3, 1-tth, iw/96, tth)
- if maxJ then
- for j = y2, maxJ, 32 do
- -- right edge of fill
- vtx:add(maxI + 32, j, iw, 32)
- tex:add(1/3, 1/3, iw/96, 1/3)
- end
- end
- end
- if jh > 0 then
- -- end of left edge
- vtx:add(x, maxJ + 32, tw, jh)
- tex:add(0, 1/3, ttw, jh/96)
- -- end of right edge
- vtx:add(x3, maxJ + 32, tw, jh)
- tex:add(1-ttw, 1/3, ttw, jh/96)
- if maxI then
- for i = x2, maxI, 32 do
- -- bottom edge of fill
- vtx:add(i, maxJ + 32, 32, jh)
- tex:add(1/3, 1/3, 1/3, jh/96)
- end
- end
- end
- if iw > 0 and jh > 0 then
- -- bottom right of fill
- vtx:add(maxI + 32, maxJ + 32, iw, jh)
- tex:add(1/3, 1/3, iw/96, jh/96)
- end
- Graphics.glDraw{
- texture = img,
- sceneCoords = true,
- vertexCoords = vtx,
- textureCoords = tex
- }
- end
- end
- swapSprites()
- end
- function onDrawEnd()
- swapSprites()
- end
Add Comment
Please, Sign In to add comment