summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Weber <web.alexander@web.de>2017-06-17 00:23:39 +0200
committerAlexander Weber <web.alexander@web.de>2017-06-17 00:23:39 +0200
commit50e6c9e2d01bbeb04be7fcaf58ff5233125b3ff3 (patch)
tree10af912f96ceccfed7b8b4b33ccd052b2edb4cd1
parent077312257de7f3fa5c3b815e5b81b001a26d9f9d (diff)
added skins.get_skinlist(listname), sfinv prepared for per player skinlist
-rw-r--r--sfinv_page.lua33
-rw-r--r--skinlist.lua23
-rw-r--r--unified_inventory_page.lua8
3 files changed, 39 insertions, 25 deletions
diff --git a/sfinv_page.lua b/sfinv_page.lua
index 30ec39d..5fcd6e2 100644
--- a/sfinv_page.lua
+++ b/sfinv_page.lua
@@ -5,17 +5,6 @@ else
S = function(s) return s end
end
-local dropdown_values = {}
-
--- collect skins data
-local total_pages = 1
-for i, skin in ipairs(skins.list) do
- local page = math.floor((i-1) / 16)+1
- skin:set_meta("inv_page", page)
- skin:set_meta("inv_page_index", (i-1)%16+1)
- total_pages = page
-end
-
-- generate the current formspec
local function get_formspec(player, context)
local name = player:get_player_name()
@@ -47,7 +36,7 @@ local function get_formspec(player, context)
end
for i = (page-1)*16+1, page*16 do
- local skin = skins.list[i]
+ local skin = context.skins_list[i]
if not skin then
break
end
@@ -67,15 +56,15 @@ local function get_formspec(player, context)
local page_prev = page - 1
local page_next = page + 1
if page_prev < 1 then
- page_prev = total_pages
+ page_prev = context.total_pages
end
- if page_next > total_pages then
+ if page_next > context.total_pages then
page_next = 1
end
local page_list = ""
dropdown_values = {}
- for pg=1, total_pages do
- local pagename = S("Page").." "..pg.."/"..total_pages
+ for pg=1, context.total_pages do
+ local pagename = S("Page").." "..pg.."/"..context.total_pages
dropdown_values[pagename] = pg
if pg > 1 then page_list = page_list.."," end
page_list = page_list..pagename
@@ -91,13 +80,23 @@ end
sfinv.register_page("skins:overview", {
title = "Skins",
get = function(self, player, context)
+ -- collect skins data
+ context.skins_list = skins.get_skinlist()
+ context.total_pages = 1
+ for i, skin in ipairs(context.skins_list ) do
+ local page = math.floor((i-1) / 16)+1
+ skin:set_meta("inv_page", page)
+ skin:set_meta("inv_page_index", (i-1)%16+1)
+ context.total_pages = page
+ end
+ -- generate first formspec
return sfinv.make_formspec(player, context, get_formspec(player, context))
end,
on_player_receive_fields = function(self, player, context, fields)
for field, _ in pairs(fields) do
local current = string.split(field, "$", 2)
if current[1] == "skins_set" then
- skins.set_player_skin(player, skins.list[tonumber(current[2])])
+ skins.set_player_skin(player, context.skins_list[tonumber(current[2])])
sfinv.set_player_inventory_formspec(player)
return
elseif current[1] == "skins_page" then
diff --git a/skinlist.lua b/skinlist.lua
index 5b074fd..87fe3f6 100644
--- a/skinlist.lua
+++ b/skinlist.lua
@@ -1,7 +1,7 @@
-skins.list = {}
local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
local unsorted_skinslist = {}
+local sorted_skinslist
for _, fn in pairs(skins_dir_list) do
if fn:find("^character_") then
nameparts = string.gsub(fn, "[.]", "_"):split("_")
@@ -26,7 +26,22 @@ for _, fn in pairs(skins_dir_list) do
end
end
-table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
-for _,v in ipairs(unsorted_skinslist) do
- table.insert(skins.list, v)
+-- get skinlist. listname not full implemented at the time: could be "mod:wardrobe" or "player:bell07" in feature
+function skins.get_skinlist(listname)
+ -- sort on demand
+ if not sorted_skinslist then
+ table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
+ sorted_skinslist = unsorted_skinslist
+ end
+ if not listname then
+ return sorted_skinslist
+ else
+ local ret = {}
+ for _, skin in ipairs(sorted_skinslist) do
+ if skin:get_meta(listname) then
+ table.insert(ret, skin)
+ end
+ end
+ return ret
+ end
end
diff --git a/unified_inventory_page.lua b/unified_inventory_page.lua
index ba3e72b..1892263 100644
--- a/unified_inventory_page.lua
+++ b/unified_inventory_page.lua
@@ -7,7 +7,7 @@ end
local dropdown_values = {}
local skins_reftab = {}
-
+local skins_list = skins.get_skinlist()
unified_inventory.register_page("skins", {
get_formspec = function(player)
local name = player:get_player_name()
@@ -44,7 +44,7 @@ unified_inventory.register_button("skins", {
-- Create all of the skin-picker pages.
local total_pages = 1
-for i, skin in ipairs(skins.list) do
+for i, skin in ipairs(skins_list) do
local page = math.floor((i-1) / 16)+1
skin:set_meta("inv_page", page)
skin:set_meta("inv_page_index", (i-1)%16+1)
@@ -54,7 +54,7 @@ end
for page=1, total_pages do
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"
for i = (page-1)*16+1, page*16 do
- local skin = skins.list[i]
+ local skin = skins_list[i]
if not skin then
break
end
@@ -108,7 +108,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
for field, _ in pairs(fields) do
local current = string.split(field, "$", 2)
if current[1] == "skins_set" then
- skins.set_player_skin(player, skins.list[tonumber(current[2])])
+ skins.set_player_skin(player, skins_list[tonumber(current[2])])
unified_inventory.set_inventory_formspec(player, "skins")
return
elseif current[1] == "skins_page" then