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 = {};
|
||||
|
||||
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
|
||||
|
||||
function gui.button(args)
|
||||
@ -18,7 +23,12 @@ function gui.button(args)
|
||||
end
|
||||
|
||||
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
|
||||
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);
|
||||
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
||||
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 SCALE_SMALL = 1;
|
||||
local SCALE_MEDIUM = 2;
|
||||
@ -114,7 +116,7 @@ function cartographer.get_material_value(stack)
|
||||
local item_name = stack:get_name();
|
||||
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
|
||||
return {
|
||||
paper = (mats.paper or 0) * item_count,
|
||||
@ -123,7 +125,7 @@ function cartographer.get_material_value(stack)
|
||||
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
|
||||
return {
|
||||
paper = (mats.paper or 0) * item_count,
|
||||
@ -358,14 +360,14 @@ local function table_formspec(player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
|
||||
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;
|
||||
if name == "cartographer:standard_table" then
|
||||
rank = 2;
|
||||
skin = cartographer.skin.table_skins.standard_table;
|
||||
skin = gui_skin.table_skins.standard_table;
|
||||
elseif name == "cartographer:advanced_table" then
|
||||
rank = 3;
|
||||
skin = cartographer.skin.table_skins.advanced_table;
|
||||
skin = gui_skin.table_skins.advanced_table;
|
||||
end
|
||||
|
||||
if data.tab == 1 then
|
||||
@ -556,8 +558,8 @@ end
|
||||
minetest.register_node("cartographer:simple_table", {
|
||||
description = "Shabby Cartographer's Table",
|
||||
drawtype = "mesh",
|
||||
mesh = cartographer.skin.table_skins.simple_table.node_mesh,
|
||||
tiles = { cartographer.skin.table_skins.simple_table.node_texture },
|
||||
mesh = gui_skin.table_skins.simple_table.node_mesh,
|
||||
tiles = { gui_skin.table_skins.simple_table.node_texture },
|
||||
paramtype2 = "facedir",
|
||||
groups = {
|
||||
choppy = 2,
|
||||
@ -596,8 +598,8 @@ minetest.register_node("cartographer:simple_table", {
|
||||
minetest.register_node("cartographer:standard_table", {
|
||||
description = "Simple Cartographer's Table",
|
||||
drawtype = "mesh",
|
||||
mesh = cartographer.skin.table_skins.standard_table.node_mesh,
|
||||
tiles = { cartographer.skin.table_skins.standard_table.node_texture },
|
||||
mesh = gui_skin.table_skins.standard_table.node_mesh,
|
||||
tiles = { gui_skin.table_skins.standard_table.node_texture },
|
||||
paramtype2 = "facedir",
|
||||
groups = {
|
||||
choppy = 2,
|
||||
@ -636,8 +638,8 @@ minetest.register_node("cartographer:standard_table", {
|
||||
minetest.register_node("cartographer:advanced_table", {
|
||||
description = "Advanced Cartographer's Table",
|
||||
drawtype = "mesh",
|
||||
mesh = cartographer.skin.table_skins.advanced_table.node_mesh,
|
||||
tiles = { cartographer.skin.table_skins.advanced_table.node_texture },
|
||||
mesh = gui_skin.table_skins.advanced_table.node_mesh,
|
||||
tiles = { gui_skin.table_skins.advanced_table.node_texture },
|
||||
paramtype2 = "facedir",
|
||||
groups = {
|
||||
choppy = 2,
|
||||
@ -674,20 +676,20 @@ minetest.register_node("cartographer:advanced_table", {
|
||||
});
|
||||
|
||||
function cartographer.register_map_material_name(name, material, value)
|
||||
if _cartographer.materials_by_name[name] then
|
||||
_cartographer.materials_by_name[name][material] = value or 1;
|
||||
if materials_by_name[name] then
|
||||
materials_by_name[name][material] = value or 1;
|
||||
else
|
||||
_cartographer.materials_by_name[name] = {
|
||||
materials_by_name[name] = {
|
||||
[material] = value or 1,
|
||||
};
|
||||
end
|
||||
end
|
||||
|
||||
function cartographer.register_map_material_group(name, material, value)
|
||||
if _cartographer.materials_by_group[name] then
|
||||
_cartographer.materials_by_group[name][material] = value or 1;
|
||||
if materials_by_group[name] then
|
||||
materials_by_group[name][material] = value or 1;
|
||||
else
|
||||
_cartographer.materials_by_group[name] = {
|
||||
materials_by_group[name] = {
|
||||
[material] = value or 1,
|
||||
};
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user