2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-07-06 04:09:17 +00:00
|
|
|
// Copyright (C) 2014-2016 by John "JTE" Muniz.
|
2018-11-25 12:35:38 +00:00
|
|
|
// Copyright (C) 2014-2018 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file lua_skinlib.c
|
|
|
|
/// \brief player skin structure library for Lua scripting
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#ifdef HAVE_BLUA
|
|
|
|
#include "fastcmp.h"
|
|
|
|
#include "r_things.h"
|
2014-08-04 03:49:33 +00:00
|
|
|
#include "sounds.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#include "lua_script.h"
|
|
|
|
#include "lua_libs.h"
|
|
|
|
|
|
|
|
enum skin {
|
|
|
|
skin_valid = 0,
|
|
|
|
skin_name,
|
|
|
|
skin_spritedef,
|
|
|
|
skin_wadnum,
|
|
|
|
skin_flags,
|
|
|
|
skin_realname,
|
|
|
|
skin_hudname,
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
skin_facerank,
|
|
|
|
skin_facewant,
|
|
|
|
skin_facemmap,
|
2017-02-07 22:19:04 +00:00
|
|
|
// SRB2kart
|
|
|
|
skin_kartspeed,
|
|
|
|
skin_kartweight,
|
|
|
|
//
|
2014-03-15 16:59:03 +00:00
|
|
|
skin_starttranscolor,
|
|
|
|
skin_prefcolor,
|
|
|
|
skin_highresscale,
|
|
|
|
skin_soundsid
|
|
|
|
};
|
|
|
|
static const char *const skin_opt[] = {
|
|
|
|
"valid",
|
|
|
|
"name",
|
|
|
|
"spritedef",
|
|
|
|
"wadnum",
|
|
|
|
"flags",
|
|
|
|
"realname",
|
|
|
|
"hudname",
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
"facerank",
|
|
|
|
"facewant",
|
|
|
|
"facemmap",
|
2017-02-07 22:19:04 +00:00
|
|
|
// SRB2kart
|
|
|
|
"kartspeed",
|
|
|
|
"kartweight",
|
|
|
|
//
|
2014-03-15 16:59:03 +00:00
|
|
|
"starttranscolor",
|
|
|
|
"prefcolor",
|
|
|
|
"highresscale",
|
|
|
|
"soundsid",
|
|
|
|
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])
|
|
|
|
|
|
|
|
static int skin_get(lua_State *L)
|
|
|
|
{
|
|
|
|
skin_t *skin = *((skin_t **)luaL_checkudata(L, 1, META_SKIN));
|
|
|
|
enum skin field = luaL_checkoption(L, 2, NULL, skin_opt);
|
|
|
|
INT32 i;
|
|
|
|
|
|
|
|
// skins are always valid, only added, never removed
|
|
|
|
I_Assert(skin != NULL);
|
|
|
|
|
|
|
|
switch (field)
|
|
|
|
{
|
|
|
|
case skin_valid:
|
|
|
|
lua_pushboolean(L, skin != NULL);
|
|
|
|
break;
|
|
|
|
case skin_name:
|
|
|
|
lua_pushstring(L, skin->name);
|
|
|
|
break;
|
|
|
|
case skin_spritedef:
|
|
|
|
return UNIMPLEMENTED;
|
|
|
|
case skin_wadnum:
|
|
|
|
// !!WARNING!! May differ between clients due to music wads, therefore NOT NETWORK SAFE
|
|
|
|
return UNIMPLEMENTED;
|
|
|
|
case skin_flags:
|
|
|
|
lua_pushinteger(L, skin->flags);
|
|
|
|
break;
|
|
|
|
case skin_realname:
|
|
|
|
lua_pushstring(L, skin->realname);
|
|
|
|
break;
|
|
|
|
case skin_hudname:
|
|
|
|
lua_pushstring(L, skin->hudname);
|
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
case skin_facerank:
|
2014-03-15 16:59:03 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
if (!skin->facerank[i])
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
lua_pushlstring(L, skin->facerank, i);
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
case skin_facewant:
|
2014-03-15 16:59:03 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
if (!skin->facewant[i])
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
lua_pushlstring(L, skin->facewant, i);
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
case skin_facemmap:
|
2014-03-15 16:59:03 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
if (!skin->facemmap[i])
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
Stupidbad-big commit, but PLEASE don't ask me to re-do this on another branch, I swear to god. I know it makes things more difficult on you, and I'm sorry for that, but I'm definitely feeling the goddamn crunch right now and I wanna take a step back from this spaghetti nightmare and clear my head.
* Do that thing where the character icons are ALWAYS 1x sized, through having two seperate lumps.
* Revamp the S_SKIN parameters to be `facerank` (rankings - equivalent of half-scale old face), `facewant` (WANTED - equivalent of old face), and `facemmap` (equivalent of old iconprefix).
* Do that thing Oni wanted where it shows two postions above and two positions below your current ranking (and you) to the left of the screen, instead of always the top 4, with some limits to avoid drawing outside of everything.
* Replace the last few shitty Mario numbers (for the left rankings) with cool, new Oni numbers.
* Change a bunch of offsets and things so the tab rankings and the intermission work nicer with 9+ players.
2018-10-28 16:27:55 +00:00
|
|
|
lua_pushlstring(L, skin->facemmap, i);
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
2017-02-07 22:19:04 +00:00
|
|
|
// SRB2kart
|
|
|
|
case skin_kartspeed:
|
2017-11-20 00:39:40 +00:00
|
|
|
lua_pushinteger(L, skin->kartspeed);
|
2017-02-07 22:19:04 +00:00
|
|
|
break;
|
|
|
|
case skin_kartweight:
|
2017-11-20 00:39:40 +00:00
|
|
|
lua_pushinteger(L, skin->kartweight);
|
2017-02-07 22:19:04 +00:00
|
|
|
break;
|
|
|
|
//
|
2014-03-15 16:59:03 +00:00
|
|
|
case skin_starttranscolor:
|
|
|
|
lua_pushinteger(L, skin->starttranscolor);
|
|
|
|
break;
|
|
|
|
case skin_prefcolor:
|
|
|
|
lua_pushinteger(L, skin->prefcolor);
|
|
|
|
break;
|
|
|
|
case skin_highresscale:
|
|
|
|
lua_pushinteger(L, skin->highresscale);
|
|
|
|
break;
|
|
|
|
case skin_soundsid:
|
2014-08-04 03:49:33 +00:00
|
|
|
LUA_PushUserdata(L, skin->soundsid, META_SOUNDSID);
|
|
|
|
break;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int skin_set(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaL_error(L, LUA_QL("skin_t") " struct cannot be edited by Lua.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int skin_num(lua_State *L)
|
|
|
|
{
|
|
|
|
skin_t *skin = *((skin_t **)luaL_checkudata(L, 1, META_SKIN));
|
|
|
|
|
|
|
|
// skins are always valid, only added, never removed
|
|
|
|
I_Assert(skin != NULL);
|
|
|
|
|
|
|
|
lua_pushinteger(L, skin-skins);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lib_iterateSkins(lua_State *L)
|
|
|
|
{
|
|
|
|
INT32 i;
|
|
|
|
|
|
|
|
if (lua_gettop(L) < 2)
|
|
|
|
{
|
|
|
|
//return luaL_error(L, "Don't call skins.iterate() directly, use it as 'for skin in skins.iterate do <block> end'.");
|
|
|
|
lua_pushcfunction(L, lib_iterateSkins);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_settop(L, 2);
|
|
|
|
lua_remove(L, 1); // state is unused.
|
|
|
|
|
|
|
|
if (!lua_isnil(L, 1))
|
|
|
|
i = (INT32)(*((skin_t **)luaL_checkudata(L, 1, META_SKIN)) - skins) + 1;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
// skins are always valid, only added, never removed
|
|
|
|
if (i < numskins)
|
|
|
|
{
|
|
|
|
LUA_PushUserdata(L, &skins[i], META_SKIN);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lib_getSkin(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *field;
|
|
|
|
INT32 i;
|
|
|
|
|
|
|
|
// find skin by number
|
|
|
|
if (lua_type(L, 2) == LUA_TNUMBER)
|
|
|
|
{
|
|
|
|
i = luaL_checkinteger(L, 2);
|
|
|
|
if (i < 0 || i >= MAXSKINS)
|
2016-07-06 04:09:17 +00:00
|
|
|
return luaL_error(L, "skins[] index %d out of range (0 - %d)", i, MAXSKINS-1);
|
2014-03-15 16:59:03 +00:00
|
|
|
if (i >= numskins)
|
|
|
|
return 0;
|
|
|
|
LUA_PushUserdata(L, &skins[i], META_SKIN);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
field = luaL_checkstring(L, 2);
|
|
|
|
|
|
|
|
// special function iterate
|
|
|
|
if (fastcmp(field,"iterate"))
|
|
|
|
{
|
|
|
|
lua_pushcfunction(L, lib_iterateSkins);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find skin by name
|
|
|
|
for (i = 0; i < numskins; i++)
|
|
|
|
if (fastcmp(skins[i].name, field))
|
|
|
|
{
|
|
|
|
LUA_PushUserdata(L, &skins[i], META_SKIN);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lib_numSkins(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, numskins);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-04 03:49:33 +00:00
|
|
|
// soundsid, i -> soundsid[i]
|
|
|
|
static int soundsid_get(lua_State *L)
|
|
|
|
{
|
|
|
|
sfxenum_t *soundsid = *((sfxenum_t **)luaL_checkudata(L, 1, META_SOUNDSID));
|
|
|
|
skinsound_t i = luaL_checkinteger(L, 2);
|
|
|
|
if (i >= NUMSKINSOUNDS)
|
|
|
|
return luaL_error(L, LUA_QL("skinsound_t") " cannot be %u", i);
|
|
|
|
lua_pushinteger(L, soundsid[i]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// #soundsid -> NUMSKINSOUNDS
|
|
|
|
static int soundsid_num(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, NUMSKINSOUNDS);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
int LUA_SkinLib(lua_State *L)
|
|
|
|
{
|
|
|
|
luaL_newmetatable(L, META_SKIN);
|
|
|
|
lua_pushcfunction(L, skin_get);
|
|
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
|
|
|
|
lua_pushcfunction(L, skin_set);
|
|
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
|
|
|
|
lua_pushcfunction(L, skin_num);
|
|
|
|
lua_setfield(L, -2, "__len");
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
2014-08-04 03:49:33 +00:00
|
|
|
luaL_newmetatable(L, META_SOUNDSID);
|
|
|
|
lua_pushcfunction(L, soundsid_get);
|
|
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
|
|
|
|
lua_pushcfunction(L, soundsid_num);
|
|
|
|
lua_setfield(L, -2, "__len");
|
|
|
|
lua_pop(L,1);
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_newuserdata(L, 0);
|
|
|
|
lua_createtable(L, 0, 2);
|
|
|
|
lua_pushcfunction(L, lib_getSkin);
|
|
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
|
|
|
|
lua_pushcfunction(L, lib_numSkins);
|
|
|
|
lua_setfield(L, -2, "__len");
|
|
|
|
lua_setmetatable(L, -2);
|
|
|
|
lua_setglobal(L, "skins");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|