mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +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
|
||||
tbl = packs_excluded
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -77,7 +80,7 @@ function refresh_search()
|
|||
end
|
||||
local res = math.max(
|
||||
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
|
||||
return res
|
||||
|
|
@ -90,7 +93,7 @@ function refresh_search()
|
|||
if score_a ~= score_b then
|
||||
return score_a > score_b
|
||||
else
|
||||
return packs_info[a][2] < packs_info[b][2]
|
||||
return packs_info[a].title < packs_info[b].title
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -350,12 +353,18 @@ function refresh()
|
|||
|
||||
for _,id in ipairs(base_packs) do
|
||||
local packinfo = pack.get_info(id)
|
||||
packs_info[id] = {packinfo.id, packinfo.title}
|
||||
packs_info[id] = {
|
||||
id = packinfo.id,
|
||||
title = packinfo.title
|
||||
}
|
||||
end
|
||||
|
||||
for _,id in ipairs(packs_all) do
|
||||
local packinfo = pack.get_info(id)
|
||||
packs_info[id] = {packinfo.id, packinfo.title}
|
||||
packs_info[id] = {
|
||||
id = packinfo.id,
|
||||
title = packinfo.title
|
||||
}
|
||||
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 function smart_fuzzy_score(a)
|
||||
if smart_score_cache[a[1]] then
|
||||
return smart_score_cache[a[1]]
|
||||
if smart_score_cache[a.id] then
|
||||
return smart_score_cache[a.id]
|
||||
end
|
||||
local res = math.max(
|
||||
search_utils.fuzzy_score(a[1], search_text),
|
||||
search_utils.fuzzy_score(a[2], search_text)
|
||||
search_utils.fuzzy_score(a.id, 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
|
||||
score_non_zero_num = score_non_zero_num + 1
|
||||
end
|
||||
|
|
@ -59,7 +59,7 @@ function refresh_search()
|
|||
local score_a = smart_fuzzy_score(a)
|
||||
local score_b = smart_fuzzy_score(b)
|
||||
if score_a == score_b then
|
||||
return a[2] > b[2]
|
||||
return a.title > b.title
|
||||
else
|
||||
return score_a > score_b
|
||||
end
|
||||
|
|
@ -68,7 +68,7 @@ function refresh_search()
|
|||
table.sort(packs, cmp)
|
||||
|
||||
for i, v in ipairs(packs) do
|
||||
local id = v[1]
|
||||
local id = v.id
|
||||
local content = document["pack_" .. id]
|
||||
local pos = content.pos
|
||||
local size = content.size
|
||||
|
|
@ -304,7 +304,10 @@ function refresh()
|
|||
local packinfo = packinfos[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)
|
||||
place_pack(contents, packinfo, callback)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue