mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added some examples, fixed a typo
This commit is contained in:
parent
b87b2676e6
commit
e10a101a4a
8 changed files with 225 additions and 2 deletions
56
sdcard/3ds/ctruLua/examples/cfgu/cfgu.lua
Normal file
56
sdcard/3ds/ctruLua/examples/cfgu/cfgu.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
local ctr = require("ctr")
|
||||
local gfx = require("ctr.gfx")
|
||||
local hid = require("ctr.hid")
|
||||
local cfgu = require("ctr.cfgu")
|
||||
|
||||
local regions = {
|
||||
[cfgu.REGION_JPN] = "Japan",
|
||||
[cfgu.REGION_USA] = "America",
|
||||
[cfgu.REGION_EUR] = "Europe",
|
||||
[cfgu.REGION_AUS] = "Australia",
|
||||
[cfgu.REGION_CHN] = "China",
|
||||
[cfgu.REGION_KOR] = "Korea",
|
||||
[cfgu.REGION_TWN] = "Taiwan"
|
||||
}
|
||||
|
||||
local languages = {
|
||||
[cfgu.LANGUAGE_JP] = "Japanese",
|
||||
[cfgu.LANGUAGE_EN] = "English",
|
||||
[cfgu.LANGUAGE_FR] = "French",
|
||||
[cfgu.LANGUAGE_DE] = "Deutch",
|
||||
[cfgu.LANGUAGE_IT] = "Italian",
|
||||
[cfgu.LANGUAGE_ES] = "Spanish",
|
||||
[cfgu.LANGUAGE_ZH] = "Chinese",
|
||||
[cfgu.LANGUAGE_KO] = "Korean",
|
||||
[cfgu.LANGUAGE_NL] = "Dutch",
|
||||
[cfgu.LANGUAGE_PT] = "Portuguese",
|
||||
[cfgu.LANGUAGE_RU] = "Russian",
|
||||
[cfgu.LANGUAGE_TW] = "Taiwanese"
|
||||
}
|
||||
|
||||
local models = {
|
||||
[cfgu.MODEL_3DS] = "3DS",
|
||||
[cfgu.MODEL_3DSXL] = "3DS XL",
|
||||
[cfgu.MODEL_N3DS] = "New 3DS",
|
||||
[cfgu.MODEL_2DS] = "2DS",
|
||||
[cfgu.MODEL_N3DSXL] = "New 3DS XL"
|
||||
}
|
||||
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
keys = hid.keys()
|
||||
if keys.down.start then break end
|
||||
|
||||
gfx.start(gfx.BOTTOM)
|
||||
gfx.text(2, 2, "CFGU example")
|
||||
gfx.text(2, 20, "Region: "..regions[cfgu.getRegion()])
|
||||
gfx.text(2, 30, "Model: "..models[cfgu.getModel()])
|
||||
gfx.text(2, 40, "Language: "..models[cfgu.getLanguage()])
|
||||
gfx.text(2, 50, "Username: "..cfgu.getUsername())
|
||||
local m,d = cfgu.getBirthday()
|
||||
gfx.text(2, 60, "Birthday: "..d.."/"..m)
|
||||
gfx.text(2, 70, "0 Hash: "..cfgu.genHash(0))
|
||||
gfx.stop()
|
||||
|
||||
gfx.render()
|
||||
end
|
||||
43
sdcard/3ds/ctruLua/examples/httpc/httpc.lua
Normal file
43
sdcard/3ds/ctruLua/examples/httpc/httpc.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local ctr = require("ctr")
|
||||
local gfx = require("ctr.gfx")
|
||||
local hid = require("ctr.hid")
|
||||
local httpc = require("ctr.httpc")
|
||||
|
||||
local err = 0
|
||||
local addr = "https://wtfismyip.com/text"
|
||||
local dls = 0
|
||||
|
||||
local context = assert(httpc.context())
|
||||
|
||||
assert(context:open(addr))
|
||||
assert(context:beginRequest())
|
||||
|
||||
local data = assert(context:downloadData())
|
||||
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
keys = hid.keys()
|
||||
if keys.held.start then break end
|
||||
if keys.down.b then
|
||||
assert(context:open(addr))
|
||||
assert(context:beginRequest())
|
||||
data = assert(context:downloadData())
|
||||
dls = dls + 1
|
||||
end
|
||||
|
||||
gfx.startFrame(gfx.TOP)
|
||||
gfx.text(0, 0, data)
|
||||
gfx.text(0, 20, "Downloaded "..dls.." times.")
|
||||
gfx.endFrame()
|
||||
|
||||
gfx.startFrame(gfx.BOTTOM)
|
||||
gfx.text(2, 2, "HTTP Contexts example")
|
||||
gfx.text(2, 20, "The data is downloaded from '"..addr.."'.")
|
||||
gfx.text(2, 30, "Press [B] to redownload.")
|
||||
gfx.endFrame()
|
||||
|
||||
gfx.render()
|
||||
end
|
||||
|
||||
|
||||
context:close()
|
||||
6
sdcard/3ds/ctruLua/examples/map/map.csv
Normal file
6
sdcard/3ds/ctruLua/examples/map/map.csv
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
0,0,0,0,0,0
|
||||
0,1,1,1,1,0
|
||||
0,1,3,2,1,0
|
||||
0,1,2,3,1,0
|
||||
0,1,1,1,1,0
|
||||
0,0,0,0,0,0
|
||||
|
49
sdcard/3ds/ctruLua/examples/map/map.lua
Normal file
49
sdcard/3ds/ctruLua/examples/map/map.lua
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
local ctr = require("ctr")
|
||||
local gfx = require("ctr.gfx")
|
||||
local map = require("ctr.gfx.map")
|
||||
local texture = require("ctr.gfx.texture")
|
||||
local hid = require("ctr.hid")
|
||||
|
||||
local tileset = assert(texture.load("tileset.png"))
|
||||
local map = assert(map.load("map.csv", tileset, 16, 16))
|
||||
|
||||
local x,y = 0,0
|
||||
local s = 0
|
||||
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
local keys = hid.keys()
|
||||
if keys.down.start then break end
|
||||
if keys.held.up then
|
||||
y = y - 1
|
||||
elseif keys.held.down then
|
||||
y = y + 1
|
||||
end
|
||||
if keys.held.left then
|
||||
x = x - 1
|
||||
elseif keys.held.right then
|
||||
x = x + 1
|
||||
end
|
||||
if keys.held.r then
|
||||
s = s + 1
|
||||
map:setSpace(s,s)
|
||||
elseif keys.held.l then
|
||||
s = s - 1
|
||||
map:setSpace(s,s)
|
||||
end
|
||||
|
||||
gfx.start(gfx.TOP)
|
||||
map:draw(x,y)
|
||||
gfx.stop()
|
||||
|
||||
gfx.start(gfx.BOTTOM)
|
||||
gfx.text(2, 2, "Map example")
|
||||
gfx.text(2, 20, "Press L (-) and R (+) to change the space between the tiles")
|
||||
gfx.text(2, 30, "Move the map with the D-pad or the C-pad")
|
||||
gfx.stop()
|
||||
|
||||
gfx.render()
|
||||
end
|
||||
|
||||
map:unload()
|
||||
tileset:unload()
|
||||
BIN
sdcard/3ds/ctruLua/examples/map/tileset.png
Normal file
BIN
sdcard/3ds/ctruLua/examples/map/tileset.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 185 B |
21
sdcard/3ds/ctruLua/examples/ptm/ptm.lua
Normal file
21
sdcard/3ds/ctruLua/examples/ptm/ptm.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
local ctr = require("ctr")
|
||||
local gfx = require("ctr.gfx")
|
||||
local hid = require("ctr.hid")
|
||||
local ptm = require("ctr.ptm")
|
||||
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
local keys = hid.keys()
|
||||
if keys.down.start then break end
|
||||
|
||||
gfx.start(gfx.TOP)
|
||||
gfx.text(2, 2, "PTM example")
|
||||
local level = ptm.getBatteryLevel()
|
||||
gfx.text(2, 20, "Battery level: ["..string.rep("|", level)..string.rep(" ", 5-level).."]")
|
||||
gfx.text(2, 30, "Charging: "..((ptm.getBatteryChargeState() and "Yes") or "No"))
|
||||
gfx.text(2, 40, "You walked: "..ptm.getTotalStepCount().." steps")
|
||||
gfx.text(2, 50, "Counting: "..((ptm.getPedometerState() and "Yes") or "No"))
|
||||
gfx.stop()
|
||||
|
||||
gfx.render()
|
||||
end
|
||||
48
sdcard/3ds/ctruLua/examples/qtm/qtm.lua
Normal file
48
sdcard/3ds/ctruLua/examples/qtm/qtm.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
local ctr = require("ctr")
|
||||
local hid = require("ctr.hid")
|
||||
local gfx = require("ctr.gfx")
|
||||
local qtm = require("ctr.qtm")
|
||||
|
||||
qtm.init()
|
||||
|
||||
if not qtm.checkInitialized() then
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
if hid.keys().down.start then
|
||||
break
|
||||
end
|
||||
gfx.start(gfx.TOP)
|
||||
gfx.text(2, 2, "Couldn't initialize the QTM module.")
|
||||
gfx.text(2, 12, "You need a New 3DS in order to use this.")
|
||||
gfx.stop()
|
||||
gfx.render()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
while ctr.run() do
|
||||
hid.read()
|
||||
local keys = hid.keys()
|
||||
if keys.down.start then break end
|
||||
|
||||
local infos = qtm.getHeadTrackingInfo()
|
||||
|
||||
gfx.start(gfx.TOP)
|
||||
if infos:checkHeadFullyDetected() then
|
||||
for i=1, 4 do
|
||||
gfx.point(infos:convertCoordToScreen(1, 400, 240))
|
||||
end
|
||||
end
|
||||
gfx.stop()
|
||||
|
||||
gfx.start(gfx.BOTTOM)
|
||||
gfx.text(0, 0, "QTM example")
|
||||
for i=1, 4 do
|
||||
local x,y = infos[i]
|
||||
gfx.text(0, 10*i, i..": "..x..";"..y)
|
||||
end
|
||||
gfx.stop()
|
||||
|
||||
gfx.render()
|
||||
end
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ struct { char *name; int value; } cfgu_constants[] = {
|
|||
/***
|
||||
Constant returned by `getLanguage` if the language is Italian.
|
||||
It is equal to `4`.
|
||||
@field LANGUAGE_JP
|
||||
@field LANGUAGE_IT
|
||||
*/
|
||||
{"LANGUAGE_IT", CFG_LANGUAGE_IT},
|
||||
/***
|
||||
|
|
@ -276,7 +276,7 @@ struct { char *name; int value; } cfgu_constants[] = {
|
|||
/***
|
||||
Constant returned by `getModel` if the console is a New 3DS.
|
||||
It is equal to `2`.
|
||||
@field MODEL_3DSXL
|
||||
@field MODEL_N3DS
|
||||
*/
|
||||
{"MODEL_N3DS", 2},
|
||||
/***
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue