summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPilzAdam <pilzadam@minetest.net>2013-08-03 01:58:29 +0200
committerPilzAdam <pilzadam@minetest.net>2013-08-03 03:22:14 +0200
commit45589fae58157c8a66c640a1db5795a42a86fc1c (patch)
treeaafb4d39b821e2bff4d590a25b982cd4228b9657 /src
parent5e433fa913cc21d4d3c9ba1ef341c3c7aedc128c (diff)
downloadminetest-45589fae58157c8a66c640a1db5795a42a86fc1c.tar.gz
minetest-45589fae58157c8a66c640a1db5795a42a86fc1c.tar.bz2
minetest-45589fae58157c8a66c640a1db5795a42a86fc1c.zip
Add replacements to schematics
Diffstat (limited to 'src')
-rw-r--r--src/mapgen.cpp7
-rw-r--r--src/mapgen.h1
-rw-r--r--src/script/lua_api/luaapi.cpp40
3 files changed, 45 insertions, 3 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index f446d05b7..397e52f74 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -506,7 +506,12 @@ void DecoSchematic::resolveNodeNames(INodeDefManager *ndef) {
}
for (size_t i = 0; i != node_names->size(); i++) {
- content_t c = ndef->getId(node_names->at(i));
+ std::string name = node_names->at(i);
+ std::map<std::string, std::string>::iterator it;
+ it = replacements.find(name);
+ if (it != replacements.end())
+ name = it->second;
+ content_t c = ndef->getId(name);
if (c == CONTENT_IGNORE) {
errorstream << "DecoSchematic::resolveNodeNames: node '"
<< node_names->at(i) << "' not defined" << std::endl;
diff --git a/src/mapgen.h b/src/mapgen.h
index 8aff33288..7b8ff57ca 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -269,6 +269,7 @@ public:
std::vector<std::string> *node_names;
std::vector<content_t> c_nodes;
+ std::map<std::string, std::string> replacements;
u32 flags;
Rotation rotation;
diff --git a/src/script/lua_api/luaapi.cpp b/src/script/lua_api/luaapi.cpp
index 0d4c7da7b..929aa40d0 100644
--- a/src/script/lua_api/luaapi.cpp
+++ b/src/script/lua_api/luaapi.cpp
@@ -808,7 +808,26 @@ int ModApiBasic::l_register_decoration(lua_State *L)
dschem->flags = getflagsfield(L, index, "flags", flagdesc_deco_schematic);
dschem->rotation = (Rotation)getenumfield(L, index,
"rotation", es_Rotation, ROTATE_0);
-
+
+ lua_getfield(L, index, "replacements");
+ if (lua_istable(L, -1)) {
+ int i = lua_gettop(L);
+ lua_pushnil(L);
+ while (lua_next(L, i) != 0) {
+ // key at index -2 and value at index -1
+ lua_rawgeti(L, -1, 1);
+ std::string replace_from = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ lua_rawgeti(L, -1, 2);
+ std::string replace_to = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ dschem->replacements[replace_from] = replace_to;
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+
lua_getfield(L, index, "schematic");
if (!read_schematic(L, -1, dschem, getServer(L))) {
delete dschem;
@@ -888,7 +907,7 @@ int ModApiBasic::l_create_schematic(lua_State *L)
}
-// place_schematic(p, schematic, rotation)
+// place_schematic(p, schematic, rotation, replacement)
int ModApiBasic::l_place_schematic(lua_State *L)
{
DecoSchematic dschem;
@@ -906,6 +925,23 @@ int ModApiBasic::l_place_schematic(lua_State *L)
dschem.rotation = rot;
+ if (lua_istable(L, 4)) {
+ int index = 4;
+ lua_pushnil(L);
+ while (lua_next(L, index) != 0) {
+ // key at index -2 and value at index -1
+ lua_rawgeti(L, -1, 1);
+ std::string replace_from = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ lua_rawgeti(L, -1, 2);
+ std::string replace_to = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ dschem.replacements[replace_from] = replace_to;
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ }
+
if (!dschem.filename.empty()) {
if (!dschem.loadSchematicFile()) {
errorstream << "place_schematic: failed to load schematic file '"