diff options
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_content.cpp | 99 | ||||
-rw-r--r-- | src/script/common/c_content.h | 5 | ||||
-rw-r--r-- | src/script/common/c_converter.cpp | 35 | ||||
-rw-r--r-- | src/script/common/c_converter.h | 5 |
4 files changed, 144 insertions, 0 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index c0728177f..94fcdecbb 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -200,6 +200,64 @@ void read_object_properties(lua_State *L, int index, } /******************************************************************************/ +void push_object_properties(lua_State *L, ObjectProperties *prop) +{ + lua_newtable(L); + lua_pushnumber(L, prop->hp_max); + lua_setfield(L, -2, "hp_max"); + lua_pushboolean(L, prop->physical); + lua_setfield(L, -2, "physical"); + lua_pushboolean(L, prop->collideWithObjects); + lua_setfield(L, -2, "collide_with_objects"); + lua_pushnumber(L, prop->weight); + lua_setfield(L, -2, "weight"); + push_aabb3f(L, prop->collisionbox); + lua_setfield(L, -2, "collisionbox"); + lua_pushlstring(L, prop->visual.c_str(), prop->visual.size()); + lua_setfield(L, -2, "visual"); + lua_pushlstring(L, prop->mesh.c_str(), prop->mesh.size()); + lua_setfield(L, -2, "mesh"); + push_v2f(L, prop->visual_size); + lua_setfield(L, -2, "visual_size"); + + lua_newtable(L); + u16 i = 1; + for (std::vector<std::string>::iterator it = prop->textures.begin(); + it != prop->textures.end(); ++it) { + lua_pushlstring(L, it->c_str(), it->size()); + lua_rawseti(L, -2, i); + } + lua_setfield(L, -2, "textures"); + + lua_newtable(L); + i = 1; + for (std::vector<video::SColor>::iterator it = prop->colors.begin(); + it != prop->colors.end(); ++it) { + push_ARGB8(L, *it); + lua_rawseti(L, -2, i); + } + lua_setfield(L, -2, "colors"); + + push_v2s16(L, prop->spritediv); + lua_setfield(L, -2, "spritediv"); + push_v2s16(L, prop->initial_sprite_basepos); + lua_setfield(L, -2, "initial_sprite_basepos"); + lua_pushboolean(L, prop->is_visible); + lua_setfield(L, -2, "is_visible"); + lua_pushboolean(L, prop->makes_footstep_sound); + lua_setfield(L, -2, "makes_footstep_sound"); + lua_pushnumber(L, prop->automatic_rotate); + lua_setfield(L, -2, "automatic_rotate"); + lua_pushnumber(L, prop->stepheight / BS); + lua_setfield(L, -2, "stepheight"); + if (prop->automatic_face_movement_dir) + lua_pushnumber(L, prop->automatic_face_movement_dir_offset); + else + lua_pushboolean(L, false); + lua_setfield(L, -2, "automatic_face_movement_dir"); +} + +/******************************************************************************/ TileDef read_tiledef(lua_State *L, int index) { if(index < 0) @@ -896,6 +954,12 @@ u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask) return flags; } +void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask) +{ + std::string flagstring = writeFlagString(flags, flagdesc, flagmask); + lua_pushlstring(L, flagstring.c_str(), flagstring.size()); +} + /******************************************************************************/ /* Lua Stored data! */ /******************************************************************************/ @@ -921,6 +985,17 @@ void read_groups(lua_State *L, int index, } /******************************************************************************/ +void push_groups(lua_State *L, std::map<std::string, int> groups) +{ + lua_newtable(L); + for (std::map<std::string, int>::iterator it = groups.begin(); + it != groups.end(); ++it) { + lua_pushnumber(L, it->second); + lua_setfield(L, -2, it->first.c_str()); + } +} + +/******************************************************************************/ void push_items(lua_State *L, const std::vector<ItemStack> &items) { // Create and fill table @@ -997,6 +1072,30 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np) return true; } +void push_noiseparams(lua_State *L, NoiseParams *np) +{ + lua_newtable(L); + lua_pushnumber(L, np->offset); + lua_setfield(L, -2, "offset"); + lua_pushnumber(L, np->scale); + lua_setfield(L, -2, "scale"); + lua_pushnumber(L, np->persist); + lua_setfield(L, -2, "persistence"); + lua_pushnumber(L, np->lacunarity); + lua_setfield(L, -2, "lacunarity"); + lua_pushnumber(L, np->seed); + lua_setfield(L, -2, "seed"); + lua_pushnumber(L, np->octaves); + lua_setfield(L, -2, "octaves"); + + push_flags_string(L, flagdesc_noiseparams, np->flags, + np->flags); + lua_setfield(L, -2, "flags"); + + push_v3f(L, np->spread); + lua_setfield(L, -2, "spread"); +} + /******************************************************************************/ // Returns depth of json value tree static int push_json_value_getdepth(const Json::Value &value) diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 241b1ca76..69b2a8355 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -88,6 +88,8 @@ ItemDefinition read_item_definition (lua_State *L, void read_object_properties (lua_State *L, int index, ObjectProperties *prop); +void push_object_properties (lua_State *L, + ObjectProperties *prop); void push_inventory_list (lua_State *L, Inventory *inv, @@ -127,6 +129,8 @@ bool getflagsfield (lua_State *L, int table, bool read_flags (lua_State *L, int index, FlagDesc *flagdesc, u32 *flags, u32 *flagmask); +void push_flags_string (lua_State *L, FlagDesc *flagdesc, + u32 flags, u32 flagmask); u32 read_flags_table (lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask); @@ -149,6 +153,7 @@ bool string_to_enum (const EnumString *spec, bool read_noiseparams (lua_State *L, int index, NoiseParams *np); +void push_noiseparams (lua_State *L, NoiseParams *np); void luaentity_get (lua_State *L,u16 id); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 211121552..f1d3cc421 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -88,6 +88,24 @@ v2s16 check_v2s16(lua_State *L, int index) return p; } +void push_v2s16(lua_State *L, v2s16 p) +{ + lua_newtable(L); + lua_pushnumber(L, p.X); + lua_setfield(L, -2, "x"); + lua_pushnumber(L, p.Y); + lua_setfield(L, -2, "y"); +} + +void push_v2s32(lua_State *L, v2s32 p) +{ + lua_newtable(L); + lua_pushnumber(L, p.X); + lua_setfield(L, -2, "x"); + lua_pushnumber(L, p.Y); + lua_setfield(L, -2, "y"); +} + v2s32 read_v2s32(lua_State *L, int index) { v2s32 p; @@ -277,6 +295,23 @@ aabb3f read_aabb3f(lua_State *L, int index, f32 scale) return box; } +void push_aabb3f(lua_State *L, aabb3f box) +{ + lua_newtable(L); + lua_pushnumber(L, box.MinEdge.X); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, box.MinEdge.Y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, box.MinEdge.Z); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, box.MaxEdge.X); + lua_rawseti(L, -2, 4); + lua_pushnumber(L, box.MaxEdge.Y); + lua_rawseti(L, -2, 5); + lua_pushnumber(L, box.MaxEdge.Z); + lua_rawseti(L, -2, 6); +} + std::vector<aabb3f> read_aabb3f_vector(lua_State *L, int index, f32 scale) { std::vector<aabb3f> boxes; diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index e4466d97f..8a49c7a73 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -96,11 +96,16 @@ std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale); size_t read_stringlist (lua_State *L, int index, std::vector<std::string> *result); +void push_v2s16 (lua_State *L, v2s16 p); +void push_v2s32 (lua_State *L, v2s32 p); void push_v3s16 (lua_State *L, v3s16 p); +void push_aabb3f (lua_State *L, aabb3f box); void push_ARGB8 (lua_State *L, video::SColor color); void pushFloatPos (lua_State *L, v3f p); void push_v3f (lua_State *L, v3f p); void push_v2f (lua_State *L, v2f p); +void push_groups (lua_State *L, + std::map<std::string, int> groups); void warn_if_field_exists(lua_State *L, int table, const char *fieldname, |