Browse Source

improve skins sorting with same sort_id

add skins license hint to the README.md
pull/35/head
Alexander Weber 6 months ago
parent
commit
166489597a
2 changed files with 16 additions and 3 deletions
  1. +1
    -0
      README.md
  2. +15
    -3
      skinlist.lua

+ 1
- 0
README.md View File

@@ -39,6 +39,7 @@ You might want to run `minetest` in a Terminal/Console window to check the log o

## License:
- GPLv3
- skin texture licenses: See "meta" folder

### Credits


+ 15
- 3
skinlist.lua View File

@@ -69,6 +69,18 @@ for _, fn in pairs(skins_dir_list) do
end
end

local function skins_sort(skinslist)
table.sort(skinslist, function(a,b)
local a_id = a:get_meta("_sort_id")
local b_id = b:get_meta("_sort_id")
if a_id ~= b_id then
return a:get_meta("_sort_id") < b:get_meta("_sort_id")
else
return a:get_meta("name") < b:get_meta("name")
end
end)
end

-- (obsolete) get skinlist. If assignment given ("mod:wardrobe" or "player:bell07") select skins matches the assignment. select_unassigned selects the skins without any assignment too
function skins.get_skinlist(assignment, select_unassigned)
minetest.log("deprecated", "skins.get_skinlist() is deprecated. Use skins.get_skinlist_for_player() instead")
@@ -80,7 +92,7 @@ function skins.get_skinlist(assignment, select_unassigned)
table.insert(skinslist, skin)
end
end
table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
skins_sort(skinslist)
return skinslist
end

@@ -92,7 +104,7 @@ function skins.get_skinlist_for_player(playername)
table.insert(skinslist, skin)
end
end
table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
skins_sort(skinslist)
return skinslist
end

@@ -105,6 +117,6 @@ function skins.get_skinlist_with_meta(key, value)
table.insert(skinslist, skin)
end
end
table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
skins_sort(skinslist)
return skinslist
end

Loading…
Cancel
Save