mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-02 12:32:40 +02:00
fix element function replacement option
This commit is contained in:
@@ -648,13 +648,17 @@ int luatpt_element_func(lua_State *l)
|
|||||||
if(lua_isfunction(l, 1))
|
if(lua_isfunction(l, 1))
|
||||||
{
|
{
|
||||||
int element = luaL_optint(l, 2, 0);
|
int element = luaL_optint(l, 2, 0);
|
||||||
|
int replace = luaL_optint(l, 3, 0);
|
||||||
int function;
|
int function;
|
||||||
lua_pushvalue(l, 1);
|
lua_pushvalue(l, 1);
|
||||||
function = luaL_ref(l, LUA_REGISTRYINDEX);
|
function = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
if(element > 0 && element < PT_NUM)
|
if(element > 0 && element < PT_NUM)
|
||||||
{
|
{
|
||||||
lua_el_func[element] = function;
|
lua_el_func[element] = function;
|
||||||
luacon_sim->elements[element].Update = &luacon_elementReplacement;
|
if(replace)
|
||||||
|
lua_el_mode[element] = 2;
|
||||||
|
else
|
||||||
|
lua_el_mode[element] = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -35,7 +35,6 @@ int luacon_step(int mx, int my, int selectl, int selectr, int bsx, int bsy);
|
|||||||
int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel);
|
int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel);
|
||||||
int luacon_keyevent(int key, int modifier, int event);
|
int luacon_keyevent(int key, int modifier, int event);
|
||||||
int luacon_eval(char *command);
|
int luacon_eval(char *command);
|
||||||
int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt);
|
|
||||||
char *luacon_geterror();
|
char *luacon_geterror();
|
||||||
void luacon_close();
|
void luacon_close();
|
||||||
int luacon_partsread(lua_State* l);
|
int luacon_partsread(lua_State* l);
|
||||||
|
@@ -913,11 +913,12 @@ int LuaScriptInterface::elements_element(lua_State * l)
|
|||||||
if(lua_type(l, -1) == LUA_TFUNCTION)
|
if(lua_type(l, -1) == LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
luacon_sim->elements[id].Update = &luacon_elementReplacement;
|
lua_el_mode[id] = 1;
|
||||||
}
|
}
|
||||||
else if(lua_type(l, -1) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
else if(lua_type(l, -1) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
||||||
{
|
{
|
||||||
lua_el_func[id] = 0;
|
lua_el_func[id] = 0;
|
||||||
|
lua_el_mode[id] = 0;
|
||||||
luacon_sim->elements[id].Update = NULL;
|
luacon_sim->elements[id].Update = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -926,12 +927,12 @@ int LuaScriptInterface::elements_element(lua_State * l)
|
|||||||
lua_getfield(l, -1, "Graphics");
|
lua_getfield(l, -1, "Graphics");
|
||||||
if(lua_type(l, -1) == LUA_TFUNCTION)
|
if(lua_type(l, -1) == LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
lua_gr_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement;
|
luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement;
|
||||||
}
|
}
|
||||||
else if(lua_type(l, -1) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
else if(lua_type(l, -1) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
||||||
{
|
{
|
||||||
lua_el_func[id] = 0;
|
lua_gr_func[id] = 0;
|
||||||
luacon_sim->elements[id].Graphics = NULL;
|
luacon_sim->elements[id].Graphics = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1068,7 +1069,17 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
{
|
{
|
||||||
lua_pushvalue(l, 3);
|
lua_pushvalue(l, 3);
|
||||||
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
luacon_sim->elements[id].Update = &luacon_elementReplacement;
|
if (args > 3)
|
||||||
|
{
|
||||||
|
luaL_checktype(l, 4, LUA_TNUMBER);
|
||||||
|
int replace = lua_tointeger(l, 4);
|
||||||
|
if (replace == 1)
|
||||||
|
lua_el_mode[id] = 2;
|
||||||
|
else
|
||||||
|
lua_el_mode[id] = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_el_mode[id] = 1;
|
||||||
}
|
}
|
||||||
else if(lua_type(l, 3) == LUA_TLIGHTUSERDATA)
|
else if(lua_type(l, 3) == LUA_TLIGHTUSERDATA)
|
||||||
{
|
{
|
||||||
@@ -1078,6 +1089,7 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
||||||
{
|
{
|
||||||
lua_el_func[id] = 0;
|
lua_el_func[id] = 0;
|
||||||
|
lua_el_mode[id] = 0;
|
||||||
luacon_sim->elements[id].Update = NULL;
|
luacon_sim->elements[id].Update = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1086,12 +1098,12 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
if(lua_type(l, 3) == LUA_TFUNCTION)
|
if(lua_type(l, 3) == LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
lua_pushvalue(l, 3);
|
lua_pushvalue(l, 3);
|
||||||
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
lua_gr_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement;
|
luacon_sim->elements[id].Graphics = &luacon_graphicsReplacement;
|
||||||
}
|
}
|
||||||
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
||||||
{
|
{
|
||||||
lua_el_func[id] = 0;
|
lua_gr_func[id] = 0;
|
||||||
luacon_sim->elements[id].Graphics = NULL;
|
luacon_sim->elements[id].Graphics = NULL;
|
||||||
}
|
}
|
||||||
std::fill(luacon_ren->graphicscache, luacon_ren->graphicscache+PT_NUM, gcache_item());
|
std::fill(luacon_ren->graphicscache, luacon_ren->graphicscache+PT_NUM, gcache_item());
|
||||||
|
@@ -24,8 +24,8 @@
|
|||||||
#include "Snapshot.h"
|
#include "Snapshot.h"
|
||||||
//#include "StorageClasses.h"
|
//#include "StorageClasses.h"
|
||||||
|
|
||||||
#undef LUACONSOLE
|
#include "cat/LuaScriptInterface.h"
|
||||||
//#include "cat/LuaScriptHelper.h"
|
#include "cat/LuaScriptHelper.h"
|
||||||
|
|
||||||
int Simulation::Load(GameSave * save)
|
int Simulation::Load(GameSave * save)
|
||||||
{
|
{
|
||||||
@@ -4132,13 +4132,9 @@ void Simulation::update_particles_i(int start, int inc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//call the particle update function, if there is one
|
//call the particle update function, if there is one
|
||||||
#ifdef LUACONSOLE
|
|
||||||
if (elements[t].Update && lua_el_mode[t] != 2)
|
if (elements[t].Update && lua_el_mode[t] != 2)
|
||||||
#else
|
|
||||||
if (elements[t].Update)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if ((*(elements[t].Update))(this, i,x,y,surround_space,nt, parts, pmap))
|
if ((*(elements[t].Update))(this, i, x, y, surround_space, nt, parts, pmap))
|
||||||
continue;
|
continue;
|
||||||
else if (t==PT_WARP)
|
else if (t==PT_WARP)
|
||||||
{
|
{
|
||||||
@@ -4147,17 +4143,14 @@ void Simulation::update_particles_i(int start, int inc)
|
|||||||
y = (int)(parts[i].y+0.5f);
|
y = (int)(parts[i].y+0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef LUACONSOLE
|
|
||||||
if(lua_el_mode[t])
|
if(lua_el_mode[t])
|
||||||
{
|
{
|
||||||
if(luacon_part_update(t,i,x,y,surround_space,nt))
|
if(luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap))
|
||||||
continue;
|
continue;
|
||||||
// Need to update variables, in case they've been changed by Lua
|
// Need to update variables, in case they've been changed by Lua
|
||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
y = (int)(parts[i].y+0.5f);
|
y = (int)(parts[i].y+0.5f);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if(legacy_enable)//if heat sim is off
|
if(legacy_enable)//if heat sim is off
|
||||||
Element::legacyUpdate(this, i,x,y,surround_space,nt, parts, pmap);
|
Element::legacyUpdate(this, i,x,y,surround_space,nt, parts, pmap);
|
||||||
|
Reference in New Issue
Block a user