Compare commits

..

5 Commits
1.5.2 ... 1.5.3

Author SHA1 Message Date
d8e17687e1 A bit of cleaning 2021-12-25 17:24:30 +01:00
2fadcdefdd Fix variable name 2021-12-25 17:01:25 +01:00
c7f6e1db62 API: fix custom recipe registration 2021-12-24 00:43:38 +01:00
16a1865e11 More cleaning 2021-12-21 17:16:46 +01:00
748cc9a7a1 Small cleaning 2021-12-21 15:39:04 +01:00
5 changed files with 78 additions and 93 deletions

View File

@ -257,4 +257,4 @@ end
--i3.files.tests.tabs() --i3.files.tests.tabs()
--i3.files.tests.operators() --i3.files.tests.operators()
--i3.files.tests.compression() --i3.files.tests.compression()
--i3.files.tests.custom_recipes(http) --i3.files.tests.custom_recipes()

View File

@ -1,5 +1,5 @@
local make_fs = i3.files.gui()
local http = ... local http = ...
local make_fs = i3.files.gui()
IMPORT("gmatch", "split") IMPORT("gmatch", "split")
IMPORT("S", "err", "fmt", "reg_items") IMPORT("S", "err", "fmt", "reg_items")
@ -22,7 +22,7 @@ end
function i3.register_craft(def) function i3.register_craft(def)
local width, c = 0, 0 local width, c = 0, 0
if true_str(def.url) then if http and true_str(def.url) then
http.fetch({url = def.url}, function(result) http.fetch({url = def.url}, function(result)
if result.succeeded then if result.succeeded then
local t = core.parse_json(result.data) local t = core.parse_json(result.data)
@ -51,7 +51,7 @@ function i3.register_craft(def)
def.result = nil def.result = nil
end end
if not true_str(def.output) then if not true_str(def.output) and not def.url then
return err "i3.register_craft: output missing" return err "i3.register_craft: output missing"
end end
@ -69,9 +69,7 @@ function i3.register_craft(def)
end end
local cp = copy(def.grid) local cp = copy(def.grid)
sort(cp, function(a, b) sort(cp, function(a, b) return #a > #b end)
return #a > #b
end)
width = #cp[1] width = #cp[1]
@ -86,26 +84,29 @@ function i3.register_craft(def)
def.items[c] = def.key[symbol] def.items[c] = def.key[symbol]
end end
else else
local items, len = def.items, #def.items local items = copy(def.items)
local lines = {}
def.items = {} def.items = {}
for i = 1, len do for i = 1, #items do
local rlen = #split(items[i], ",") lines[i] = split(items[i], ",", true)
if rlen > width then if #lines[i] > width then
width = rlen width = #lines[i]
end end
end end
for i = 1, len do for i = 1, #items do
while #split(items[i], ",") < width do while #lines[i] < width do
items[i] = fmt("%s,", items[i]) insert(lines[i], items[i])
end end
end end
for name in gmatch(concat(items, ","), "[%s%w_:]+") do for _, line in ipairs(lines) do
for _, v in ipairs(line) do
c++ c++
def.items[c] = clean_name(name) def.items[c] = clean_name(v)
end
end end
end end

View File

@ -234,14 +234,14 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
local width = 8 local width = 8
local base_height = 4 local base_height = 4
local base_depth = depth == -1 local base_depth = depth == -1
local max_depth = -10 local max_depth = -7
local height = base_depth and (base_height - 1) or depth local height = base_depth and (base_height - 1) or depth
local pos1 = vec_new(pos.x - width, pos.y + depth, pos.z - width) local pos1 = vec_new(pos.x - width, pos.y + depth, pos.z - width)
local pos2 = vec_new(pos.x + width, pos.y + height, pos.z + width) local pos2 = vec_new(pos.x + width, pos.y + height, pos.z + width)
local vm = VoxelManip(pos1, pos2) local vm = VoxelManip(pos1, pos2)
local emin, emax = vm:read_from_map(pos1, pos2) local emin, emax = vm:get_emerged_area()
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax} local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data() local data = vm:get_data()
@ -276,8 +276,9 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
if cubes < maxc and depth > max_depth then if cubes < maxc and depth > max_depth then
-- if there's not enough map to preview, go deeper -- if there's not enough map to preview, go deeper
depth -= 1 depth -= 1
get_isometric_view(fs, pos, X, Y, t, cubes, depth, high) return get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
else end
local shift = -0.3 - high local shift = -0.3 - high
for i = max_depth, 0 do for i = max_depth, 0 do
@ -295,7 +296,6 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
shift += (base_depth and 0.45 or 0.95) shift += (base_depth and 0.45 or 0.95)
fs("image", 2.7, Y + shift, 0.3, 0.3, PNG.flag) fs("image", 2.7, Y + shift, 0.3, 0.3, PNG.flag)
end end
end
local function get_waypoint_fs(fs, data, player, yextra, ctn_len) local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
fs(fmt("box[0,%f;4.9,0.6;#bababa25]", yextra + 1.1)) fs(fmt("box[0,%f;4.9,0.6;#bababa25]", yextra + 1.1))
@ -1093,8 +1093,7 @@ local function get_model_fs(fs, data, def, model_alias)
hex = "0" .. hex hex = "0" .. hex
end end
_name = fmt("%s^[multiply:%s", v.name, _name = fmt("%s^[multiply:%s", v.name, fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
else else
_name = fmt("%s^[multiply:%s", v.name, v.color) _name = fmt("%s^[multiply:%s", v.name, v.color)
end end
@ -1201,7 +1200,7 @@ local function get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_
fmt("craft_%s", name), ES("Craft (×@1)", stack_fs)) fmt("craft_%s", name), ES("Craft (×@1)", stack_fs))
end end
local function get_rcp_extra(fs, player, data, panel, is_recipe, is_usage) local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage)
fs"container[0,0.075]" fs"container[0,0.075]"
local rn = panel.rcp and #panel.rcp local rn = panel.rcp and #panel.rcp
@ -1270,7 +1269,7 @@ local function hide_items(player, data)
end end
end end
local function get_items_fs(fs, player, data, full_height) local function get_items_fs(fs, data, player, full_height)
hide_items(player, data) hide_items(player, data)
local items = data.alt_items or data.items or {} local items = data.alt_items or data.items or {}
@ -1278,6 +1277,8 @@ local function get_items_fs(fs, player, data, full_height)
local ipp = rows * lines local ipp = rows * lines
local size = 0.85 local size = 0.85
fs("bg9", data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full, 10)
fs(fmt("box[%f,0.2;4.05,0.6;#bababa25]", data.inv_width + 0.3), fs(fmt("box[%f,0.2;4.05,0.6;#bababa25]", data.inv_width + 0.3),
"set_focus[filter]", "set_focus[filter]",
fmt("field[%f,0.2;2.95,0.6;filter;;%s]", data.inv_width + 0.35, ESC(data.filter)), fmt("field[%f,0.2;2.95,0.6;filter;;%s]", data.inv_width + 0.35, ESC(data.filter)),
@ -1363,43 +1364,23 @@ local function get_favs(fs, data)
end end
end end
local function get_panels(fs, player, data, full_height) local function get_panels(fs, data, player)
local _title = {name = "title", height = 1.4} local title = {name = "title", height = 1.4, func = get_header}
local _favs = {name = "favs", height = 2.23} local favs = {name = "favs", height = 2.23, func = get_favs}
local _items = {name = "items", height = full_height} local recipes = {name = "recipes", rcp = data.recipes, height = 4.045, func = get_rcp_extra}
local _recipes = {name = "recipes", rcp = data.recipes, height = 4.045} local usages = {name = "usages", rcp = data.usages, height = 4.045, func = get_rcp_extra}
local _usages = {name = "usages", rcp = data.usages, height = 4.045} local panels = {title, recipes, usages, favs}
local panels
if data.query_item then
panels = {_title, _recipes, _usages, _favs}
else
panels = {_items}
end
for idx = 1, #panels do
local panel = panels[idx]
data.yoffset = 0 data.yoffset = 0
if idx > 1 then for i, panel in ipairs(panels) do
for _idx = idx - 1, 1, -1 do if i > 1 then
data.yoffset = data.yoffset + panels[_idx].height + 0.1 data.yoffset += panels[i - 1].height + 0.1
end
end end
fs("bg9", data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full, 10) fs("bg9", data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full, 10)
local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages" local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages"
panel.func(fs, data, player, panel, is_recipe, is_usage)
if is_recipe or is_usage then
get_rcp_extra(fs, player, data, panel, is_recipe, is_usage)
elseif panel.name == "items" then
get_items_fs(fs, player, data, full_height)
elseif panel.name == "title" then
get_header(fs, data)
elseif panel.name == "favs" then
get_favs(fs, data)
end
end end
end end
@ -1504,7 +1485,11 @@ local function make_fs(player, data)
tab.formspec(player, data, fs) tab.formspec(player, data, fs)
end end
get_panels(fs, player, data, full_height) if data.query_item then
get_panels(fs, data, player)
else
get_items_fs(fs, data, player, full_height)
end
if #i3.tabs > 1 then if #i3.tabs > 1 then
get_tabs_fs(fs, player, data, full_height) get_tabs_fs(fs, player, data, full_height)

View File

@ -34,7 +34,7 @@ local function init_hud(player)
}, },
} }
if not i3.legacy_inventory then if not i3.settings.legacy_inventory then
core.after(0, function() core.after(0, function()
player:hud_set_hotbar_itemcount(i3.settings.hotbar_len) player:hud_set_hotbar_itemcount(i3.settings.hotbar_len)
player:hud_set_hotbar_image"i3_hotbar.png" player:hud_set_hotbar_image"i3_hotbar.png"

View File

@ -38,6 +38,24 @@ i3.register_craft({
items = {"default:copper_ingot 7, default:tin_ingot, default:steel_ingot 2"}, items = {"default:copper_ingot 7, default:tin_ingot, default:steel_ingot 2"},
}) })
i3.register_craft {
result = "default:tree",
items = {
"default:wood",
"",
"default:wood"
},
}
i3.register_craft {
result = "default:cobble 16",
items = {
"default:stone, default:stone",
"default:stone, , default:stone",
", default:stone, default:stone",
}
}
i3.register_craft({ i3.register_craft({
grid = { grid = {
"X", "X",
@ -311,22 +329,3 @@ i3.register_craft({
}, },
result = "default:mese 3", result = "default:mese 3",
}) })
i3.register_craft({
grid = {
"X #",
" ## ",
"X#X#",
"#X#X#",
"X X##X#X",
" ## ",
"#X#X#",
"#X#X#",
"X #",
},
key = {
['#'] = "default:wood",
['X'] = "default:glass",
},
result = "default:mese 3",
})