summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-12-24 23:44:00 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-12-28 22:39:59 (GMT)
commit2553dac942b9b5c3ad6b834d32c9053d3592faaf (patch)
tree149c3e053f938c0f6a4e556aea4f408b180d2be4 /src
parent23d6823bc3b877451e40103d2007dee9ddb10cb0 (diff)
downloadpowder-2553dac942b9b5c3ad6b834d32c9053d3592faaf.zip
powder-2553dac942b9b5c3ad6b834d32c9053d3592faaf.tar.gz
Update can_move, recount menu items and clear graphics cache when tpt.el is changed
Diffstat (limited to 'src')
-rw-r--r--src/interface.c9
-rw-r--r--src/luaconsole.c28
2 files changed, 33 insertions, 4 deletions
diff --git a/src/interface.c b/src/interface.c
index 472fd9b..f62bd51 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -92,11 +92,18 @@ int drawgrav_enable = 0;
void menu_count(void)//puts the number of elements in each section into .itemcount
{
int i=0;
+ for (i=0;i<SC_TOTAL;i++)
+ {
+ msections[i].itemcount = 0;
+ }
msections[SC_LIFE].itemcount = NGOLALT;
msections[SC_WALL].itemcount = UI_WALLCOUNT-4;
for (i=0; i<PT_NUM; i++)
{
- msections[ptypes[i].menusection].itemcount+=ptypes[i].menu;
+ if (ptypes[i].menusection<SC_TOTAL)
+ {
+ msections[ptypes[i].menusection].itemcount+=ptypes[i].menu;
+ }
}
}
diff --git a/src/luaconsole.c b/src/luaconsole.c
index e7632dd..65bda4d 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -431,7 +431,7 @@ int luacon_transitionwrite(lua_State* l){
}
return 0;
}
-int luacon_element_getproperty(char * key, int * format)
+int luacon_element_getproperty(char * key, int * format, unsigned int * modified_stuff)
{
int offset;
if (strcmp(key, "name")==0){
@@ -441,10 +441,14 @@ int luacon_element_getproperty(char * key, int * format)
else if (strcmp(key, "color")==0){
offset = offsetof(part_type, pcolors);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS;
}
else if (strcmp(key, "colour")==0){
offset = offsetof(part_type, pcolors);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS;
}
else if (strcmp(key, "advection")==0){
offset = offsetof(part_type, advection);
@@ -501,6 +505,8 @@ int luacon_element_getproperty(char * key, int * format)
else if (strcmp(key, "menu")==0){
offset = offsetof(part_type, menu);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_MENUS;
}
else if (strcmp(key, "enabled")==0){
offset = offsetof(part_type, enabled);
@@ -509,10 +515,14 @@ int luacon_element_getproperty(char * key, int * format)
else if (strcmp(key, "weight")==0){
offset = offsetof(part_type, weight);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_CANMOVE;
}
else if (strcmp(key, "menusection")==0){
offset = offsetof(part_type, menusection);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_MENUS;
}
else if (strcmp(key, "heat")==0){
offset = offsetof(part_type, heat);
@@ -529,6 +539,8 @@ int luacon_element_getproperty(char * key, int * format)
else if (strcmp(key, "properties")==0){
offset = offsetof(part_type, properties);
*format = 0;
+ if (modified_stuff)
+ *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS | LUACON_EL_MODIFIED_CANMOVE;
}
else if (strcmp(key, "description")==0){
offset = offsetof(part_type, descs);
@@ -546,7 +558,7 @@ int luacon_elementread(lua_State* l){
float tempfloat;
int i;
char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_element_getproperty(key, &format);
+ offset = luacon_element_getproperty(key, &format, NULL);
free(key);
//Get Raw Index value for element
@@ -588,8 +600,9 @@ int luacon_elementwrite(lua_State* l){
int tempinteger;
float tempfloat;
int i;
+ unsigned int modified_stuff = 0;
char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_element_getproperty(key, &format);
+ offset = luacon_element_getproperty(key, &format, &modified_stuff);
//Get Raw Index value for element
lua_pushstring(l, "id");
@@ -640,6 +653,15 @@ int luacon_elementwrite(lua_State* l){
*((unsigned char*)(((void*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
break;
}
+ if (modified_stuff)
+ {
+ if (modified_stuff & LUACON_EL_MODIFIED_MENUS)
+ menu_count();
+ if (modified_stuff & LUACON_EL_MODIFIED_CANMOVE)
+ init_can_move();
+ if (modified_stuff & LUACON_EL_MODIFIED_GRAPHICS)
+ memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM);
+ }
free(key);
return 0;
}