mirror of
https://github.com/ctruLua/uCompat.git
synced 2025-10-28 09:09:31 +00:00
Added DateTime, Fixed things
This commit is contained in:
parent
7fdae891d9
commit
590a47d88d
9 changed files with 72 additions and 12 deletions
|
|
@ -1,12 +1,11 @@
|
||||||
# uCompat
|
# uCompat
|
||||||
µLua compatibility layer for ctrµLua.
|
µLua compatibility layer for ctrµLua.
|
||||||
|
|
||||||
Untested.
|
|
||||||
|
|
||||||
Actually done:
|
Actually done:
|
||||||
* Canvas
|
* Canvas
|
||||||
* Color
|
* Color
|
||||||
* Controls
|
* Controls
|
||||||
|
* DateTime
|
||||||
* Debug
|
* Debug
|
||||||
* dsUser
|
* dsUser
|
||||||
* Font
|
* Font
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,7 @@ function Canvas.newImage(x1, y1, image, x2, y2, x3, y3)
|
||||||
o[ATTR_Y2] = y2
|
o[ATTR_Y2] = y2
|
||||||
o[ATTR_X3] = x3
|
o[ATTR_X3] = x3
|
||||||
o[ATTR_Y3] = y3
|
o[ATTR_Y3] = y3
|
||||||
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function Canvas.add(canvas, object)
|
function Canvas.add(canvas, object)
|
||||||
|
|
|
||||||
31
uCompat/DateTime.lua
Normal file
31
uCompat/DateTime.lua
Normal 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
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
-- Local
|
-- Local
|
||||||
|
|
||||||
local texture = require("ctr.gfx.texture")
|
local texture = require("ctr.gfx.texture")
|
||||||
|
local color = require("ctr.gfx.color")
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
|
||||||
|
|
@ -18,9 +19,10 @@ Image = {}
|
||||||
function Image.load(path, dest)
|
function Image.load(path, dest)
|
||||||
local t = texture.load(path, dest)
|
local t = texture.load(path, dest)
|
||||||
if not t then return nil end
|
if not t then return nil end
|
||||||
|
local w,h = t:getSize()
|
||||||
return { -- Image object
|
return { -- Image object
|
||||||
texture = t,
|
texture = t,
|
||||||
rotation = 0,
|
rotation = 0.0,
|
||||||
scaleX = 1,
|
scaleX = 1,
|
||||||
scaleY = 1
|
scaleY = 1
|
||||||
}
|
}
|
||||||
|
|
@ -49,11 +51,11 @@ function Image.scale(img, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Image.rotate(img, angle, cx, cy)
|
function Image.rotate(img, angle, cx, cy)
|
||||||
img.rotation = angle*(math.pi/256)
|
img.rotation = angle*(math.pi/256.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Image.rotateDegree(img, angle, cx, cy)
|
function Image.rotateDegree(img, angle, cx, cy)
|
||||||
img.rotation = angle*(math.pi/180)
|
img.rotation = angle*(math.pi/180.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Image.mirrorH(img, activate)
|
function Image.mirrorH(img, activate)
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,8 @@ function Map.draw(scr, m, x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.scroll(m, x, y)
|
function Map.scroll(m, x, y)
|
||||||
m.scrollX = x
|
m.scrollX = (0-x)
|
||||||
m.scrollY = y
|
m.scrollY = (0-y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.space(m, x, y)
|
function Map.space(m, x, y)
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ function ScrollMap.draw(scr, m)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScrollMap.scroll(m, x, y)
|
function ScrollMap.scroll(m, x, y)
|
||||||
m.scrollX = x
|
m.scrollX = (0-x)
|
||||||
m.scrollY = y
|
m.scrollY = (0-y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScrollMap.setTile(m, x, y, t)
|
function ScrollMap.setTile(m, x, y, t)
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,16 @@ local function fixPath(DSpath)
|
||||||
path = ("sdmc:"..DSpath)
|
path = ("sdmc:"..DSpath)
|
||||||
elseif DSpath:sub(1, 5) == "efs:/" then
|
elseif DSpath:sub(1, 5) == "efs:/" then
|
||||||
path = ("romfs:/"..DSpath:sub(6,-1))
|
path = ("romfs:/"..DSpath:sub(6,-1))
|
||||||
|
elseif DSpath:sub(1, 2) ~= "./" then
|
||||||
|
path = (fs.getDirectory()..DSpath)
|
||||||
else
|
else
|
||||||
path = DSpath
|
path = DSpath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if path:sub(-1,-1) ~= "/" then
|
||||||
|
path = (path.."/")
|
||||||
|
end
|
||||||
|
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ function table.getn(t)
|
||||||
return #t
|
return #t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unpack = table.unpack
|
||||||
|
|
||||||
-- Other libs
|
-- Other libs
|
||||||
require("uCompat.screen")
|
require("uCompat.screen")
|
||||||
require("uCompat.Color")
|
require("uCompat.Color")
|
||||||
|
|
@ -41,3 +43,4 @@ require("uCompat.System")
|
||||||
require("uCompat.ini")
|
require("uCompat.ini")
|
||||||
require("uCompat.Wifi")
|
require("uCompat.Wifi")
|
||||||
require("uCompat.Nifi")
|
require("uCompat.Nifi")
|
||||||
|
require("uCompat.DateTime")
|
||||||
|
|
|
||||||
|
|
@ -120,29 +120,43 @@ function screen.setAlpha(level, layer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.print(scr, x, y, text, color)
|
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}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.printFont(scr, x, y, text, color, font)
|
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}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.blit(scr, x, y, img, sx, sy, w, h)
|
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 x = math.floor(x)
|
||||||
local y = math.floor(y) -- /
|
local y = math.floor(y)
|
||||||
local sizex, sizey = img.texture:getSize()
|
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}}
|
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
|
end
|
||||||
|
|
||||||
function screen.drawPoint(scr, x, y, color)
|
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)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawLine(scr, x0, y0, x1, y1, color)
|
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
|
end
|
||||||
|
|
||||||
function screen.drawRect(scr, x0, y0, x1, y1, color)
|
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+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+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)}}
|
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
|
end
|
||||||
|
|
||||||
function screen.drawFillRect(scr, x0, y0, x1, y1, color)
|
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)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0, offsetY+y0, (x1-x0), (y1-y0), 0, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue