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

Added documentation for gfx.map and ctr.qtm modules

This commit is contained in:
Firew0lf 2015-09-12 19:29:11 +02:00
parent 0773992b68
commit e94da040f7
2 changed files with 123 additions and 0 deletions

View file

@ -1,3 +1,9 @@
/***
The `map` module.
@module ctr.gfx.map
@usage local map = require("ctr.gfx.map")
*/
#include <sf2d.h>
#include <lapi.h>
@ -30,6 +36,16 @@ u16 getTile(map_userdata *map, int x, int y) {
}
// module functions
/***
Load a map from a file.
@function load
@tparam string path path to the .map
@tparam texture tileset containing the tileset
@tparam number tileWidth tile width
@tparam number tileHeight tile height
@treturn map loaded map object
*/
static int map_load(lua_State *L) {
const char *mapPath = luaL_checkstring(L, 1);
texture_userdata *texture = luaL_checkudata(L, 2, "LTexture");
@ -91,6 +107,18 @@ static int map_load(lua_State *L) {
return 1;
}
/***
Map object
@section Methods
*/
/***
Draw a map.
@function :draw
@tparam number x X position
@tparam number y Y position
@within Methods
*/
static int map_draw(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);
@ -120,6 +148,11 @@ static int map_draw(lua_State *L) {
return 0;
}
/***
Unload a map.
@function :unload
@within Methods
*/
static int map_unload(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
free(map->data);
@ -127,6 +160,13 @@ static int map_unload(lua_State *L) {
return 0;
}
/***
Return the size of a map.
@function :getSize
@treturn number width of the map, in tiles
@treturn number height of the map, in tiles
@within Methods
*/
static int map_getSize(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
@ -136,6 +176,14 @@ static int map_getSize(lua_State *L) {
return 2;
}
/***
Return the value of a tile.
@function :getTile
@tparam number x X position of the tile
@tparam number y Y position of the tile
@treturn number value of the tile
@within Methods
*/
static int map_getTile(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);
@ -145,6 +193,14 @@ static int map_getTile(lua_State *L) {
return 1;
}
/***
Set the value of a tile.
@function :setTile
@tparam number x X position of the tile
@tparam number y Y position of the tile
@tparam number value New value for the tile
@within Methods
*/
static int map_setTile(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);

View file

@ -1,3 +1,9 @@
/***
The `qtm` module, for headtracking. New3ds only.
@module ctr.qtm
@usage local qtm = require("ctr.qtm")
@newonly
*/
#include <3ds.h>
#include <3ds/types.h>
#include <3ds/services/qtm.h>
@ -13,6 +19,10 @@ typedef struct {
static const struct luaL_Reg qtm_methods[];
/***
Initialize the QTM module.
@function init
*/
static int qtm_init(lua_State *L) {
Result ret = qtmInit();
if (ret) {
@ -25,12 +35,21 @@ static int qtm_init(lua_State *L) {
return 1;
}
/***
Disable the QTM module.
@function shutdown
*/
static int qtm_shutdown(lua_State *L) {
qtmExit();
return 0;
}
/***
Check if the module is initialized.
@function checkInitialized
@treturn boolean `true` if initialized.
*/
static int qtm_checkInitialized(lua_State *L) {
bool isInit = qtmCheckInitialized();
@ -38,6 +57,11 @@ static int qtm_checkInitialized(lua_State *L) {
return 1;
}
/***
Return informations about the headtracking
@function getHeadTrackingInfo
@treturn qtmInfos QTM informations
*/
static int qtm_getHeadtrackingInfo(lua_State *L) {
qtm_userdata *data = lua_newuserdata(L, sizeof(*data));
luaL_getmetatable(L, "LQTM");
@ -50,6 +74,12 @@ static int qtm_getHeadtrackingInfo(lua_State *L) {
return 1;
}
/***
Check if the head is fully detected
@function checkHeadFullyDetected
@tparam qtmInfos qtmInfos QTM informations
@treturn boolean `true` if fully detected
*/
static int qtm_checkHeadFullyDetected(lua_State *L) {
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
lua_pushboolean(L, qtmCheckHeadFullyDetected(info->info));
@ -84,6 +114,16 @@ static int qtm___index(lua_State *L) {
return 1;
}
/***
Convert QTM coordinates to screen coordinates
@function convertCoordToScreen
@tparam qtmInfos qtmInfos QTM informations
@tparam number coordinates index
@tparam number [screenWidth] specify a screen width (default `400`)
@tparam number [screenHeight] specify a screen height (default `320`)
@treturn number screen X coordinate
@treturn number screen Y coordinate
*/
static int qtm_convertCoordToScreen(lua_State *L) {
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
lua_Integer index = luaL_checkinteger(L, 2);
@ -105,6 +145,33 @@ static int qtm_convertCoordToScreen(lua_State *L) {
return 2;
}
/***
qtmInfos object
@section Methods
*/
/***
Check if the head is fully detected
@function :checkHeadFullyDetected
@treturn boolean `true` if fully detected
*/
/***
Convert QTM coordinates to screen coordinates
@function :convertCoordToScreen
@tparam number coordinates index
@tparam number [screenWidth] specify a screen width (default `400`)
@tparam number [screenHeight] specify a screen height (default `320`)
@treturn number screen X coordinate
@treturn number screen Y coordinate
*/
/***
When the object is indexed with a number from 1 to 4, it returns a coordinate
of one of the headtracker point.
@tfield number index coordinates, as two numbers (not a table)
*/
// object
static const struct luaL_Reg qtm_methods[] = {
{"checkHeadFullyDetected", qtm_checkHeadFullyDetected},