mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-17 09:32:33 +00:00
Allow access to skin.sprites[]
Only numframes so far though, as there's already a function for what spriteframe provides.
This commit is contained in:
parent
9b151ca45c
commit
1320f10839
3 changed files with 66 additions and 1 deletions
|
@ -162,6 +162,8 @@ static const struct {
|
||||||
{META_SKIN, "skin_t"},
|
{META_SKIN, "skin_t"},
|
||||||
{META_POWERS, "player_t.powers"},
|
{META_POWERS, "player_t.powers"},
|
||||||
{META_SOUNDSID, "skin_t.soundsid"},
|
{META_SOUNDSID, "skin_t.soundsid"},
|
||||||
|
{META_SKINSPRITES, "skin_t.sprites"},
|
||||||
|
{META_SKINSPRITESLIST, "skin_t.sprites[]"},
|
||||||
|
|
||||||
{META_VERTEX, "vertex_t"},
|
{META_VERTEX, "vertex_t"},
|
||||||
{META_LINE, "line_t"},
|
{META_LINE, "line_t"},
|
||||||
|
|
|
@ -34,6 +34,8 @@ extern lua_State *gL;
|
||||||
#define META_SKIN "SKIN_T*"
|
#define META_SKIN "SKIN_T*"
|
||||||
#define META_POWERS "PLAYER_T*POWERS"
|
#define META_POWERS "PLAYER_T*POWERS"
|
||||||
#define META_SOUNDSID "SKIN_T*SOUNDSID"
|
#define META_SOUNDSID "SKIN_T*SOUNDSID"
|
||||||
|
#define META_SKINSPRITES "SKIN_T*SPRITES"
|
||||||
|
#define META_SKINSPRITESLIST "SKIN_T*SPRITES[]"
|
||||||
|
|
||||||
#define META_VERTEX "VERTEX_T*"
|
#define META_VERTEX "VERTEX_T*"
|
||||||
#define META_LINE "LINE_T*"
|
#define META_LINE "LINE_T*"
|
||||||
|
|
|
@ -54,7 +54,8 @@ enum skin {
|
||||||
skin_contspeed,
|
skin_contspeed,
|
||||||
skin_contangle,
|
skin_contangle,
|
||||||
skin_soundsid,
|
skin_soundsid,
|
||||||
skin_availability
|
skin_availability,
|
||||||
|
skin_sprites
|
||||||
};
|
};
|
||||||
static const char *const skin_opt[] = {
|
static const char *const skin_opt[] = {
|
||||||
"valid",
|
"valid",
|
||||||
|
@ -93,6 +94,7 @@ static const char *const skin_opt[] = {
|
||||||
"contangle",
|
"contangle",
|
||||||
"soundsid",
|
"soundsid",
|
||||||
"availability",
|
"availability",
|
||||||
|
"sprites",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
#define UNIMPLEMENTED luaL_error(L, LUA_QL("skin_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", skin_opt[field])
|
#define UNIMPLEMENTED luaL_error(L, LUA_QL("skin_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", skin_opt[field])
|
||||||
|
@ -214,6 +216,9 @@ static int skin_get(lua_State *L)
|
||||||
case skin_availability:
|
case skin_availability:
|
||||||
lua_pushinteger(L, skin->availability);
|
lua_pushinteger(L, skin->availability);
|
||||||
break;
|
break;
|
||||||
|
case skin_sprites:
|
||||||
|
LUA_PushUserdata(L, skin->sprites, META_SKINSPRITES);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -324,6 +329,49 @@ static int soundsid_num(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum spritesopt {
|
||||||
|
numframes = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *const sprites_opt[] = {
|
||||||
|
"numframes",
|
||||||
|
NULL};
|
||||||
|
|
||||||
|
// skin.sprites[i] -> sprites[i]
|
||||||
|
static int lib_getSkinSprite(lua_State *L)
|
||||||
|
{
|
||||||
|
spritedef_t *sprites = *((spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITES));
|
||||||
|
playersprite_t i = luaL_checkinteger(L, 2);
|
||||||
|
|
||||||
|
if (i < 0 || i >= NUMPLAYERSPRITES*2)
|
||||||
|
return luaL_error(L, "skin.sprites[] index %d out of range (0 - %d)", i, (NUMPLAYERSPRITES*2)-1);
|
||||||
|
|
||||||
|
LUA_PushLightUserdata(L, &sprites[i], META_SKINSPRITESLIST);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #skin.sprites -> NUMPLAYERSPRITES*2
|
||||||
|
static int lib_numSkinsSprites(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, NUMPLAYERSPRITES*2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sprite_get(lua_State *L)
|
||||||
|
{
|
||||||
|
spritedef_t *sprite = (spritedef_t *)luaL_checkudata(L, 1, META_SKINSPRITESLIST);
|
||||||
|
enum spritesopt field = luaL_checkoption(L, 2, NULL, sprites_opt);
|
||||||
|
|
||||||
|
switch (field)
|
||||||
|
{
|
||||||
|
case numframes:
|
||||||
|
lua_pushinteger(L, sprite->numframes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int LUA_SkinLib(lua_State *L)
|
int LUA_SkinLib(lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_newmetatable(L, META_SKIN);
|
luaL_newmetatable(L, META_SKIN);
|
||||||
|
@ -345,6 +393,19 @@ int LUA_SkinLib(lua_State *L)
|
||||||
lua_setfield(L, -2, "__len");
|
lua_setfield(L, -2, "__len");
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
|
|
||||||
|
luaL_newmetatable(L, META_SKINSPRITES);
|
||||||
|
lua_pushcfunction(L, lib_getSkinSprite);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lua_pushcfunction(L, lib_numSkinsSprites);
|
||||||
|
lua_setfield(L, -2, "__len");
|
||||||
|
lua_pop(L,1);
|
||||||
|
|
||||||
|
luaL_newmetatable(L, META_SKINSPRITESLIST);
|
||||||
|
lua_pushcfunction(L, sprite_get);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
lua_pop(L,1);
|
||||||
|
|
||||||
lua_newuserdata(L, 0);
|
lua_newuserdata(L, 0);
|
||||||
lua_createtable(L, 0, 2);
|
lua_createtable(L, 0, 2);
|
||||||
lua_pushcfunction(L, lib_getSkin);
|
lua_pushcfunction(L, lib_getSkin);
|
||||||
|
|
Loading…
Reference in a new issue