forked from Sokomine/yl_speak_up
sort keys numericly, i.e. p_2 before p_10
This commit is contained in:
parent
2d233a16e7
commit
86701d5325
@ -1950,13 +1950,26 @@ yl_speak_up.get_sorted_options = function(options, sort_by)
|
||||
end
|
||||
|
||||
|
||||
-- simple sort of keys of a table
|
||||
-- simple sort of keys of a table numericly;
|
||||
-- this is not efficient - but that doesn't matter: the lists are small and
|
||||
-- it is only executed when configuring an NPC
|
||||
yl_speak_up.sort_keys = function(t)
|
||||
local keys = {}
|
||||
for k, v in pairs(t) do
|
||||
-- add a prefix so that p_2 ends up before p_10
|
||||
if(string.len(k) == 3) then
|
||||
k = "a"..k
|
||||
end
|
||||
table.insert(keys, k)
|
||||
end
|
||||
table.sort(keys)
|
||||
for i,k in ipairs(keys) do
|
||||
-- avoid cutting the single a from a_1 (action 1)
|
||||
if(k and string.sub(k, 1, 1) == "a" and string.sub(k, 1, 2) ~= "aa") then
|
||||
-- remove the leading blank
|
||||
keys[i] = string.sub(k, 2)
|
||||
end
|
||||
end
|
||||
return keys
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user