summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-05-31 16:07:38 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-05-31 16:07:38 (GMT)
commit2327d9678d5b75f1fcf6133966de8f4d754b0476 (patch)
treed99abc011f4a4833b5fd07c21328066de9dab5aa /src
parent03a048afe548b4fcbf281b5e3cb593f006c1d087 (diff)
downloadpowder-2327d9678d5b75f1fcf6133966de8f4d754b0476.zip
powder-2327d9678d5b75f1fcf6133966de8f4d754b0476.tar.gz
implement create and delete functions
Diffstat (limited to 'src')
-rw-r--r--src/luaconsole.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 8b8c222..53f81f0 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -112,9 +112,26 @@ int luatpt_drawtext(lua_State* l)
int luatpt_create(lua_State* l)
{
- lua_pushstring(l, "not implemented");
- lua_error(l);
- //TODO: Implement luatpt_create (Create a particle)
+ int x, y, retid, t = 0;
+ char * name;
+ x = abs(luaL_optint(l, 1, 0));
+ y = abs(luaL_optint(l, 2, 0));
+ if(x < XRES && y < YRES){
+ if(lua_isnumber(l, 3)){
+ t = luaL_optint(l, 3, 0);
+ if(t >= PT_NUM)
+ return -1;
+ } else {
+ name = luaL_optstring(l, 3, "dust");
+ if (name[0]!=0)
+ console_parse_type(name, &t, console_error);
+ }
+ retid = create_part(-1, x, y, t);
+ if(retid==-1)
+ return -1;
+ lua_pushinteger(l, retid);
+ return 1;
+ }
return -1;
}
@@ -372,9 +389,18 @@ int luatpt_set_shortcuts(lua_State* l)
int luatpt_delete(lua_State* l)
{
- lua_pushstring(l, "not implemented");
- lua_error(l);
- //TODO: Implement luatpt_delete (Delete particle)
+ int arg1, arg2;
+ arg1 = abs(luaL_optint(l, 1, 0));
+ arg2 = luaL_optint(l, 2, -1);
+ if(arg2 == -1 && arg1 < NPART){
+ kill_part(arg1);
+ return 0;
+ }
+ arg2 = abs(arg2);
+ if(arg2 < YRES && arg1 < XRES){
+ delete_part(arg1, arg2);
+ return 0;
+ }
return -1;
}