diff --git a/README.md b/README.md index 10fbcea..d129834 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # uCompat µLua compatibility layer for ctrµLua. -Untested. - Actually done: * Canvas * Color * Controls + * DateTime * Debug * dsUser * Font diff --git a/uCompat/Canvas.lua b/uCompat/Canvas.lua index dade243..e1d29d6 100644 --- a/uCompat/Canvas.lua +++ b/uCompat/Canvas.lua @@ -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) diff --git a/uCompat/DateTime.lua b/uCompat/DateTime.lua new file mode 100644 index 0000000..69a62b2 --- /dev/null +++ b/uCompat/DateTime.lua @@ -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 diff --git a/uCompat/Image.lua b/uCompat/Image.lua index 1d5e730..1c47227 100644 --- a/uCompat/Image.lua +++ b/uCompat/Image.lua @@ -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) diff --git a/uCompat/Map.lua b/uCompat/Map.lua index 9bd7206..99c01ab 100644 --- a/uCompat/Map.lua +++ b/uCompat/Map.lua @@ -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) diff --git a/uCompat/ScrollMap.lua b/uCompat/ScrollMap.lua index d9e606e..5f91a99 100644 --- a/uCompat/ScrollMap.lua +++ b/uCompat/ScrollMap.lua @@ -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) diff --git a/uCompat/System.lua b/uCompat/System.lua index d70c638..32d7604 100644 --- a/uCompat/System.lua +++ b/uCompat/System.lua @@ -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 diff --git a/uCompat/init.lua b/uCompat/init.lua index 4e439b7..194bafd 100644 --- a/uCompat/init.lua +++ b/uCompat/init.lua @@ -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") diff --git a/uCompat/screen.lua b/uCompat/screen.lua index cef0b82..6cfd080 100644 --- a/uCompat/screen.lua +++ b/uCompat/screen.lua @@ -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