mirror of
https://github.com/ctruLua/uCompat.git
synced 2025-10-27 16:49:31 +00:00
Added Canvas and Sound.
Warning: the Canvas are slow, and the sound doesn't work.
This commit is contained in:
parent
c70cfab18f
commit
f9b2fcb11a
6 changed files with 292 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
Untested.
|
Untested.
|
||||||
|
|
||||||
Actually done:
|
Actually done:
|
||||||
|
* Canvas
|
||||||
* Color
|
* Color
|
||||||
* Controls
|
* Controls
|
||||||
* Debug
|
* Debug
|
||||||
|
|
@ -13,9 +14,12 @@ Actually done:
|
||||||
* ini
|
* ini
|
||||||
* Map
|
* Map
|
||||||
* Motion
|
* Motion
|
||||||
|
* Nifi
|
||||||
* Rumble
|
* Rumble
|
||||||
* screen
|
* screen
|
||||||
* ScrollMap
|
* ScrollMap
|
||||||
|
* Sound (without sound)
|
||||||
* Sprite
|
* Sprite
|
||||||
* System
|
* System
|
||||||
* Timer
|
* Timer
|
||||||
|
* Wifi
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,230 @@
|
||||||
--[[
|
--[[
|
||||||
Canvas related µLua compatibility layer/lib for ctrµLua
|
Canvas related µLua compatibility layer/lib for ctrµLua
|
||||||
|
|
||||||
|
If you used to use the canvas to speed up your drawing: f*ck you.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
require("uCompat.screen")
|
||||||
|
|
||||||
|
-- Constants
|
||||||
|
|
||||||
|
ATTR_X1 = 1
|
||||||
|
ATTR_Y1 = 2
|
||||||
|
ATTR_X2 = 3
|
||||||
|
ATTR_Y2 = 4
|
||||||
|
ATTR_X3 = 5
|
||||||
|
ATTR_Y3 = 6
|
||||||
|
ATTR_COLOR = 7
|
||||||
|
ATTR_COLOR1 = 8
|
||||||
|
ATTR_COLOR2 = 9
|
||||||
|
ATTR_COLOR3 = 10
|
||||||
|
ATTR_COLOR4 = 11
|
||||||
|
ATTR_TEXT = 12
|
||||||
|
ATTR_VISIBLE = 13
|
||||||
|
ATTR_FONT = 14
|
||||||
|
ATTR_IMAGE = 15
|
||||||
|
|
||||||
-- Local
|
-- Local
|
||||||
|
|
||||||
|
local function attrTable()
|
||||||
|
return {
|
||||||
|
type = false,
|
||||||
|
[ATTR_X1] = false,
|
||||||
|
[ATTR_Y1] = false,
|
||||||
|
[ATTR_X2] = false,
|
||||||
|
[ATTR_Y2] = false,
|
||||||
|
[ATTR_X3] = false,
|
||||||
|
[ATTR_Y3] = false,
|
||||||
|
[ATTR_COLOR] = false,
|
||||||
|
[ATTR_COLOR1] = false,
|
||||||
|
[ATTR_COLOR2] = false,
|
||||||
|
[ATTR_COLOR3] = false,
|
||||||
|
[ATTR_COLOR4] = false,
|
||||||
|
[ATTR_TEXT] = false,
|
||||||
|
[ATTR_VISIBLE] = false,
|
||||||
|
[ATTR_FONT] = false,
|
||||||
|
[ATTR_IMAGE] = false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local TYPE_LINE = 1
|
||||||
|
local TYPE_POINT = 2
|
||||||
|
local TYPE_RECT = 3
|
||||||
|
local TYPE_FILLRECT = 4
|
||||||
|
local TYPE_GRADIENTRECT = 5
|
||||||
|
local TYPE_TEXT = 6
|
||||||
|
local TYPE_TEXTFONT = 7
|
||||||
|
local TYPE_TEXTBOX = 8
|
||||||
|
local TYPE_IMAGE = 9
|
||||||
|
|
||||||
|
local function searchObject(t, o)
|
||||||
|
for n,v in pairs(t) do
|
||||||
|
if (v == o) then return n end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
|
|
||||||
Canvas = {}
|
Canvas = {}
|
||||||
|
|
||||||
|
function Canvas.new()
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.destroy(canvas)
|
||||||
|
--
|
||||||
|
collectgarbage()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newLine(x1, y1, x2, y2, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_LINE
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newPoint(x1, y1, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_POINT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newRect(x1, y1, x2, y2, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_RECT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newFillRect(x1, y1, x2, y2, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_FILLRECT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newGradientRect(x1, y1, x2, y2, color1, color2, color3, color4)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_GRADIENTRECT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_COLOR1] = color1
|
||||||
|
o[ATTR_COLOR2] = color2
|
||||||
|
o[ATTR_COLOR3] = color3
|
||||||
|
o[ATTR_COLOR4] = color4
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newText(x1, y1 text, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_TEXT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_TEXT] = text
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newTextFont(x1, y1, text, color, font)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_TEXTFONT
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_TEXT] = text
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
o[ATTR_FONT] = font
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newTextBox(x1, y1, x2, y2, text, color)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_TEXTBOX
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_TEXT] = text
|
||||||
|
o[ATTR_COLOR] = color
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.newImage(x1, y1, image, x2, y2, x3, y3)
|
||||||
|
local o = attrTable()
|
||||||
|
o.type = TYPE_IMAGE
|
||||||
|
o[ATTR_X1] = x1
|
||||||
|
o[ATTR_Y1] = y1
|
||||||
|
o[ATTR_IMAGE] = image
|
||||||
|
o[ATTR_X2] = x2
|
||||||
|
o[ATTR_Y2] = y2
|
||||||
|
o[ATTR_X3] = x3
|
||||||
|
o[ATTR_Y3] = y3
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.add(canvas, object)
|
||||||
|
canvas[#canvas+1] = object
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.draw(scr, canvas, x, y)
|
||||||
|
for i=1, #canvas do
|
||||||
|
local o = canvas[i] -- gotta go fast
|
||||||
|
if o.type == TYPE_LINE then
|
||||||
|
screen.drawLine(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_POINT then
|
||||||
|
screen.drawPoint(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_RECT then
|
||||||
|
screen.drawRect(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_FILLRECT then
|
||||||
|
screen.drawFillRect(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_GRADIENTRECT then
|
||||||
|
screen.drawGradientRect(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR1], o[ATTR_COLOR2], o[ATTR_COLOR3], o[ATTR_COLOR4])
|
||||||
|
elseif o.type == TYPE_TEXT then
|
||||||
|
screen.print(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_TEXT], o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_TEXTFONT then
|
||||||
|
screen.printFont(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_TEXT], o[ATTR_COLOR], o[ATTR_FONT])
|
||||||
|
elseif o.type == TYPE_TEXTBOX then
|
||||||
|
screen.drawTextBox(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_TEXT], o[ATTR_COLOR])
|
||||||
|
elseif o.type == TYPE_IMAGE then
|
||||||
|
screen.blit(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_IMAGE], o[ATTR_X2], o[ATTR_Y2], o[ATTR_X3], o[ATTR_Y3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.setAttr(object, attrName, attrValue)
|
||||||
|
object[attrName] = attrValue
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.getAttr(object, attrName)
|
||||||
|
return obect[attrName]
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.setObjOnTop(canvas, object)
|
||||||
|
local i = searchObject(canvas, object)
|
||||||
|
if not i then return end
|
||||||
|
|
||||||
|
table.remove(canvas, i)
|
||||||
|
canvas[#canvas+1] = object
|
||||||
|
end
|
||||||
|
|
||||||
|
function Canvas.removeObj(canvas, object)
|
||||||
|
local i = searchObject(canvas, object)
|
||||||
|
if not i then return end
|
||||||
|
table.remove(canvas, i)
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
--[[
|
--[[
|
||||||
Debug Images related µLua compatibility layer/lib for ctrµLua
|
Debug related µLua compatibility layer/lib for ctrµLua
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
|
|
|
||||||
58
uCompat/Sound.lua
Normal file
58
uCompat/Sound.lua
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
--[[
|
||||||
|
Sound
|
||||||
|
]]
|
||||||
|
|
||||||
|
Sound = {}
|
||||||
|
|
||||||
|
PLAY_ONCE = 0
|
||||||
|
PLAY_LOOP = 1
|
||||||
|
|
||||||
|
-- Module
|
||||||
|
|
||||||
|
function Sound.loadMod(id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.unloadMod(id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.startMod(id, playmode)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.pause()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.stop()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.setPosition(id, position)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.isActive()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.startJingle(id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.setModVolume(volume) -- range: 0-1024
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.setJingleVolume(volume) -- range: 0-1024
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.setModTempo(tempo) -- range: 512-2048
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sound.setModPitch(pitch)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -18,10 +18,12 @@ require("uCompat.Color")
|
||||||
require("uCompat.Debug")
|
require("uCompat.Debug")
|
||||||
require("uCompat.Font")
|
require("uCompat.Font")
|
||||||
require("uCompat.Image")
|
require("uCompat.Image")
|
||||||
|
require("uCompat.Canvas")
|
||||||
require("uCompat.Map")
|
require("uCompat.Map")
|
||||||
require("uCompat.ScrollMap")
|
require("uCompat.ScrollMap")
|
||||||
require("uCompat.Timer")
|
require("uCompat.Timer")
|
||||||
require("uCompat.Sprite")
|
require("uCompat.Sprite")
|
||||||
|
require("uCompat.Sound")
|
||||||
require("uCompat.Controls")
|
require("uCompat.Controls")
|
||||||
require("uCompat.Motion")
|
require("uCompat.Motion")
|
||||||
require("uCompat.Rumble")
|
require("uCompat.Rumble")
|
||||||
|
|
@ -29,3 +31,4 @@ require("uCompat.dsUser")
|
||||||
require("uCompat.System")
|
require("uCompat.System")
|
||||||
require("uCompat.ini")
|
require("uCompat.ini")
|
||||||
require("uCompat.Wifi")
|
require("uCompat.Wifi")
|
||||||
|
reqiore("uCompat.Nifi")
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,13 @@ function screen.drawFillRect(scr, x0, y0, x1, y1, color)
|
||||||
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
|
||||||
|
|
||||||
function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color)
|
function screen.drawGradientRect(scr, x0, y0, x1, y1, color1, color2, color3, color4)
|
||||||
|
local midX = math.ceil((x1-x0)/2)
|
||||||
|
local midY = math.ceil((y1-y0)/2)
|
||||||
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0, offsetY+y0, midX, midY, 0, RGB2RGBA(color1)}}
|
||||||
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0+midX, offsetY+y0, midX, midY, 0, RGB2RGBA(color2)}}
|
||||||
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0, offsetY+y0+midY, midX, midY, 0, RGB2RGBA(color3)}}
|
||||||
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0+midX, offsetY+y0+midY, midX, midY, 0, RGB2RGBA(color4)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawTextBox(scr, x0, y0, x1, y1, text, color)
|
function screen.drawTextBox(scr, x0, y0, x1, y1, text, color)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue