Skip to content

Commit

Permalink
Add documention and fix some minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
red-001 committed Apr 1, 2017
1 parent 574bccc commit eff6596
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
41 changes: 41 additions & 0 deletions doc/client_lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@ Call these functions only at load time!
### Particles
* `minetest.add_particle(particle definition)`

* `minetest.add_particlespawner(particlespawner definition)`
* Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds
* Returns an `id`, and -1 if adding didn't succeed

* `minetest.delete_particlespawner(id)`
* Delete `ParticleSpawner` with `id` (return value from `minetest.add_particlespawner`)

### Misc.
* `minetest.parse_json(string[, nullvalue])`: returns something
* Convert a string containing JSON data into the Lua equivalent
Expand Down Expand Up @@ -872,3 +879,37 @@ value must (always) be two hexadecimal digits.
-- ^ optional, specify particle self-luminescence in darkness
}

### `ParticleSpawner` definition (`add_particlespawner`)
**NOTE: `attached` is not implemented yet.**

{
amount = 1,
time = 1,
-- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
minpos = {x=0, y=0, z=0},
maxpos = {x=0, y=0, z=0},
minvel = {x=0, y=0, z=0},
maxvel = {x=0, y=0, z=0},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 1,
minsize = 1,
maxsize = 1,
-- ^ The particle's properties are random values in between the bounds:
-- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
-- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
collisiondetection = false,
-- ^ collisiondetection: if true uses collision detection
collision_removal = false,
-- ^ collision_removal: if true then particle is removed when it collides,
-- ^ requires collisiondetection = true to have any effect
attached = ObjectRef,
-- ^ attached: if defined, particle positions, velocities and accelerations
-- ^ are relative to this object's position and yaw.
vertical = false,
-- ^ vertical: if true faces player using y axis only
texture = "image.png",
-- ^ Uses texture (string)
}

8 changes: 5 additions & 3 deletions src/script/lua_api/l_particles_local.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2017 red-001 <red-001@outlook.ie>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -99,7 +100,7 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L)
event.spawn_particle.glow = glow;
getClient(L)->pushToEventQueue(event);

return 1;
return 0;
}

// add_particlespawner({amount=, time=,
Expand Down Expand Up @@ -133,7 +134,7 @@ int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
collisiondetection = vertical = collision_removal = false;
struct TileAnimationParams animation;
animation.type = TAT_NONE;
ServerActiveObject *attached = NULL;
ServerActiveObject *attached = NULL; // TODO: Implement this when there is a way to get an objectref
std::string texture = "";
u8 glow = 0;

Expand Down Expand Up @@ -178,6 +179,7 @@ int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
animation = read_animation_definition(L, -1);
lua_pop(L, 1);

// TODO: Implement this when a way to get an objectref on the client is added
lua_getfield(L, 1, "attached");
if (!lua_isnil(L, -1)) {
ObjectRef *ref = ObjectRef::checkobject(L, -1);
Expand Down Expand Up @@ -231,7 +233,7 @@ int ModApiParticlesLocal::l_delete_particlespawner(lua_State *L)
event.delete_particlespawner.id = id;

getClient(L)->pushToEventQueue(event);
return 1;
return 0;
}

void ModApiParticlesLocal::Initialize(lua_State *L, int top)
Expand Down
1 change: 1 addition & 0 deletions src/script/lua_api/l_particles_local.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2017 red-001 <red-001@outlook.ie>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down

0 comments on commit eff6596

Please sign in to comment.