mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
mcl_craftguide
: Autoformat and fix misleading variable names
This commit is contained in:
parent
a3fbb2e0c9
commit
f8e934c1dd
1 changed files with 63 additions and 63 deletions
|
@ -24,11 +24,11 @@ local ESC = M.formspec_escape
|
||||||
local S = M.get_translator("mcl_craftguide")
|
local S = M.get_translator("mcl_craftguide")
|
||||||
|
|
||||||
local maxn, sort, concat, insert, copy =
|
local maxn, sort, concat, insert, copy =
|
||||||
table.maxn, table.sort, table.concat, table.insert,
|
table.maxn, table.sort, table.concat, table.insert,
|
||||||
table.copy
|
table.copy
|
||||||
|
|
||||||
local fmt, find, gmatch, match, sub, split, lower =
|
local fmt, find, gmatch, match, sub, split, lower =
|
||||||
string.format, string.find, string.gmatch, string.match,
|
string.format, string.find, string.gmatch, string.match,
|
||||||
string.sub, string.split, string.lower
|
string.sub, string.split, string.lower
|
||||||
|
|
||||||
local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
|
local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
|
||||||
|
@ -42,38 +42,38 @@ local GRID_LIMIT = 5
|
||||||
local POLL_FREQ = 0.25
|
local POLL_FREQ = 0.25
|
||||||
|
|
||||||
local FMT = {
|
local FMT = {
|
||||||
box = "box[%f,%f;%f,%f;%s]",
|
box = "box[%f,%f;%f,%f;%s]",
|
||||||
label = "label[%f,%f;%s]",
|
label = "label[%f,%f;%s]",
|
||||||
image = "image[%f,%f;%f,%f;%s]",
|
image = "image[%f,%f;%f,%f;%s]",
|
||||||
button = "button[%f,%f;%f,%f;%s;%s]",
|
button = "button[%f,%f;%f,%f;%s;%s]",
|
||||||
tooltip = "tooltip[%s;%s]",
|
tooltip = "tooltip[%s;%s]",
|
||||||
item_image = "item_image[%f,%f;%f,%f;%s]",
|
item_image = "item_image[%f,%f;%f,%f;%s]",
|
||||||
image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
|
image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
}
|
}
|
||||||
|
|
||||||
local group_stereotypes = {
|
local group_stereotypes = {
|
||||||
wood = "mcl_core:wood",
|
wood = "mcl_core:wood",
|
||||||
stone = "mcl_core:stone",
|
stone = "mcl_core:stone",
|
||||||
sand = "mcl_core:sand",
|
sand = "mcl_core:sand",
|
||||||
wool = "mcl_wool:white",
|
wool = "mcl_wool:white",
|
||||||
carpet = "mcl_wool:white_carpet",
|
carpet = "mcl_wool:white_carpet",
|
||||||
dye = "mcl_dye:red",
|
dye = "mcl_dye:red",
|
||||||
water_bucket = "mcl_buckets:bucket_water",
|
water_bucket = "mcl_buckets:bucket_water",
|
||||||
flower = "mcl_flowers:dandelion",
|
flower = "mcl_flowers:dandelion",
|
||||||
mushroom = "mcl_mushrooms:mushroom_brown",
|
mushroom = "mcl_mushrooms:mushroom_brown",
|
||||||
wood_slab = "mcl_stairs:slab_wood",
|
wood_slab = "mcl_stairs:slab_wood",
|
||||||
wood_stairs = "mcl_stairs:stairs_wood",
|
wood_stairs = "mcl_stairs:stairs_wood",
|
||||||
coal = "mcl_core:coal_lump",
|
coal = "mcl_core:coal_lump",
|
||||||
shulker_box = "mcl_chests:violet_shulker_box",
|
shulker_box = "mcl_chests:violet_shulker_box",
|
||||||
quartz_block = "mcl_nether:quartz_block",
|
quartz_block = "mcl_nether:quartz_block",
|
||||||
banner = "mcl_banners:banner_item_white",
|
banner = "mcl_banners:banner_item_white",
|
||||||
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
||||||
purpur_block = "mcl_end:purpur_block",
|
purpur_block = "mcl_end:purpur_block",
|
||||||
normal_sandstone = "mcl_core:sandstone",
|
normal_sandstone = "mcl_core:sandstone",
|
||||||
red_sandstone = "mcl_core:redsandstone",
|
red_sandstone = "mcl_core:redsandstone",
|
||||||
compass = mcl_compass.stereotype,
|
compass = mcl_compass.stereotype,
|
||||||
clock = mcl_clock.sterotype,
|
clock = mcl_clock.sterotype,
|
||||||
}
|
}
|
||||||
|
|
||||||
local group_names = {
|
local group_names = {
|
||||||
|
@ -192,7 +192,7 @@ function mcl_craftguide.set_recipe_filter(name, f)
|
||||||
assert(name, func .. "filter name missing")
|
assert(name, func .. "filter name missing")
|
||||||
assert(f and type(f) == "function", func .. "filter function missing")
|
assert(f and type(f) == "function", func .. "filter function missing")
|
||||||
|
|
||||||
recipe_filters = {[name] = f}
|
recipe_filters = { [name] = f }
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_craftguide.get_recipe_filters()
|
function mcl_craftguide.get_recipe_filters()
|
||||||
|
@ -289,23 +289,23 @@ local function get_item_usages(item)
|
||||||
local usages, c = {}, 0
|
local usages, c = {}, 0
|
||||||
|
|
||||||
for _, recipes in pairs(recipes_cache) do
|
for _, recipes in pairs(recipes_cache) do
|
||||||
for i = 1, #recipes do
|
for i = 1, #recipes do
|
||||||
local recipe = recipes[i]
|
local recipe = recipes[i]
|
||||||
if item_in_recipe(item, recipe) then
|
if item_in_recipe(item, recipe) then
|
||||||
c = c + 1
|
|
||||||
usages[c] = recipe
|
|
||||||
else
|
|
||||||
recipe = groups_item_in_recipe(item, recipe)
|
|
||||||
if recipe then
|
|
||||||
c = c + 1
|
c = c + 1
|
||||||
usages[c] = recipe
|
usages[c] = recipe
|
||||||
|
else
|
||||||
|
recipe = groups_item_in_recipe(item, recipe)
|
||||||
|
if recipe then
|
||||||
|
c = c + 1
|
||||||
|
usages[c] = recipe
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if fuel_cache[item] then
|
if fuel_cache[item] then
|
||||||
usages[#usages + 1] = {type = "fuel", width = 1, items = {item}}
|
usages[#usages + 1] = { type = "fuel", width = 1, items = { item } }
|
||||||
end
|
end
|
||||||
|
|
||||||
return usages
|
return usages
|
||||||
|
@ -320,7 +320,7 @@ local function get_filtered_items(player)
|
||||||
local usages = usages_cache[item]
|
local usages = usages_cache[item]
|
||||||
|
|
||||||
if recipes and #apply_recipe_filters(recipes, player) > 0 or
|
if recipes and #apply_recipe_filters(recipes, player) > 0 or
|
||||||
usages and #apply_recipe_filters(usages, player) > 0 then
|
usages and #apply_recipe_filters(usages, player) > 0 then
|
||||||
c = c + 1
|
c = c + 1
|
||||||
items[c] = item
|
items[c] = item
|
||||||
end
|
end
|
||||||
|
@ -373,7 +373,7 @@ local function get_recipes(item, data, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_burntime(item)
|
local function get_burntime(item)
|
||||||
return get_result({method = "fuel", width = 1, items = {item}}).time
|
return get_result({ method = "fuel", width = 1, items = { item } }).time
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cache_fuel(item)
|
local function cache_fuel(item)
|
||||||
|
@ -430,13 +430,13 @@ local function get_tooltip(item, groups, cooktime, burntime)
|
||||||
tooltip = groupstr
|
tooltip = groupstr
|
||||||
else
|
else
|
||||||
|
|
||||||
local groupstr, c = {}, 0
|
local grouptable, c = {}, 0
|
||||||
for i = 1, #groups do
|
for i = 1, #groups do
|
||||||
c = c + 1
|
c = c + 1
|
||||||
groupstr[c] = colorize(gcol, groups[i])
|
grouptable[c] = colorize(gcol, groups[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
groupstr = concat(groupstr, ", ")
|
groupstr = concat(grouptable, ", ")
|
||||||
tooltip = S("Any item belonging to the groups: @1", groupstr)
|
tooltip = S("Any item belonging to the groups: @1", groupstr)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -475,7 +475,7 @@ local function get_recipe_fs(data, iY)
|
||||||
end
|
end
|
||||||
|
|
||||||
local rows = ceil(maxn(recipe.items) / width)
|
local rows = ceil(maxn(recipe.items) / width)
|
||||||
local rightest, btn_size, s_btn_size = 0, 1.1
|
local rightest, btn_size, s_btn_size = 0, 1.1, nil
|
||||||
|
|
||||||
local btn_lab = data.show_usages and
|
local btn_lab = data.show_usages and
|
||||||
ESC(S("Usage @1 of @2", data.rnum, #data.recipes)) or
|
ESC(S("Usage @1 of @2", data.rnum, #data.recipes)) or
|
||||||
|
@ -545,7 +545,7 @@ local function get_recipe_fs(data, iY)
|
||||||
|
|
||||||
if custom_recipe or shapeless or recipe.type == "cooking" then
|
if custom_recipe or shapeless or recipe.type == "cooking" then
|
||||||
local icon = custom_recipe and custom_recipe.icon or
|
local icon = custom_recipe and custom_recipe.icon or
|
||||||
shapeless and "shapeless" or "furnace"
|
shapeless and "shapeless" or "furnace"
|
||||||
|
|
||||||
if recipe.type == "cooking" then
|
if recipe.type == "cooking" then
|
||||||
icon = "craftguide_furnace.png"
|
icon = "craftguide_furnace.png"
|
||||||
|
@ -561,7 +561,7 @@ local function get_recipe_fs(data, iY)
|
||||||
icon)
|
icon)
|
||||||
|
|
||||||
local tooltip = custom_recipe and custom_recipe.description or
|
local tooltip = custom_recipe and custom_recipe.description or
|
||||||
shapeless and S("Shapeless") or S("Cooking")
|
shapeless and S("Shapeless") or S("Cooking")
|
||||||
|
|
||||||
fs[#fs + 1] = fmt("tooltip[%f,%f;%f,%f;%s]",
|
fs[#fs + 1] = fmt("tooltip[%f,%f;%f,%f;%s]",
|
||||||
rightest + 1.2,
|
rightest + 1.2,
|
||||||
|
@ -741,7 +741,7 @@ mcl_craftguide.add_search_filter("groups", function(item, groups)
|
||||||
for i = 1, #groups do
|
for i = 1, #groups do
|
||||||
local group = groups[i]
|
local group = groups[i]
|
||||||
if not itemdef.groups[group] then
|
if not itemdef.groups[group] then
|
||||||
has_groups = nil
|
has_groups = false
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -772,9 +772,9 @@ local function search(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #data.items_raw do
|
for i = 1, #data.items_raw do
|
||||||
local item = data.items_raw[i]
|
local item = data.items_raw[i]
|
||||||
local def = reg_items[item]
|
local def = reg_items[item]
|
||||||
local desc = lower(def.description)
|
local desc = lower(def.description)
|
||||||
local search_in = item .. desc
|
local search_in = item .. desc
|
||||||
local to_add
|
local to_add
|
||||||
|
|
||||||
|
@ -833,10 +833,10 @@ end
|
||||||
|
|
||||||
local function init_data(name)
|
local function init_data(name)
|
||||||
player_data[name] = {
|
player_data[name] = {
|
||||||
filter = "",
|
filter = "",
|
||||||
pagenum = 1,
|
pagenum = 1,
|
||||||
iX = sfinv_only and 8 or DEFAULT_SIZE,
|
iX = sfinv_only and 8 or DEFAULT_SIZE,
|
||||||
items = init_items,
|
items = init_items,
|
||||||
items_raw = init_items,
|
items_raw = init_items,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -863,8 +863,8 @@ local function get_init_items()
|
||||||
for name, def in pairs(reg_items) do
|
for name, def in pairs(reg_items) do
|
||||||
local is_fuel = cache_fuel(name)
|
local is_fuel = cache_fuel(name)
|
||||||
if not (def.groups.not_in_craft_guide == 1) and
|
if not (def.groups.not_in_craft_guide == 1) and
|
||||||
def.description and def.description ~= "" and
|
def.description and def.description ~= "" and
|
||||||
(cache_recipes(name) or is_fuel) then
|
(cache_recipes(name) or is_fuel) then
|
||||||
c = c + 1
|
c = c + 1
|
||||||
init_items[c] = name
|
init_items[c] = name
|
||||||
end
|
end
|
||||||
|
@ -898,7 +898,7 @@ local function on_receive_fields(player, fields)
|
||||||
show_fs(player, name)
|
show_fs(player, name)
|
||||||
|
|
||||||
elseif (fields.key_enter_field == "filter" or fields.search) and
|
elseif (fields.key_enter_field == "filter" or fields.search) and
|
||||||
fields.filter ~= "" then
|
fields.filter ~= "" then
|
||||||
local fltr = lower(fields.filter)
|
local fltr = lower(fields.filter)
|
||||||
if data.filter == fltr then
|
if data.filter == fltr then
|
||||||
return
|
return
|
||||||
|
@ -925,7 +925,7 @@ local function on_receive_fields(player, fields)
|
||||||
show_fs(player, name)
|
show_fs(player, name)
|
||||||
|
|
||||||
elseif (fields.size_inc and data.iX < MAX_LIMIT) or
|
elseif (fields.size_inc and data.iX < MAX_LIMIT) or
|
||||||
(fields.size_dec and data.iX > MIN_LIMIT) then
|
(fields.size_dec and data.iX > MIN_LIMIT) then
|
||||||
data.pagenum = 1
|
data.pagenum = 1
|
||||||
data.iX = data.iX + (fields.size_inc and 1 or -1)
|
data.iX = data.iX + (fields.size_inc and 1 or -1)
|
||||||
show_fs(player, name)
|
show_fs(player, name)
|
||||||
|
@ -1073,9 +1073,9 @@ if progressive_mode then
|
||||||
local function poll_new_items()
|
local function poll_new_items()
|
||||||
local players = M.get_connected_players()
|
local players = M.get_connected_players()
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local player = players[i]
|
local player = players[i]
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = player_data[name]
|
local data = player_data[name]
|
||||||
local inv_items = get_inv_items(player)
|
local inv_items = get_inv_items(player)
|
||||||
local diff = table_diff(inv_items, data.inv_items)
|
local diff = table_diff(inv_items, data.inv_items)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue