Update set_mapgen_params and set_gen_notify Lua API to use new flag format
parent
db98ef6b45
commit
28d6326bd4
|
@ -840,23 +840,32 @@ void push_hit_params(lua_State *L,const HitParams ¶ms)
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u32 getflagsfield(lua_State *L, int table, const char *fieldname,
|
||||
FlagDesc *flagdesc, u32 *flagmask)
|
||||
{
|
||||
u32 flags = 0;
|
||||
|
||||
bool getflagsfield(lua_State *L, int table, const char *fieldname,
|
||||
FlagDesc *flagdesc, u32 *flags, u32 *flagmask)
|
||||
{
|
||||
lua_getfield(L, table, fieldname);
|
||||
|
||||
if (lua_isstring(L, -1)) {
|
||||
std::string flagstr = lua_tostring(L, -1);
|
||||
flags = readFlagString(flagstr, flagdesc, flagmask);
|
||||
} else if (lua_istable(L, -1)) {
|
||||
flags = read_flags_table(L, -1, flagdesc, flagmask);
|
||||
}
|
||||
bool success = read_flags(L, -1, flagdesc, flags, flagmask);
|
||||
|
||||
lua_pop(L, 1);
|
||||
|
||||
return flags;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool read_flags(lua_State *L, int index, FlagDesc *flagdesc,
|
||||
u32 *flags, u32 *flagmask)
|
||||
{
|
||||
if (lua_isstring(L, index)) {
|
||||
std::string flagstr = lua_tostring(L, index);
|
||||
*flags = readFlagString(flagstr, flagdesc, flagmask);
|
||||
} else if (lua_istable(L, index)) {
|
||||
*flags = read_flags_table(L, index, flagdesc, flagmask);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask)
|
||||
|
|
|
@ -119,9 +119,14 @@ int getenumfield (lua_State *L,
|
|||
const EnumString *spec,
|
||||
int default_);
|
||||
|
||||
u32 getflagsfield (lua_State *L, int table,
|
||||
bool getflagsfield (lua_State *L, int table,
|
||||
const char *fieldname,
|
||||
FlagDesc *flagdesc, u32 *flagmask);
|
||||
FlagDesc *flagdesc,
|
||||
u32 *flags, u32 *flagmask);
|
||||
|
||||
bool read_flags (lua_State *L, int index,
|
||||
FlagDesc *flagdesc,
|
||||
u32 *flags, u32 *flagmask);
|
||||
|
||||
u32 read_flags_table (lua_State *L, int table,
|
||||
FlagDesc *flagdesc, u32 *flagmask);
|
||||
|
|
|
@ -189,9 +189,10 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
|
|||
return 0;
|
||||
|
||||
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
||||
ASSERT(emerge);
|
||||
assert(emerge);
|
||||
|
||||
std::string flagstr;
|
||||
u32 flags = 0, flagmask = 0;
|
||||
|
||||
lua_getfield(L, 1, "mgname");
|
||||
if (lua_isstring(L, -1)) {
|
||||
|
@ -216,13 +217,7 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
|
|||
"see lua_api.txt" << std::endl;
|
||||
}
|
||||
|
||||
lua_getfield(L, 1, "flags");
|
||||
if (lua_isstring(L, -1)) {
|
||||
u32 flags, flagmask;
|
||||
|
||||
flagstr = lua_tostring(L, -1);
|
||||
flags = readFlagString(flagstr, flagdesc_mapgen, &flagmask);
|
||||
|
||||
if (getflagsfield(L, 1, "flags", flagdesc_mapgen, &flags, &flagmask)) {
|
||||
emerge->params.flags &= ~flagmask;
|
||||
emerge->params.flags |= flags;
|
||||
}
|
||||
|
@ -260,11 +255,13 @@ int ModApiMapgen::l_set_noiseparam_defaults(lua_State *L)
|
|||
// set_gen_notify(string)
|
||||
int ModApiMapgen::l_set_gen_notify(lua_State *L)
|
||||
{
|
||||
if (lua_isstring(L, 1)) {
|
||||
u32 flags = 0, flagmask = 0;
|
||||
|
||||
if (read_flags(L, 1, flagdesc_gennotify, &flags, &flagmask)) {
|
||||
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
||||
emerge->gennotify = readFlagString(lua_tostring(L, 1),
|
||||
flagdesc_gennotify, NULL);
|
||||
emerge->gennotify = flags;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -407,8 +404,11 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
|
|||
break; }
|
||||
case DECO_SCHEMATIC: {
|
||||
DecoSchematic *dschem = (DecoSchematic *)deco;
|
||||
dschem->flags = getflagsfield(L, index, "flags",
|
||||
flagdesc_deco_schematic, NULL);
|
||||
|
||||
dschem->flags = 0;
|
||||
getflagsfield(L, index, "flags", flagdesc_deco_schematic,
|
||||
&dschem->flags, NULL);
|
||||
|
||||
dschem->rotation = (Rotation)getenumfield(L, index,
|
||||
"rotation", es_Rotation, ROTATE_0);
|
||||
|
||||
|
@ -482,8 +482,10 @@ int ModApiMapgen::l_register_ore(lua_State *L)
|
|||
ore->clust_size = getintfield_default(L, index, "clust_size", 0);
|
||||
ore->height_min = getintfield_default(L, index, "height_min", 0);
|
||||
ore->height_max = getintfield_default(L, index, "height_max", 0);
|
||||
ore->flags = getflagsfield(L, index, "flags", flagdesc_ore, NULL);
|
||||
ore->nthresh = getfloatfield_default(L, index, "noise_threshhold", 0.);
|
||||
ore->flags = 0;
|
||||
getflagsfield(L, index, "flags", flagdesc_ore, &ore->flags, NULL);
|
||||
|
||||
lua_getfield(L, index, "wherein");
|
||||
if (lua_istable(L, -1)) {
|
||||
int i = lua_gettop(L);
|
||||
|
|
Loading…
Reference in New Issue