Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadAnimation(path, x, y, currentFrame)
- local anim = {
- type = "animation",
- x = x,
- y = y,
- frames = { },
- mirror = { x = false, y = false },
- currentFrame = currentFrame
- }
- table.insert(anim.frames, { })
- if fs.exists(path) then
- local file = io.open(path, "r")
- local leftX, rightX = math.huge, 0
- local topY, botY = 1,1
- local lcount = 0
- for line in file:lines() do
- lcount = lcount+1
- local cFrame = #anim.frames
- if line == "~" then
- anim.frames[cFrame].bounds = {
- x = leftX,
- y = topY,
- width = rightX - leftX + 1,
- height = botY - topY + 1
- }
- anim.frames[cFrame].dimensions = {
- width = rightX,
- height = botY
- }
- table.insert(anim.frames, { })
- leftX, rightX = math.huge, 0
- topY, botY = 1,1
- lcount = 0
- else
- table.insert(anim.frames[cFrame], {})
- for i=1,#line do
- if string.sub(line, i, i) ~= " " then
- leftX = math.min(leftX, i)
- rightX = math.max(rightX, i)
- if not topY then topY = lcount end
- botY = lcount
- end
- anim.frames[cFrame][#anim.frames[cFrame]] [i] = getColourOf(string.sub(line,i,i))
- end
- end
- end
- file:close()
- local cFrame = #anim.frames
- anim.frames[cFrame].bounds = {
- x = leftX,
- y = topY,
- width = rightX - leftX + 1,
- height = botY - topY + 1
- }
- anim.frames[cFrame].dimensions = {
- width = rightX,
- height = botY
- }
- anim.x = anim.x - leftX + 1
- anim.y = anim.y - topY + 1
- if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
- currentFrame > #anim.frames then
- anim.currentFrame = 1
- end
- anim.timerID = nil
- anim.lowerBound = 1
- anim.upperBound = #anim.frames
- anim.updating = false
- anim.repaint = repaintA
- anim.rCollidesWith = rCollidesWith
- anim.pCollidesWith = pCollidesWith
- anim.draw = drawA
- anim.update = updateA
- anim.next = nextA
- anim.previous = previousA
- anim.moveTo = moveTo
- return anim
- else
- error(path.." not found!")
- end
- end
- mon = peripheral.wrap("right")
- mon.setBackgroundColor(colors.black)
- mon.clear()
- loadAnimation("techsoft.nfa",1,1,1)
Advertisement
Add Comment
Please, Sign In to add comment