DataTypes are no longer YACI classes

This commit is contained in:
Josh
2018-06-04 21:57:36 -05:00
parent 444acb408f
commit e31e4bf66c
7 changed files with 69 additions and 103 deletions

View File

@@ -41,7 +41,7 @@ end
function Label:recalculateInternalFont()
if self.fontFace then
self.font = love.graphics.newFont(self.font, self.textSize)
self.font = love.graphics.newFont(self.fontFace, self.textSize)
else
self.font = love.graphics.newFont(self.textSize)
end

View File

@@ -128,8 +128,9 @@ function UIRect:getSize()
end
function UIRect:update(delta)
self.super:update(delta)
local mousePos = Vector2D:new(love.mouse.getX(), love.mouse.getY())
local pos = self:getAbsolutePosition()
@@ -191,7 +192,6 @@ function UIRect:getAbsolutePosition()
end
function UIRect:render()
local pos = self:getAbsolutePosition()
local size = self:getAbsoluteSize()

View File

@@ -1,24 +1,29 @@
local DataType = require("lib.datatypes.DataType")
local Color = {}
setmetatable(Color,{
__index = Color,
__add = function(a,b) return Color:new(a.x+b.x,a.y+b.y) end,
__tostring = function(a) return "("..a.x..','..a.y..")" end
})
local Color = DataType:subclass("Color")
function Color:new(red, green, blue)
return setmetatable({
r = red or 0,
g = green or 0,
b = blue or 0
}, getmetatable(self))
end
function Color:fromRGB()
end
function Color:fromHex()
function Color:init(red, green, blue)
self.r = red or 1
self.g = green or 1
self.b = blue or 1
end
function Color:out()
return self.r, self.g, self.b
end
function Color:outTable()
return {
self.r,
self.g,
self.b
}
end
return Color

View File

@@ -1,10 +0,0 @@
local newclass = require("lib.YACI")
local DataType = newclass("DataType")
function DataType:init()
end
return DataType

View File

@@ -1,40 +1,24 @@
local DataType = require("lib.datatypes.DataType")
local Dimension = {}
setmetatable(Dimension,{
__index = Dimension,
__add = function(a,b) return Dimension:new(a.x+b.x,a.y+b.y) end,
__tostring = function(a) return "("..a.x..','..a.y..")" end
})
local Dimension = DataType:subclass("Dimension")
function Dimension:new(xScale, yScale, xPixel, yPixel)
local newDim = {
x = {
scale = xScale or 0,
pixel = xPixel or 0
},
y = {
scale = yScale or 0,
pixel = yPixel or 0
}
}
function Dimension.__add(dimA, dimB)
return Dimension:new(
dimA.x.scale + dimB.x.scale,
dimA.y.scale + dimB.y.scale,
dimA.x.pixel + dimB.x.pixel,
dimA.y.pixel + dimA.y.pixel
)
end
function Dimension:init(xScale, yScale, xPixel, yPixel)
self.super:init()
self.x = {}
self.y = {}
self.x.scale = xScale
self.y.scale = yScale
self.x.pixel = (xPixel or 0)
self.y.pixel = (yPixel or 0)
end
function Dimension:getScaleXY()
return self.x.scale, self.y.scale
end
function Dimension:getPixelXY()
return self.x.pixel, self.y.pixel
end
function Dimension:getComponents()
return self:getScaleXY(), self:getPixelXY()
end
return setmetatable(newDim, getmetatable(self))
end
return Dimension

View File

@@ -1,28 +1,13 @@
local DataType = require("lib.datatypes.DataType")
local Vector2D = {}
setmetatable(Vector2D,{
__index = Vector2D,
__add = function(a,b) return Vector2D:new(a.x+b.x,a.y+b.y) end,
__tostring = function(a) return "("..a.x..','..a.y..")" end
})
local Vector2D = DataType:subclass("Vector2D")
function Vector2D:__add(vecA, vecB)
return Vector2D:new(
vecA.x + vecB.x,
vecA.y + vecB.y
)
end
function Vector2D:init(x, y)
self.super:init()
self.x = x
self.y = y
end
function Vector2D:getX()
return self.x
end
function Vector2D:getY()
return self.y
end
function Vector2D:new(x,y)
return setmetatable({x=x or 0, y=y or 0}, getmetatable(self))
end
return Vector2D

View File

@@ -14,11 +14,12 @@ background:setSize(bigboy)
background:setPosition(bigboy)
background:setCornerRounding(0)
--[[local emptyColor = JUI.Label:new()
local emptyColor = JUI.Label:new()
emptyColor:setSize(JUI.Dimension:new(0.3, 0.1))
emptyColor:setPosition(JUI.Dimension:new(0.2, 0.8))
emptyColor:setBorderColor(JUI.Color:new(0.5, 0.5, 0.5))
emptyColor:setBorderWidth(2)
emptyColor:setTextSize(22)
emptyColor:setCornerRounding(5)
emptyColor:setBackgroundColor(JUI.Color:new(200/255, 69/255, 128/255))
emptyColor:setTextAlignment("center")
@@ -28,16 +29,20 @@ emptyColor.mouseEnter:connect(function()
end)
emptyColor.mouseExit:connect(function()
emptyColor:setText("Outside")
end)]]
end)
JUI.parent(mainmenu, background)
--JUI.parent(mainmenu, emptyColor)
JUI.parent(mainmenu, emptyColor)
local function round(number, decimalPlaces)
local placer = 10^(-decimalPlaces)
return (math.floor(number)/placer)*placer
end
local windowCreationSuccess
local debugInfoString = ""
local renderStats = nil
local normalRenders = 0
local luaEngineMemory = 0
local luaHighestMem = 0
function love.load()
windowCreationSuccess = love.window.setMode(1024, 600, {
@@ -52,21 +57,22 @@ function love.load()
end
function love.update(delta)
mainmenu:update(delta)
mainmenu:update(delta)
luaEngineMemory = round(collectgarbage('count'), 0)
luaHighestMem = (luaEngineMemory > luaHighestMem) and luaEngineMemory or luaHighestMem
do
if not renderStats then return end
local fps = "fps: "..tostring(love.timer.getFPS())
local os = "\tos: "..love.system.getOS()
local coreCount = "\tcores: "..love.system.getProcessorCount()
local displayCount = "\tdisplays: "..love.window.getDisplayCount()
local hasFocus = "\tfocus: "..tostring(love.window.hasFocus())
local luaMem = "\tluamem: "..(math.floor(collectgarbage('count')/1000)).."mB"
local drawStats = "\tdrawcalls: "..renderStats.drawcalls.."\ttexturemem: "..renderStats.texturememory.."\tfonts: "..renderStats.fonts
local mainChildren = "\tobjs: "..#mainmenu:getChildren()+1
local thingRenders = "\trcount: "..background.renders.."\tnrcount: "..normalRenders
local luaMem = "\tluamem: "..luaEngineMemory.."kB"
local luaMemHigh = "\tluamemhigh: "..luaHighestMem.."kb"
debugInfoString = fps..os..coreCount..displayCount..hasFocus..luaMem..drawStats..mainChildren..thingRenders
debugInfoString = fps..os..coreCount..displayCount..hasFocus..luaMem..luaMemHigh
end
end
@@ -79,8 +85,4 @@ function love.draw()
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 22)
love.graphics.setColor(0, 0, 0)
love.graphics.print(debugInfoString, 4, 4)
normalRenders = normalRenders + 1
renderStats = love.graphics.getStats()
end