Table cleanup part 1 - Replace global tables with file inputs
This commit is contained in:
parent
2461c66f99
commit
06b509ed94
14
formspec.lua
14
formspec.lua
@ -1,7 +1,12 @@
|
|||||||
local gui = {};
|
local gui = {};
|
||||||
|
|
||||||
function gui.bg9(args)
|
function gui.bg9(args)
|
||||||
return string.format("background9[%f,%f;%f,%f;%s;%s;%s]", args.x, args.y, args.w, args.h, args.skin.texture .. ".png", args.fullsize or false, tostring(args.skin.radius));
|
return string.format("background9[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
|
args.x, args.y,
|
||||||
|
args.w, args.h,
|
||||||
|
args.skin.texture .. ".png",
|
||||||
|
args.fullsize or false,
|
||||||
|
tostring(args.skin.radius));
|
||||||
end
|
end
|
||||||
|
|
||||||
function gui.button(args)
|
function gui.button(args)
|
||||||
@ -18,7 +23,12 @@ function gui.button(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gui.image_button(args)
|
function gui.image_button(args)
|
||||||
local data = string.format("image_button[%f,%f;%f,%f;%s;%s;%s]", args.x, args.y, args.w, args.h, args.image, args.id, args.text or "");
|
local data = string.format("image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
|
args.x, args.y,
|
||||||
|
args.w, args.h,
|
||||||
|
args.image,
|
||||||
|
args.id,
|
||||||
|
args.text or "");
|
||||||
|
|
||||||
if args.tooltip then
|
if args.tooltip then
|
||||||
data = data .. gui.tooltip {
|
data = data .. gui.tooltip {
|
||||||
|
2
init.lua
2
init.lua
@ -58,4 +58,4 @@ loadfile(modpath .. "/items.lua") ();
|
|||||||
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (_cartographer.marker_lookup, cartographer.gui);
|
_cartographer.generate_marker_formspec = loadfile(modpath .. "/marker_formspec.lua") (_cartographer.marker_lookup, cartographer.gui);
|
||||||
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
||||||
loadfile(modpath .. "/commands.lua") ();
|
loadfile(modpath .. "/commands.lua") ();
|
||||||
loadfile(modpath .. "/table.lua") ();
|
loadfile(modpath .. "/table.lua") (_cartographer.materials_by_name, _cartographer.materials_by_group, cartographer.skin);
|
||||||
|
36
table.lua
36
table.lua
@ -1,3 +1,5 @@
|
|||||||
|
local materials_by_name, materials_by_group, gui_skin = ...;
|
||||||
|
|
||||||
local MAP_SIZE = 40;
|
local MAP_SIZE = 40;
|
||||||
local SCALE_SMALL = 1;
|
local SCALE_SMALL = 1;
|
||||||
local SCALE_MEDIUM = 2;
|
local SCALE_MEDIUM = 2;
|
||||||
@ -114,7 +116,7 @@ function cartographer.get_material_value(stack)
|
|||||||
local item_name = stack:get_name();
|
local item_name = stack:get_name();
|
||||||
local item_count = stack:get_count();
|
local item_count = stack:get_count();
|
||||||
|
|
||||||
for name,mats in pairs(_cartographer.materials_by_name) do
|
for name,mats in pairs(materials_by_name) do
|
||||||
if name == item_name then
|
if name == item_name then
|
||||||
return {
|
return {
|
||||||
paper = (mats.paper or 0) * item_count,
|
paper = (mats.paper or 0) * item_count,
|
||||||
@ -123,7 +125,7 @@ function cartographer.get_material_value(stack)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for group,mats in pairs(_cartographer.materials_by_group) do
|
for group,mats in pairs(materials_by_group) do
|
||||||
if minetest.get_item_group(item_name, group) ~= 0 then
|
if minetest.get_item_group(item_name, group) ~= 0 then
|
||||||
return {
|
return {
|
||||||
paper = (mats.paper or 0) * item_count,
|
paper = (mats.paper or 0) * item_count,
|
||||||
@ -358,14 +360,14 @@ local function table_formspec(player)
|
|||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
|
|
||||||
local rank = 1;
|
local rank = 1;
|
||||||
local skin = cartographer.skin.table_skins.simple_table;
|
local skin = gui_skin.table_skins.simple_table;
|
||||||
local name = minetest.get_node(pos).name;
|
local name = minetest.get_node(pos).name;
|
||||||
if name == "cartographer:standard_table" then
|
if name == "cartographer:standard_table" then
|
||||||
rank = 2;
|
rank = 2;
|
||||||
skin = cartographer.skin.table_skins.standard_table;
|
skin = gui_skin.table_skins.standard_table;
|
||||||
elseif name == "cartographer:advanced_table" then
|
elseif name == "cartographer:advanced_table" then
|
||||||
rank = 3;
|
rank = 3;
|
||||||
skin = cartographer.skin.table_skins.advanced_table;
|
skin = gui_skin.table_skins.advanced_table;
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.tab == 1 then
|
if data.tab == 1 then
|
||||||
@ -556,8 +558,8 @@ end
|
|||||||
minetest.register_node("cartographer:simple_table", {
|
minetest.register_node("cartographer:simple_table", {
|
||||||
description = "Shabby Cartographer's Table",
|
description = "Shabby Cartographer's Table",
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = cartographer.skin.table_skins.simple_table.node_mesh,
|
mesh = gui_skin.table_skins.simple_table.node_mesh,
|
||||||
tiles = { cartographer.skin.table_skins.simple_table.node_texture },
|
tiles = { gui_skin.table_skins.simple_table.node_texture },
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {
|
groups = {
|
||||||
choppy = 2,
|
choppy = 2,
|
||||||
@ -596,8 +598,8 @@ minetest.register_node("cartographer:simple_table", {
|
|||||||
minetest.register_node("cartographer:standard_table", {
|
minetest.register_node("cartographer:standard_table", {
|
||||||
description = "Simple Cartographer's Table",
|
description = "Simple Cartographer's Table",
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = cartographer.skin.table_skins.standard_table.node_mesh,
|
mesh = gui_skin.table_skins.standard_table.node_mesh,
|
||||||
tiles = { cartographer.skin.table_skins.standard_table.node_texture },
|
tiles = { gui_skin.table_skins.standard_table.node_texture },
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {
|
groups = {
|
||||||
choppy = 2,
|
choppy = 2,
|
||||||
@ -636,8 +638,8 @@ minetest.register_node("cartographer:standard_table", {
|
|||||||
minetest.register_node("cartographer:advanced_table", {
|
minetest.register_node("cartographer:advanced_table", {
|
||||||
description = "Advanced Cartographer's Table",
|
description = "Advanced Cartographer's Table",
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = cartographer.skin.table_skins.advanced_table.node_mesh,
|
mesh = gui_skin.table_skins.advanced_table.node_mesh,
|
||||||
tiles = { cartographer.skin.table_skins.advanced_table.node_texture },
|
tiles = { gui_skin.table_skins.advanced_table.node_texture },
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {
|
groups = {
|
||||||
choppy = 2,
|
choppy = 2,
|
||||||
@ -674,20 +676,20 @@ minetest.register_node("cartographer:advanced_table", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function cartographer.register_map_material_name(name, material, value)
|
function cartographer.register_map_material_name(name, material, value)
|
||||||
if _cartographer.materials_by_name[name] then
|
if materials_by_name[name] then
|
||||||
_cartographer.materials_by_name[name][material] = value or 1;
|
materials_by_name[name][material] = value or 1;
|
||||||
else
|
else
|
||||||
_cartographer.materials_by_name[name] = {
|
materials_by_name[name] = {
|
||||||
[material] = value or 1,
|
[material] = value or 1,
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function cartographer.register_map_material_group(name, material, value)
|
function cartographer.register_map_material_group(name, material, value)
|
||||||
if _cartographer.materials_by_group[name] then
|
if materials_by_group[name] then
|
||||||
_cartographer.materials_by_group[name][material] = value or 1;
|
materials_by_group[name][material] = value or 1;
|
||||||
else
|
else
|
||||||
_cartographer.materials_by_group[name] = {
|
materials_by_group[name] = {
|
||||||
[material] = value or 1,
|
[material] = value or 1,
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user