Clean up schematic saving.

All these can be written in way less characters. At least
now we're not using endless locals to do the same, and use
1 less indent.
This commit is contained in:
Auke Kok 2016-01-10 22:27:57 -08:00
parent d6ed4854c4
commit 433d9d62af
1 changed files with 3825 additions and 3962 deletions

215
init.lua
View File

@ -1,12 +1,27 @@
-- Schematic file format version 4
local mts_save = function(name, schematic)
local s = minetest.serialize_schematic(schematic, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/" .. name .. ".mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(s)
file:flush()
file:close()
end
end
local A = {name="air", prob=0}
local T = {name="default:aspen_tree", prob=255, force_place = true}
local B = {name="default:aspen_tree", prob=255}
local L = {name="default:aspen_leaves", prob=255}
local O = {name="default:aspen_leaves", prob=127}
local aspen_tree_data = {
mts_save("aspen_tree", {
size = { x = 5, y = 10, z = 5 },
data = {
A, A, A, A, A,
@ -68,20 +83,9 @@ local aspen_tree_data = {
{ypos=2, prob=191},
{ypos=7, prob=191},
},
}
})
local aspen_tree_serialized = minetest.serialize_schematic(aspen_tree_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/aspen_tree.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(aspen_tree_serialized)
file:flush()
file:close()
end
local aspen_tree_from_sapling_data = {
mts_save("aspen_tree_from_sapling", {
size = { x = 5, y = 10, z = 5 },
data = {
A, A, A, A, A,
@ -143,22 +147,10 @@ local aspen_tree_from_sapling_data = {
{ypos=2, prob=191},
{ypos=7, prob=191},
},
}
local aspen_tree_from_sapling_serialized = minetest.serialize_schematic(aspen_tree_from_sapling_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/aspen_tree_from_sapling.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(aspen_tree_from_sapling_serialized)
file:flush()
file:close()
end
})
-- Apple tree
local apple_tree_data = {
mts_save("apple_tree", {
size = {x=5, y=7, z=5},
data = {-- -2
@ -383,23 +375,10 @@ end
yslice_prob = {
{ypos=2, prob=127},
},
}
local apple_tree_serialized = minetest.serialize_schematic(apple_tree_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/apple_tree.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(apple_tree_serialized)
file:flush()
file:close()
end
})
-- Apple tree from sapling
local apple_tree_from_sapling_data = {
mts_save("apple_tree_from_sapling", {
size = {x=5, y=7, z=5},
data = {-- -2
@ -624,23 +603,10 @@ end
yslice_prob = {
{ypos=2, prob=127},
},
}
local apple_tree_from_sapling_serialized = minetest.serialize_schematic(apple_tree_from_sapling_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/apple_tree_from_sapling.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(apple_tree_from_sapling_serialized)
file:flush()
file:close()
end
})
-- Jungle tree
local jungle_tree_data = {
mts_save("jungle_tree", {
size = {x=5, y=17, z=5},
data = {
-- -2
@ -1169,23 +1135,10 @@ end
{ypos=10, prob=127},
{ypos=11, prob=127},
},
}
local jungle_tree_serialized = minetest.serialize_schematic(jungle_tree_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/jungle_tree.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(jungle_tree_serialized)
file:flush()
file:close()
end
})
-- Jungle tree from sapling
local jungle_tree_from_sapling_data = {
mts_save("jungle_tree_from_sapling", {
size = {x=5, y=17, z=5},
data = {
-- -2
@ -1714,23 +1667,10 @@ end
{ypos=10, prob=127},
{ypos=11, prob=127},
},
}
local jungle_tree_from_sapling_serialized = minetest.serialize_schematic(jungle_tree_from_sapling_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/jungle_tree_from_sapling.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(jungle_tree_from_sapling_serialized)
file:flush()
file:close()
end
})
-- Pine tree
local pine_tree_data = {
mts_save("pine_tree", {
size = {x=5, y=14, z=5},
data = {-- -2
@ -2168,23 +2108,10 @@ end
{ypos=7, prob=127},
{ypos=10, prob=127},
},
}
local pine_tree_serialized = minetest.serialize_schematic(pine_tree_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/pine_tree.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(pine_tree_serialized)
file:flush()
file:close()
end
})
-- Pine tree from sapling
local pine_tree_from_sapling_data = {
mts_save("pine_tree_from_sapling", {
size = {x=5, y=14, z=5},
data = {-- -2
@ -2622,23 +2549,10 @@ end
{ypos=7, prob=127},
{ypos=10, prob=127},
},
}
local pine_tree_from_sapling_serialized = minetest.serialize_schematic(pine_tree_from_sapling_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/pine_tree_from_sapling.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(pine_tree_from_sapling_serialized)
file:flush()
file:close()
end
})
-- Acacia tree
local acacia_tree_data = {
mts_save("acacia_tree", {
size = {x=9, y=8, z=9},
data = {-- -4
@ -3381,24 +3295,10 @@ end
yslice_prob = {
{ypos=2, prob=127},
},
}
local acacia_tree_serialized = minetest.serialize_schematic(acacia_tree_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/acacia_tree.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(acacia_tree_serialized)
file:flush()
file:close()
end
})
-- Acacia tree from sapling
local acacia_tree_from_sapling_data = {
mts_save("acacia_tree_from_sapling", {
size = {x=9, y=8, z=9},
data = {-- -4
@ -4141,24 +4041,10 @@ end
yslice_prob = {
{ypos=2, prob=127},
},
}
local acacia_tree_from_sapling_serialized = minetest.serialize_schematic(acacia_tree_from_sapling_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/acacia_tree_from_sapling.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(acacia_tree_from_sapling_serialized)
file:flush()
file:close()
end
})
-- Large cactus
local large_cactus_data = {
mts_save("large_cactus", {
size = {x=5, y=7, z=1},
data = {
{name="air", prob=0},
@ -4203,23 +4089,10 @@ local large_cactus_data = {
{name="air", prob=0},
{name="air", prob=0},
},
}
local large_cactus_serialized = minetest.serialize_schematic(large_cactus_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/large_cactus.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(large_cactus_serialized)
file:flush()
file:close()
end
})
-- Papyrus
local papyrus_data = {
mts_save("papyrus", {
size = {x = 1, y = 7, z = 1},
data = {
{name = "default:sand", prob = 255, force_place = true},
@ -4234,15 +4107,5 @@ local papyrus_data = {
{ypos = 2, prob = 127},
{ypos = 3, prob = 127},
},
}
})
local papyrus_serialized = minetest.serialize_schematic(papyrus_data, mts, {})
local path = minetest.get_modpath("saveschems") .. "/schematics"
local filename = path .. "/papyrus.mts"
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
local file, err = io.open(filename, "wb")
if err == nil then
file:write(papyrus_serialized)
file:flush()
file:close()
end