Remove table constants, we don't actually need them

This commit is contained in:
Hugues Ross 2021-11-24 06:51:28 -05:00
parent f3ea77a373
commit f07d729d1a

184
table.lua
View File

@ -13,29 +13,6 @@ local SCALE_MEDIUM = 2
local SCALE_LARGE = 4
local SCALE_HUGE = 8
-- Constants providing previously-hardcoded values as defaults
local BUTTON_WIDTH = 1
local BUTTON_HEIGHT = 0.25
local OUTER_MARGIN_X = 0.125
local OUTER_MARGIN_Y = 0.125
local INDICATOR_WIDTH = 1
local INDICATOR_HEIGHT = 0.25
local INDICATOR_SPACING = 0.25
local INNER_MARGIN_X = 0.125
local INNER_MARGIN_Y = 0.125
local SLOT_WIDTH = 1
local SLOT_HEIGHT = 1
local SLOT_COLUMN_MARGIN = 0.25
local SLOT_ROW_MARGIN = 0.25
local LABEL_MARGIN_X = 0.125
local LABEL_MARGIN_Y = 0
local RADIO_WIDTH = 0.5
local RADIO_HEIGHT = 0.5
local RADIO_MARGIN_X = 0.25
local RADIO_MARGIN_Y = 0.25
local TAB_WIDTH = 1.5
local TAB_HEIGHT = 0.55
-- Get the material cost for the given map scale and detail level
--
-- scale: The map scale
@ -153,8 +130,8 @@ end
--
-- Returns a formspec string
function fs.header(w, h, rank, tab, skin)
local tabs_x = (skin.background.margin_x or OUTER_MARGIN_X) + (skin.inner_background.margin_x or INNER_MARGIN_X)
local tabs_y = (skin.background.margin_y or OUTER_MARGIN_Y) - (skin.tab.height or TAB_HEIGHT)
local tabs_x = skin.background.margin_x + skin.inner_background.margin_x
local tabs_y = skin.background.margin_y - skin.tab.height
local data = {
gui.formspec {
@ -164,11 +141,11 @@ function fs.header(w, h, rank, tab, skin)
bg = skin.background,
},
gui.bg9 {
x = skin.background.margin_x or OUTER_MARGIN_X,
y = skin.background.margin_y or OUTER_MARGIN_Y,
x = skin.background.margin_x,
y = skin.background.margin_y,
w = w - (skin.background.margin_x or OUTER_MARGIN_X) * 2,
h = h - (skin.background.margin_y or OUTER_MARGIN_Y) * 2,
w = w - skin.background.margin_x * 2,
h = h - skin.background.margin_y * 2,
skin = skin.inner_background,
},
@ -200,19 +177,19 @@ function fs.header(w, h, rank, tab, skin)
x = tabs_x,
y = tabs_y,
w = skin.tab.width or TAB_WIDTH,
h = skin.tab.height or TAB_HEIGHT,
w = skin.tab.width,
h = skin.tab.height,
id = "tab1",
text = "Materials"
},
gui.button {
x = tabs_x + (skin.tab.width or TAB_WIDTH),
x = tabs_x + skin.tab.width,
y = tabs_y,
w = skin.tab.width or TAB_WIDTH,
h = skin.tab.height or TAB_HEIGHT,
w = skin.tab.width,
h = skin.tab.height,
id = "tab2",
@ -222,11 +199,11 @@ function fs.header(w, h, rank, tab, skin)
if rank >= 2 then
table.insert(data, gui.button {
x = tabs_x + (skin.tab.width or TAB_WIDTH) * 2,
x = tabs_x + skin.tab.width * 2,
y = tabs_y,
w = skin.tab.width or TAB_WIDTH,
h = skin.tab.height or TAB_HEIGHT,
w = skin.tab.width,
h = skin.tab.height,
id = "tab3",
@ -269,16 +246,11 @@ end
--
-- Returns a formspec string
function fs.materials(x, y, meta, skin)
local indicator_w = INDICATOR_WIDTH
local indicator_h = INDICATOR_HEIGHT
local indicator_spacing = INDICATOR_SPACING
if skin.material_indicator then
indicator_w = skin.material_indicator.width
indicator_h = skin.material_indicator.height
indicator_spacing = skin.material_indicator.spacing
end
local margin_x = skin.label.margin_x or LABEL_MARGIN_X
local margin_y = skin.label.margin_y or LABEL_MARGIN_Y
local indicator_w = skin.material_indicator.width
local indicator_h = skin.material_indicator.height
local indicator_spacing = skin.material_indicator.spacing
local margin_x = skin.label.margin_x
local margin_y = skin.label.margin_y
local inner_h = indicator_h - (margin_y * 2)
return gui.container {
@ -340,14 +312,10 @@ end
--
-- Returns a formspec string
function fs.cost(x, y, cost, skin)
local indicator_w = INDICATOR_WIDTH
local indicator_h = INDICATOR_HEIGHT
if skin.material_indicator then
indicator_w = skin.material_indicator.width
indicator_h = skin.material_indicator.height
end
local margin_x = skin.label.margin_x or LABEL_MARGIN_X
local margin_y = skin.label.margin_y or LABEL_MARGIN_Y
local indicator_w = skin.material_indicator.width
local indicator_h = skin.material_indicator.height
local margin_x = skin.label.margin_x
local margin_y = skin.label.margin_y
local inner_h = indicator_h - (margin_y * 2)
local data = {
gui.bg9 {
@ -404,19 +372,13 @@ function fs.convert(x, y, pos, skin)
local meta = minetest.get_meta(pos)
local value = materials.get_stack_value(meta:get_inventory():get_stack("input", 1))
local button_w = skin.button.width or BUTTON_WIDTH
local button_h = skin.button.height or BUTTON_HEIGHT
local indicator_w = INDICATOR_WIDTH
local indicator_h = INDICATOR_HEIGHT * 2
local inv_w = skin.slot.width or SLOT_WIDTH
local inv_h = skin.slot.height or SLOT_HEIGHT
local indicator_spacing = INDICATOR_SPACING
if skin.material_indicator then
indicator_w = skin.material_indicator.width
indicator_h = skin.material_indicator.height * 2
indicator_spacing = skin.material_indicator.spacing
end
local button_w = skin.button.width
local button_h = skin.button.height
local inv_w = skin.slot.width
local inv_h = skin.slot.height
local indicator_w = skin.material_indicator.width
local indicator_h = skin.material_indicator.height * 2
local indicator_spacing = skin.material_indicator.spacing
return gui.container {
x = x,
@ -464,26 +426,14 @@ function fs.craft(x, y, pos, rank, meta, skin)
local cost, is_positive = get_craft_material_cost(meta)
local stack = meta:get_inventory():get_stack("output", 1)
local button_w = skin.button.width or BUTTON_WIDTH
local button_h = skin.button.height or BUTTON_HEIGHT
local indicator_w = INDICATOR_WIDTH
local indicator_h = INDICATOR_HEIGHT * 2
local inv_w = skin.slot.width or SLOT_WIDTH
local inv_h = skin.slot.height or SLOT_HEIGHT
local radio = skin.radio or {
width = RADIO_WIDTH,
height = RADIO_HEIGHT,
margin_x = RADIO_MARGIN_X,
margin_y = RADIO_MARGIN_Y,
}
local indicator_spacing = INDICATOR_SPACING
if skin.material_indicator then
indicator_w = skin.material_indicator.width
indicator_h = skin.material_indicator.height * 2
indicator_spacing = skin.material_indicator.spacing
end
local button_w = skin.button.width
local button_h = skin.button.height
local inv_w = skin.slot.width
local inv_h = skin.slot.height
local indicator_w = skin.material_indicator.width
local indicator_h = skin.material_indicator.height * 2
local indicator_spacing = skin.material_indicator.spacing
local radio = skin.radio
local data = {
x = x,
@ -635,19 +585,13 @@ function fs.copy(x, y, width, pos, skin)
local meta = minetest.get_meta(pos)
local costs = get_copy_material_cost(meta)
local button_w = skin.button.width or BUTTON_WIDTH
local button_h = skin.button.height or BUTTON_HEIGHT
local indicator_w = INDICATOR_WIDTH
local indicator_h = INDICATOR_HEIGHT * 2
local inv_w = skin.slot.width or SLOT_WIDTH
local inv_h = skin.slot.height or SLOT_HEIGHT
local indicator_spacing = INDICATOR_SPACING
if skin.material_indicator then
indicator_w = skin.material_indicator.width
indicator_h = skin.material_indicator.height * 2
indicator_spacing = skin.material_indicator.spacing
end
local button_w = skin.button.width
local button_h = skin.button.height
local inv_w = skin.slot.width
local inv_h = skin.slot.height
local indicator_w = skin.material_indicator.width
local indicator_h = skin.material_indicator.height * 2
local indicator_spacing = skin.material_indicator.spacing
return gui.container {
x = x,
@ -735,27 +679,23 @@ local function table_formspec(player)
skin = gui_skin.table_skins.advanced_table
end
local outer_x = (skin.background.margin_x or OUTER_MARGIN_X)
local outer_y = (skin.background.margin_y or OUTER_MARGIN_Y)
local inner_x = (skin.inner_background.margin_x or INNER_MARGIN_X)
local inner_y = (skin.inner_background.margin_y or INNER_MARGIN_Y)
local outer_x = skin.background.margin_x
local outer_y = skin.background.margin_y
local inner_x = skin.inner_background.margin_x
local inner_y = skin.inner_background.margin_y
local inv_width = (skin.slot_w or SLOT_WIDTH) * gui_skin.player_inv_columns
+ (SLOT_COLUMN_MARGIN * (gui_skin.player_inv_columns - 1))
local inv_height = (skin.slot_h or SLOT_HEIGHT) * gui_skin.player_inv_rows
+ (SLOT_ROW_MARGIN * (gui_skin.player_inv_rows - 1))
local inv_width = skin.slot.width * gui_skin.player_inv_columns
+ (skin.slot.column_margin * (gui_skin.player_inv_columns - 1))
local inv_height = skin.slot.height * gui_skin.player_inv_rows
+ (skin.slot.row_margin * (gui_skin.player_inv_rows - 1))
local inner_width = inv_width + inner_x * 2
local width = inner_width + outer_x * 2
local sep_height = INDICATOR_SPACING
local ind_h = INDICATOR_HEIGHT + INDICATOR_SPACING * 0.5
if skin.material_indicator then
sep_height = skin.material_indicator.spacing
ind_h = skin.material_indicator.height + skin.material_indicator.spacing * 0.5
end
local sep_height = skin.material_indicator.spacing
local ind_h = skin.material_indicator.height + skin.material_indicator.spacing * 0.5
if data.tab == 1 then
local convert_height = (skin.slot.height or SLOT_HEIGHT) + sep_height
local convert_height = skin.slot.height + sep_height
local form_height = (outer_y * 2) + (inner_y * 2) + convert_height + ind_h + sep_height * 2 + inv_height
minetest.show_formspec(player, "cartographer:table",
fs.header(width, form_height, rank, data.tab, skin) ..
@ -769,13 +709,9 @@ local function table_formspec(player)
fs.inv(inner_x, ind_h + sep_height * 2 + convert_height, skin),
})
elseif data.tab == 2 then
local radio_height = RADIO_HEIGHT
local radio_margin_y = RADIO_MARGIN_Y
if skin.radio then
radio_height = skin.radio.height
radio_margin_y = skin.radio.margin_y
end
local craft_height = radio_height + radio_margin_y * 2 + (skin.slot_height or SLOT_HEIGHT) + sep_height
local radio_height = skin.radio.height
local radio_margin_y = skin.radio.margin_y
local craft_height = radio_height + radio_margin_y * 2 + skin.slot.height + sep_height
local form_height = (outer_y * 2) + (inner_y * 2) + craft_height + ind_h + sep_height * 2 + inv_height
minetest.show_formspec(player, "cartographer:table",
fs.header(width, form_height, rank, data.tab, skin) ..
@ -789,7 +725,7 @@ local function table_formspec(player)
fs.inv(inner_x, ind_h + craft_height + sep_height * 2, skin),
})
elseif data.tab == 3 then
local copy_height = (skin.slot.height or SLOT_HEIGHT) + sep_height
local copy_height = skin.slot.height + sep_height
local form_height = (outer_y * 2) + (inner_y * 2) + copy_height + ind_h + sep_height * 2 + inv_height
minetest.show_formspec(player, "cartographer:table",
fs.header(width, form_height, rank, data.tab, skin) ..