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

Added Rumble and Timer libs, implemented the offset system for drawing.

This commit is contained in:
Firew0lf 2015-10-04 15:25:34 +02:00
parent 703418a419
commit 5eeb78d9ec
3 changed files with 88 additions and 16 deletions

17
Rumble.lua Normal file
View file

@ -0,0 +1,17 @@
--[[
Rumble pack related µLua compatibility layer/lib for ctrµLua
As the 3DS doesn't have a rumble function, I couldn't implement this.
]]
-- Module
Rumble = {}
function Rumble.isInserted()
return false
end
function Rumble.set(s)
end

53
Timer.lua Normal file
View file

@ -0,0 +1,53 @@
--[[
Timers related µLua compatibility layer/lib for ctrµLua
The code comes directly from µLua, befores timers were coded in C, but with
the name patch.
]]
-- Local
local ctr = require("ctr")
-- Module
Timer = {
new = function()
local t = ctr.time()
local isStarted = false
local tick = 0
local time = function(self)
if isStarted then return ctr.time() - t
else return tick end
end
local stop = function(self)
if isStarted then
isStarted = false
tick = ctr.time() - t
end
end
local start = function(self)
if not isStarted then
isStarted = true
t = ctr.time() - tick
end
end
local reset = function(self)
t = ctr.time()
isStarted = false
tick = 0
end
return{
time = time,
getTime = time, -- name patch
stop = stop,
start = start,
reset = reset
}
end
}

View file

@ -39,6 +39,7 @@ local videoStack = {}
local alpha = ALPHA_RESET
local drawScreen = SCREEN_UP
local offsetX, offsetY = 0,0
local fpscount = 0
local fpstime = ctr.time()
@ -53,12 +54,6 @@ function startDrawing()
end
function stopDrawing()
-- As you can change the screen size, we have to re-calculate this every time.
local offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2
local offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2
if drawScreen == gfx.SCREEN_UP then
offsetX = offsetX + 40
end
-- FPS counter
fpscount = fpscount + 1
@ -98,35 +93,35 @@ function screen.setAlpha(level, layer)
end
function screen.print(scr, x, y, text, color)
videoStack[scr][#videoStack[scr]] = {"text", {x, y, text, 8, RGB2RGBA(color), nil}}
videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
end
function screen.printFont(scr, x, y, text, color, font)
videoStack[scr][#videoStack[scr]] = {"text", {x, y, text, 8, RGB2RGBA(color), font}}
videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), font}}
end
function screen.blit(scr, x, y, img, sx, sy, w, h)
local sizex, sizey = img:getSize()
videoStack[scr][#videoStack[scr]] = {"img", {x, y, (sx or 0), (sy or 0), (w or sizex), (h or sizey)}}
videoStack[scr][#videoStack[scr]] = {"img", {offsetX+x, offsetY+y, (sx or 0), (sy or 0), (w or sizex), (h or sizey)}}
end
function screen.drawPoint(scr, x, y, color)
videoStack[scr][#videoStack[scr]] = {"point", {x, y, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}}
end
function screen.drawLine(scr, x0, y0, x1, y1, color)
videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x1, y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetX+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
end
function screen.drawRect(scr, x0, y0, x1, y1, color)
videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x0, y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x1, y0, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {x0, y1, x1, y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {x1, y0, x1, y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x0, offsetY+y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y0, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y1, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x1, offsetY+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
end
function screen.drawFillRect(scr, x0, y0, x1, y1, color)
videoStack[scr][#videoStack[scr]] = {"rectangle", {x0, y0, (x1-x0), (y1-y0), 0, RGB2RGBA(color)}}
videoStack[scr][#videoStack[scr]] = {"rectangle", {offsetX+x0, offsetY+y0, offsetX+(x1-x0), offsetY+(y1-y0), 0, RGB2RGBA(color)}}
end
function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color)
@ -162,6 +157,13 @@ function screen.startDrawing2D() -- unused
videoStack = {}
videoStack[0] = {}
videoStack[1] = {}
-- As you can change the screen size, we have to re-calculate this every time.
offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2
offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2
if drawScreen == gfx.SCREEN_UP then
offsetX = offsetX + 40
end
end
function screen.endDrawing()