Small fix
- Added default autosize for images - removed unnecessary Graphic object - removed unnecessary module file
This commit is contained in:
@@ -187,6 +187,12 @@ return function(img)
|
||||
local metadata = {creator="Bimg Library by NyoriE", date=os.date("!%Y-%m-%dT%TZ")}
|
||||
local width,height = 0, 0
|
||||
|
||||
if(img~=nil)then
|
||||
if(img[1][1][1]~=nil)then
|
||||
width,height = metadata.width or #img[1][1][1], metadata.height or #img[1]
|
||||
end
|
||||
end
|
||||
|
||||
local manager = {}
|
||||
|
||||
local function addFrame(id, data)
|
||||
@@ -363,18 +369,19 @@ return function(img)
|
||||
for k,v in pairs(img)do
|
||||
if(type(k)=="string")then
|
||||
metadata[k] = v
|
||||
else
|
||||
addFrame(k, v)
|
||||
end
|
||||
end
|
||||
if(metadata.width==nil)or(metadata.height==nil)then
|
||||
for k,v in pairs(frames)do
|
||||
local w, h = v.getSize()
|
||||
if(w>width)then w = width end
|
||||
if(h>height)then h = height end
|
||||
end
|
||||
width = metadata.width or #img[1][1][1]
|
||||
height = metadata.height or #img[1]
|
||||
manager.updateSize(width, height, true)
|
||||
end
|
||||
|
||||
for k,v in pairs(img)do
|
||||
if(type(k)=="number")then
|
||||
addFrame(k, v)
|
||||
end
|
||||
end
|
||||
else
|
||||
addFrame(1)
|
||||
end
|
||||
|
||||
@@ -12,6 +12,7 @@ local function loadBIMG(path, binaryMode)
|
||||
local f = fs.open(path, binaryMode and "rb" or "r")
|
||||
if(f==nil)then error("Path - "..path.." doesn't exist!") end
|
||||
local content = textutils.unserialize(f.readAll())
|
||||
|
||||
f.close()
|
||||
if(content~=nil)then
|
||||
return content, "bimg"
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
return function(path)
|
||||
local exists, content = pcall(require, path)
|
||||
return exists and content or nil
|
||||
end
|
||||
@@ -1,214 +0,0 @@
|
||||
local Object = require("Object")
|
||||
local tHex = require("tHex")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
local bimgLib = require("bimg")
|
||||
local images = require("images")
|
||||
|
||||
local sub,len,max,min = string.sub,string.len,math.max,math.min
|
||||
|
||||
return function(name)
|
||||
-- Graphic
|
||||
local base = Object(name)
|
||||
local objectType = "Graphic"
|
||||
local imgData = bimgLib()
|
||||
local bimgFrame = imgData.getFrameObject(1)
|
||||
local bimg
|
||||
local selectedFrame = 1
|
||||
base:setZIndex(5)
|
||||
|
||||
local xOffset, yOffset = 0, 0
|
||||
|
||||
local object = {
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
setOffset = function(self, _x, _y, rel)
|
||||
if(rel)then
|
||||
xOffset = xOffset + _x or 0
|
||||
yOffset = yOffset + _y or 0
|
||||
else
|
||||
xOffset = _x or xOffset
|
||||
yOffset = _y or yOffset
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getOffset = function(self)
|
||||
return xOffset,yOffset
|
||||
end,
|
||||
|
||||
setValuesByXMLData = function(self, data)
|
||||
base.setValuesByXMLData(self, data)
|
||||
|
||||
return self
|
||||
end,
|
||||
|
||||
selectFrame = function(self, id)
|
||||
if(imgData.getFrameObject(id)==nil)then
|
||||
imgData.addFrame(id)
|
||||
end
|
||||
bimgFrame = imgData.getFrameObject(id)
|
||||
bimg = bimgFrame.getImage(id)
|
||||
selectedFrame = id
|
||||
self:updateDraw()
|
||||
end,
|
||||
|
||||
addFrame = function(self, id)
|
||||
imgData.addFrame(id)
|
||||
return self
|
||||
end,
|
||||
|
||||
getFrameMetadata = function(self, id, key)
|
||||
return imgData.getFrameData(id, key)
|
||||
end,
|
||||
|
||||
setFrameMetadata = function(self, id, key, val)
|
||||
imgData.setFrameData(id, key, val)
|
||||
return self
|
||||
end,
|
||||
|
||||
getMetadata = function(self, key)
|
||||
return imgData.getMetadata(key)
|
||||
end,
|
||||
|
||||
setMetadata = function(self, key, value)
|
||||
return imgData.setMetadata(key, value)
|
||||
end,
|
||||
|
||||
getFrame = function(self, id)
|
||||
return imgData.getFrame(id)
|
||||
end,
|
||||
|
||||
getFrameObject = function(self, id)
|
||||
return imgData.getFrameObject(id)
|
||||
end,
|
||||
|
||||
removeFrame = function(self, id)
|
||||
imgData.removeFrame(id)
|
||||
return self
|
||||
end,
|
||||
|
||||
moveFrame = function(self, id, dir)
|
||||
imgData.moveFrame(id, dir)
|
||||
return self
|
||||
end,
|
||||
|
||||
getFrames = function(self)
|
||||
return imgData.getFrames()
|
||||
end,
|
||||
|
||||
getFrameCount = function(self)
|
||||
return #imgData.getFrames()
|
||||
end,
|
||||
|
||||
getSelectedFrame = function(self)
|
||||
return selectedFrame
|
||||
end,
|
||||
|
||||
blit = function(self, text, fg, bg, _x, _y)
|
||||
x = _x or x
|
||||
y = _y or y
|
||||
bimgFrame.blit(text, fg, bg, x, y)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setText = function(self, text, _x, _y)
|
||||
x = _x or x
|
||||
y = _y or y
|
||||
bimgFrame.text(text, x, y)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setBg = function(self, bg, _x, _y)
|
||||
x = _x or x
|
||||
y = _y or y
|
||||
bimgFrame.bg(bg, x, y)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setFg = function(self, fg, _x, _y)
|
||||
x = _x or x
|
||||
y = _y or y
|
||||
bimgFrame.fg(fg, x, y)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getImageSize = function(self)
|
||||
return imgData.getSize()
|
||||
end,
|
||||
|
||||
setImageSize = function(self, w, h)
|
||||
imgData.setSize(w, h)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
resizeImage = function(self, w, h)
|
||||
local newBimg = images.resizeBIMG(imgData.createBimg(), w, h)
|
||||
imgData = bimgLib(newBimg)
|
||||
selectedFrame = 1
|
||||
bimgFrame = imgData.getFrameObject(1)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
loadImage = function(self, path)
|
||||
if(fs.exists(path))then
|
||||
local newBimg = images.loadBIMG(path)
|
||||
imgData = bimgLib(newBimg)
|
||||
selectedFrame = 1
|
||||
bimgFrame = imgData.getFrameObject(1)
|
||||
bimg = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
clear = function(self)
|
||||
imgData = bimgLib()
|
||||
bimg = nil
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getImage = function(self)
|
||||
return imgData.createBimg()
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if(bimg~=nil)then
|
||||
for k,v in pairs(bimg)do
|
||||
if(k<=h-yOffset)and(k+yOffset>=1)then
|
||||
self.parent:blit(obx+xOffset, oby+k-1+yOffset, v[1], v[2], v[3])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("GraphicBG")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
end
|
||||
@@ -15,6 +15,7 @@ return function(name, basalt)
|
||||
local infinitePlay = false
|
||||
local animTimer
|
||||
local usePalette = false
|
||||
local autoSize = true
|
||||
|
||||
local xOffset, yOffset = 0, 0
|
||||
|
||||
@@ -44,6 +45,14 @@ return function(name, basalt)
|
||||
return p
|
||||
end
|
||||
|
||||
local function checkAutoSize()
|
||||
if(autoSize)then
|
||||
if(bimgLibrary~=nil)then
|
||||
base:setSize(bimgLibrary.getSize())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local object = {
|
||||
getType = function(self)
|
||||
return objectType
|
||||
@@ -64,6 +73,12 @@ return function(name, basalt)
|
||||
return self
|
||||
end,
|
||||
|
||||
setSize = function(self, _x, _y)
|
||||
base:setSize(_x, _y)
|
||||
autoSize = false
|
||||
return self
|
||||
end,
|
||||
|
||||
getOffset = function(self)
|
||||
return xOffset, yOffset
|
||||
end,
|
||||
@@ -74,7 +89,7 @@ return function(name, basalt)
|
||||
end
|
||||
bimgFrame = bimgLibrary.getFrameObject(id)
|
||||
image = bimgFrame.getImage(id)
|
||||
selectedFrame = id
|
||||
activeFrame = id
|
||||
self:updateDraw()
|
||||
end,
|
||||
|
||||
@@ -117,10 +132,11 @@ return function(name, basalt)
|
||||
if(fs.exists(path))then
|
||||
local newBimg = images.loadBIMG(path)
|
||||
bimgLibrary = bimg(newBimg)
|
||||
selectedFrame = 1
|
||||
activeFrame = 1
|
||||
bimgFrame = bimgLibrary.getFrameObject(1)
|
||||
originalImage = bimgLibrary.createBimg()
|
||||
image = bimgFrame.getImage()
|
||||
checkAutoSize()
|
||||
self:updateDraw()
|
||||
end
|
||||
return self
|
||||
@@ -129,10 +145,11 @@ return function(name, basalt)
|
||||
setImage = function(self, t)
|
||||
if(type(t)=="table")then
|
||||
bimgLibrary = bimg(t)
|
||||
selectedFrame = 1
|
||||
activeFrame = 1
|
||||
bimgFrame = bimgLibrary.getFrameObject(1)
|
||||
originalImage = bimgLibrary.createBimg()
|
||||
image = bimgFrame.getImage()
|
||||
checkAutoSize()
|
||||
self:updateDraw()
|
||||
end
|
||||
return self
|
||||
@@ -266,7 +283,7 @@ return function(name, basalt)
|
||||
resizeImage = function(self, w, h)
|
||||
local newBimg = images.resizeBIMG(originalImage, w, h)
|
||||
bimgLibrary = bimg(newBimg)
|
||||
selectedFrame = 1
|
||||
activeFrame = 1
|
||||
bimgFrame = bimgLibrary.getFrameObject(1)
|
||||
image = bimgFrame.getImage()
|
||||
self:updateDraw()
|
||||
|
||||
Reference in New Issue
Block a user