1
0
Fork 0
mirror of https://github.com/ctruLua/uCompat.git synced 2025-10-27 16:49:31 +00:00

Added DateTime, Fixed things

This commit is contained in:
Firew0lf 2016-03-28 16:45:32 +02:00
parent 7fdae891d9
commit 590a47d88d
9 changed files with 72 additions and 12 deletions

View file

@ -1,12 +1,11 @@
# uCompat
µLua compatibility layer for ctrµLua.
Untested.
Actually done:
* Canvas
* Color
* Controls
* DateTime
* Debug
* dsUser
* Font

View file

@ -176,6 +176,7 @@ function Canvas.newImage(x1, y1, image, x2, y2, x3, y3)
o[ATTR_Y2] = y2
o[ATTR_X3] = x3
o[ATTR_Y3] = y3
return o
end
function Canvas.add(canvas, object)

31
uCompat/DateTime.lua Normal file
View file

@ -0,0 +1,31 @@
--[[
DateTime related µLua compatibility layer/lib for ctrµLua
]]
-- Local
-- Module
DateTime = {}
function DateTime.new()
return {
year = 0,
month = 0,
day = 0,
hour = 0,
minute = 0,
second = 0
}
end
function DateTime.getCurrentTime()
return {
year = tonumber(os.date("%Y")),
month = tonumber(os.date("%m")),
day = tonumber(os.date("%d")),
hour = tonumber(os.date("%H")),
minute = tonumber(os.date("%M")),
second = tonumber(os.date("%S"))
}
end

View file

@ -5,6 +5,7 @@
-- Local
local texture = require("ctr.gfx.texture")
local color = require("ctr.gfx.color")
-- Constants
@ -18,9 +19,10 @@ Image = {}
function Image.load(path, dest)
local t = texture.load(path, dest)
if not t then return nil end
local w,h = t:getSize()
return { -- Image object
texture = t,
rotation = 0,
rotation = 0.0,
scaleX = 1,
scaleY = 1
}
@ -49,11 +51,11 @@ function Image.scale(img, w, h)
end
function Image.rotate(img, angle, cx, cy)
img.rotation = angle*(math.pi/256)
img.rotation = angle*(math.pi/256.0)
end
function Image.rotateDegree(img, angle, cx, cy)
img.rotation = angle*(math.pi/180)
img.rotation = angle*(math.pi/180.0)
end
function Image.mirrorH(img, activate)

View file

@ -62,8 +62,8 @@ function Map.draw(scr, m, x, y, w, h)
end
function Map.scroll(m, x, y)
m.scrollX = x
m.scrollY = y
m.scrollX = (0-x)
m.scrollY = (0-y)
end
function Map.space(m, x, y)

View file

@ -37,8 +37,8 @@ function ScrollMap.draw(scr, m)
end
function ScrollMap.scroll(m, x, y)
m.scrollX = x
m.scrollY = y
m.scrollX = (0-x)
m.scrollY = (0-y)
end
function ScrollMap.setTile(m, x, y, t)

View file

@ -18,10 +18,16 @@ local function fixPath(DSpath)
path = ("sdmc:"..DSpath)
elseif DSpath:sub(1, 5) == "efs:/" then
path = ("romfs:/"..DSpath:sub(6,-1))
elseif DSpath:sub(1, 2) ~= "./" then
path = (fs.getDirectory()..DSpath)
else
path = DSpath
end
if path:sub(-1,-1) ~= "/" then
path = (path.."/")
end
return path
end

View file

@ -21,6 +21,8 @@ function table.getn(t)
return #t
end
unpack = table.unpack
-- Other libs
require("uCompat.screen")
require("uCompat.Color")
@ -41,3 +43,4 @@ require("uCompat.System")
require("uCompat.ini")
require("uCompat.Wifi")
require("uCompat.Nifi")
require("uCompat.DateTime")

View file

@ -120,29 +120,43 @@ function screen.setAlpha(level, layer)
end
function screen.print(scr, x, y, text, color)
local x = math.floor(x)
local y = math.floor(y)
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
end
function screen.printFont(scr, x, y, text, color, font)
local x = math.floor(x)
local y = math.floor(y)
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
end
function screen.blit(scr, x, y, img, sx, sy, w, h)
local x = math.floor(x) -- \ Compatibility patch for some homebrews not using integers
local y = math.floor(y) -- /
local x = math.floor(x)
local y = math.floor(y)
local sizex, sizey = img.texture:getSize()
checkBuffer(scr)[#videoStack[scr]+1] = {"img", img.texture, {offsetX+x+math.floor(sizex/2), offsetY+y+math.floor(sizey/2), (sx or 0), (sy or 0), (w or sizex), (h or sizey), img.rotation}}
end
function screen.drawPoint(scr, x, y, color)
local x = math.floor(x)
local y = math.floor(y)
checkBuffer(scr)[#videoStack[scr]+1] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}}
end
function screen.drawLine(scr, x0, y0, x1, y1, color)
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetX+y0, offsetX+x1, offsetY+y1, 1, RGB2RGBA(color)}}
local x0 = math.floor(x0)
local y0 = math.floor(y0)
local x1 = math.floor(x1)
local y1 = math.floor(y1)
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y1, 1, RGB2RGBA(color)}}
end
function screen.drawRect(scr, x0, y0, x1, y1, color)
local x0 = math.floor(x0)
local y0 = math.floor(y0)
local x1 = math.floor(x1)
local y1 = math.floor(y1)
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y0, offsetX+x0, offsetY+y1, 1, RGB2RGBA(color)}}
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y0, 1, RGB2RGBA(color)}}
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y1, offsetX+x1, offsetY+y1, 1, RGB2RGBA(color)}}
@ -150,6 +164,10 @@ function screen.drawRect(scr, x0, y0, x1, y1, color)
end
function screen.drawFillRect(scr, x0, y0, x1, y1, color)
local x0 = math.floor(x0)
local y0 = math.floor(y0)
local x1 = math.floor(x1)
local y1 = math.floor(y1)
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0, offsetY+y0, (x1-x0), (y1-y0), 0, RGB2RGBA(color)}}
end