Skip to content

Commit

Permalink
Added a sort by accessibility to the Sort module.
Browse files Browse the repository at this point in the history
  • Loading branch information
DFortun81 committed Jul 23, 2023
1 parent d757aab commit 6b472d4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Sort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ local ipairs, pairs, tostring, type, string_lower, table_sort, pcall
-- Module locals

-- Sorting Logic
local calculateAccessibility = function(source)
local score = 0;
if source.nmr then
score = score + 10;
end
if source.nmc then
score = score + 10;
end
if source.e then
score = score + 1;
end
if source.u then
score = score + 1;
if source.u < 3 then
score = score + 100;
elseif source.u < 4 then
score = score + 10;
else
score = score + 1;
end
end
return score;
end
local sortByAccessibility = function(a, b)
return calculateAccessibility(a) <= calculateAccessibility(b);
end
local defaultComparison = function(a,b)
-- If either object doesn't exist
if a then
Expand Down Expand Up @@ -178,6 +204,7 @@ local defaultEventStartComparison = function(a,b)
return acomp < bcomp;
end
app.SortDefaults = {
Accessibility = sortByAccessibility,
Global = defaultComparison,
Text = defaultTextComparison,
Name = defaultNameComparison,
Expand Down

0 comments on commit 6b472d4

Please sign in to comment.