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

Added Debug and ScrollMap libs

This commit is contained in:
Firew0lf 2015-10-09 15:38:37 +02:00
parent 40bd208b21
commit 0a1f9930a0
6 changed files with 130 additions and 4 deletions

View file

@ -6,6 +6,7 @@ Untested.
Actually done:
* Color
* Controls
* Debug
* dsUser
* Font
* Image
@ -14,6 +15,7 @@ Actually done:
* Motion
* Rumble
* screen
* ScrollMap
* Sprite
* System
* Timer

61
uCompat/Debug.lua Normal file
View file

@ -0,0 +1,61 @@
--[[
Debug Images related µLua compatibility layer/lib for ctrµLua
]]
-- Module
Debug = {}
Debug.isDebugOn = false
Debug.listText = {}
Debug.debugText = ""
Debug.debugColor = Color.new(31, 31, 31)
function Debug.ON()
Debug.isDebugOn = true
Debug.clear()
end
function Debug.OFF()
Debug.isDebugOn = false
end
Debug.print = function(text,aff)
local i
if(text == nil) then text = "<nil>"
elseif(text == true) then text = "TRUE"
elseif(text == false) then text = "FALSE"
elseif(type(text) == "table") then text = "<"..tostring(text).."["..table.maxn(text).."]>"
elseif(type(text) == "userdata") then text = "<"..tostring(text)..">"
elseif(type(text) == "function") then text = "<"..tostring(text)..">"
elseif(type(text) == "thread") then text = "<"..tostring(text)..">"
end
if(aff ~= nil) then
if(aff ~= true) then aff = false end
end
if(#Debug.listText == 21) then
for i=1,20 do
Debug.listText[i] = Debug.listText[i+1]
end
Debug.listText[21] = text
else
Debug.listText[#Debug.listText] = text
end
Debug.debugText = ""
for i = 1,#Debug.listText do
Debug.debugText = (Debug.debugText..Debug.listText[i].."\n")
end
if aff then render() end
end
Debug.setColor = function(color)
assert(color ~= nil, "Color can't be null")
Debug.debugColor = color
end
Debug.clear = function()
local i
for i = 1,#Debug.listText do
table.remove(Debug.listText,1)
end
end

View file

@ -32,7 +32,7 @@ function Map.draw(scr, m, x, y, w, h)
local stack = screen.getStack(scr)
local offsetX, offsetY = screen.offset()
stack[#stack+1] = {"map", m, {offsetX+(x*math.floor(m.scrollX*m.tileWidth)), offsetY+(y*math.floor(m.scrollY*m.tileHeight))}}
stack[#stack+1] = {"map", m.map, {offsetX+(x*math.floor(m.scrollX*m.tileWidth)), offsetY+(y*math.floor(m.scrollY*m.tileHeight))}}
end
function Map.scroll(m, x, y)

48
uCompat/ScrollMap.lua Normal file
View file

@ -0,0 +1,48 @@
--[[
Scrollps related µLua compatibility layer/lib for ctrµLua
]]
-- Local
map = require("ctr.gfx.map")
-- Module
require("uCompat.screen")
ScrollMap = {}
function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight)
local m = map.load(mapFile, image.texture, tileWidth, tileHeight)
return {
map = m,
scrollX = 0,
scrollY = 0,
tileWidth = tileWidth,
tileHeight = tileHeight,
}
end
function ScrollMap.destroy(m)
m.map:destroy()
end
function ScrollMap.draw(scr, m)
local stack = screen.getStack(scr)
local offsetX, offsetY = screen.offset()
stack[#stack+1] = {"map", m.map, {offsetX+m.scrollX, offsetY+m.scrollY}}
end
function ScrollMap.scroll(m, x, y)
m.scrollX = x
m.scrollY = y
end
function ScrollMap.setTile(m, x, y, t)
m.map:setTile(x, y, t)
end
function ScrollMap.getTile(m, x, y)
return m.map:getTile(x, y)
end

View file

@ -15,9 +15,11 @@ ULUA_BOOT_FULLPATH = (ULUA_DIR..ULUA_BOOT_FILE)
-- Other libs
require("uCompat.screen")
require("uCompat.Color")
require("uCompat.Debug")
require("uCompat.Font")
require("uCompat.Image")
require("uCompat.Map")
require("uCompat.ScrollMap")
require("uCompat.Timer")
require("uCompat.Sprite")
require("uCompat.Controls")

View file

@ -77,9 +77,22 @@ function stopDrawing()
fpstime = ctr.time()
fpscount = 0
end
-- Debug
if Debug and Debug.isDebugOn then
local buffer="FPS: "..NB_FPS
local xx=255-(string.len(buffer)*6)
screen.print(SCREEN_UP,171,152,"RAM : "..math.floor(collectgarbage("count")).."ko.",Debug.debugColor)
screen.print(SCREEN_UP,171,162,"VRAM: "..System.CurrentVramFree().."o.",Debug.debugColor)
screen.print(SCREEN_UP,171,172,"PRAM: "..System.CurrentPalFree().."o.",Debug.debugColor)
screen.print(SCREEN_UP,171,182,"FPS : "..NB_FPS,Debug.debugColor)
screen.drawTextBox(SCREEN_DOWN, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Debug.debugText, Debug.debugColor)
end
-- render
screen.endDrawing()
screen.setAlpha(ALPHA_RESET)
end
function render()
@ -143,7 +156,7 @@ function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color
end
function screen.drawTextBox(scr, x0, y0, x1, y1, text, color)
checkBuffer(scr)[#videoStack[scr]+1] = {"wrappedText", {offsetX+x0, offsetY+y0, text, x1-x0, 8, RGB2RGBA(color)}}
end
function screen.drawTexturedQuad(scr, x0, y0, x1, y1, x2, y2, x3, y3, img, sx, sy, w, h)
@ -171,8 +184,8 @@ function screen.startDrawing2D() -- unused
videoStack[drawScreen] = {}
-- 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
offsetX = math.floor((gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2)
offsetY = math.floor((gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2)
if drawScreen == gfx.GFX_TOP then
offsetX = offsetX + 40
end