]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/common/c_content.cpp
Allow setting chunksize in core.set_mapgen_params
[dragonfireclient.git] / src / script / common / c_content.cpp
index c0728177fda0ad9ba90b530b06155172d52e57f4..3754fc2ff9f8f886d8d1873b185791348da771f8 100644 (file)
@@ -200,17 +200,78 @@ void read_object_properties(lua_State *L, int index,
 }
 
 /******************************************************************************/
-TileDef read_tiledef(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, u8 drawtype)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
 
        TileDef tiledef;
-
+       bool default_tiling = (drawtype == NDT_PLANTLIKE || drawtype == NDT_FIRELIKE)
+               ? false : true;
        // key at index -2 and value at index
        if(lua_isstring(L, index)){
                // "default_lava.png"
                tiledef.name = lua_tostring(L, index);
+               tiledef.tileable_vertical = default_tiling;
+               tiledef.tileable_horizontal = default_tiling;
        }
        else if(lua_istable(L, index))
        {
@@ -219,20 +280,24 @@ TileDef read_tiledef(lua_State *L, int index)
                getstringfield(L, index, "name", tiledef.name);
                getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat.
                tiledef.backface_culling = getboolfield_default(
-                                       L, index, "backface_culling", true);
+                       L, index, "backface_culling", true);
+               tiledef.tileable_horizontal = getboolfield_default(
+                       L, index, "tileable_horizontal", default_tiling);
+               tiledef.tileable_vertical = getboolfield_default(
+                       L, index, "tileable_vertical", default_tiling);
                // animation = {}
                lua_getfield(L, index, "animation");
                if(lua_istable(L, -1)){
                        // {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}
                        tiledef.animation.type = (TileAnimationType)
-                                       getenumfield(L, -1, "type", es_TileAnimationType,
-                                       TAT_NONE);
+                               getenumfield(L, -1, "type", es_TileAnimationType,
+                               TAT_NONE);
                        tiledef.animation.aspect_w =
-                                       getintfield_default(L, -1, "aspect_w", 16);
+                               getintfield_default(L, -1, "aspect_w", 16);
                        tiledef.animation.aspect_h =
-                                       getintfield_default(L, -1, "aspect_h", 16);
+                               getintfield_default(L, -1, "aspect_h", 16);
                        tiledef.animation.length =
-                                       getfloatfield_default(L, -1, "length", 1.0);
+                               getfloatfield_default(L, -1, "length", 1.0);
                }
                lua_pop(L, 1);
        }
@@ -295,7 +360,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef[i] = read_tiledef(L, -1);
+                       f.tiledef[i] = read_tiledef(L, -1, f.drawtype);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -330,7 +395,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef_special[i] = read_tiledef(L, -1);
+                       f.tiledef_special[i] = read_tiledef(L, -1, f.drawtype);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -896,6 +961,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!                                                           */
 /******************************************************************************/
@@ -920,15 +991,24 @@ void read_groups(lua_State *L, int index,
        }
 }
 
+/******************************************************************************/
+void push_groups(lua_State *L, const std::map<std::string, int> &groups)
+{
+       lua_newtable(L);
+       std::map<std::string, int>::const_iterator it;
+       for (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
        lua_createtable(L, items.size(), 0);
-       std::vector<ItemStack>::const_iterator iter = items.begin();
-       for (u32 i = 0; iter != items.end(); iter++) {
-               LuaItemStack::create(L, *iter);
-               lua_rawseti(L, -2, ++i);
+       for (u32 i = 0; i != items.size(); i++) {
+               LuaItemStack::create(L, items[i]);
+               lua_rawseti(L, -2, i + 1);
        }
 }
 
@@ -997,6 +1077,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)