mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 21:11:50 +00:00
small refactor of packs_info
This commit is contained in:
parent
2e55380f2c
commit
ccc11232bb
2 changed files with 25 additions and 13 deletions
|
|
@ -52,7 +52,10 @@ function reposition_func(_pack)
|
||||||
else
|
else
|
||||||
tbl = packs_excluded
|
tbl = packs_excluded
|
||||||
local packinfo = pack.get_info(_pack)
|
local packinfo = pack.get_info(_pack)
|
||||||
packinfo[packinfo.id] = {packinfo.id, packinfo.title}
|
packinfo[packinfo.id] = {
|
||||||
|
id = packinfo.id,
|
||||||
|
title = packinfo.title
|
||||||
|
}
|
||||||
table.insert(packs_excluded, packinfo.id)
|
table.insert(packs_excluded, packinfo.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -77,7 +80,7 @@ function refresh_search()
|
||||||
end
|
end
|
||||||
local res = math.max(
|
local res = math.max(
|
||||||
search_utils.fuzzy_score(id, search_text),
|
search_utils.fuzzy_score(id, search_text),
|
||||||
search_utils.fuzzy_score(packs_info[id][2], search_text)
|
search_utils.fuzzy_score(packs_info[id].title, search_text)
|
||||||
)
|
)
|
||||||
smart_score_cache[id] = res
|
smart_score_cache[id] = res
|
||||||
return res
|
return res
|
||||||
|
|
@ -90,7 +93,7 @@ function refresh_search()
|
||||||
if score_a ~= score_b then
|
if score_a ~= score_b then
|
||||||
return score_a > score_b
|
return score_a > score_b
|
||||||
else
|
else
|
||||||
return packs_info[a][2] < packs_info[b][2]
|
return packs_info[a].title < packs_info[b].title
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -350,12 +353,18 @@ function refresh()
|
||||||
|
|
||||||
for _,id in ipairs(base_packs) do
|
for _,id in ipairs(base_packs) do
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
packs_info[id] = {packinfo.id, packinfo.title}
|
packs_info[id] = {
|
||||||
|
id = packinfo.id,
|
||||||
|
title = packinfo.title
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,id in ipairs(packs_all) do
|
for _,id in ipairs(packs_all) do
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
packs_info[id] = {packinfo.id, packinfo.title}
|
packs_info[id] = {
|
||||||
|
id = packinfo.id,
|
||||||
|
title = packinfo.title
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) end
|
if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) end
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,14 @@ function refresh_search()
|
||||||
local smart_score_cache = {}
|
local smart_score_cache = {}
|
||||||
|
|
||||||
local function smart_fuzzy_score(a)
|
local function smart_fuzzy_score(a)
|
||||||
if smart_score_cache[a[1]] then
|
if smart_score_cache[a.id] then
|
||||||
return smart_score_cache[a[1]]
|
return smart_score_cache[a.id]
|
||||||
end
|
end
|
||||||
local res = math.max(
|
local res = math.max(
|
||||||
search_utils.fuzzy_score(a[1], search_text),
|
search_utils.fuzzy_score(a.id, search_text),
|
||||||
search_utils.fuzzy_score(a[2], search_text)
|
search_utils.fuzzy_score(a.title, search_text)
|
||||||
)
|
)
|
||||||
smart_score_cache[a[1]] = res
|
smart_score_cache[a.id] = res
|
||||||
if res > 0 then
|
if res > 0 then
|
||||||
score_non_zero_num = score_non_zero_num + 1
|
score_non_zero_num = score_non_zero_num + 1
|
||||||
end
|
end
|
||||||
|
|
@ -59,7 +59,7 @@ function refresh_search()
|
||||||
local score_a = smart_fuzzy_score(a)
|
local score_a = smart_fuzzy_score(a)
|
||||||
local score_b = smart_fuzzy_score(b)
|
local score_b = smart_fuzzy_score(b)
|
||||||
if score_a == score_b then
|
if score_a == score_b then
|
||||||
return a[2] > b[2]
|
return a.title > b.title
|
||||||
else
|
else
|
||||||
return score_a > score_b
|
return score_a > score_b
|
||||||
end
|
end
|
||||||
|
|
@ -68,7 +68,7 @@ function refresh_search()
|
||||||
table.sort(packs, cmp)
|
table.sort(packs, cmp)
|
||||||
|
|
||||||
for i, v in ipairs(packs) do
|
for i, v in ipairs(packs) do
|
||||||
local id = v[1]
|
local id = v.id
|
||||||
local content = document["pack_" .. id]
|
local content = document["pack_" .. id]
|
||||||
local pos = content.pos
|
local pos = content.pos
|
||||||
local size = content.size
|
local size = content.size
|
||||||
|
|
@ -304,7 +304,10 @@ function refresh()
|
||||||
local packinfo = packinfos[id]
|
local packinfo = packinfos[id]
|
||||||
|
|
||||||
packinfo.id = id
|
packinfo.id = id
|
||||||
packs_installed[i] = {packinfo.id, packinfo.title}
|
packs_installed[i] = {
|
||||||
|
id = packinfo.id,
|
||||||
|
title = packinfo.title
|
||||||
|
}
|
||||||
local callback = string.format('open_pack("%s")', id)
|
local callback = string.format('open_pack("%s")', id)
|
||||||
place_pack(contents, packinfo, callback)
|
place_pack(contents, packinfo, callback)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue