summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Weber <web.alexander@web.de>2018-01-07 19:09:52 +0100
committerAlexander Weber <web.alexander@web.de>2018-01-07 19:09:52 +0100
commit429874698ea5176e15a3b5703ac734b5b123d842 (patch)
tree560d03e39bae1038f6f483bec00546c36ffbaf06
parent7df6363aa0247068205a09815721164813849b19 (diff)
Add skins.get_skinlist_with_meta(key, value) and small adjustments
-rw-r--r--API.md14
-rw-r--r--skin_meta_api.lua4
-rw-r--r--skinlist.lua13
3 files changed, 24 insertions, 7 deletions
diff --git a/API.md b/API.md
index ad0248b..f94213b 100644
--- a/API.md
+++ b/API.md
@@ -16,12 +16,14 @@ skins.update_player_skin(player)
```
## skins.get_skinlist(assignment, select_unassigned)
-Get a list of skin objects matching to the assignment.
+Obsolete - use get_skinlist_for_player() or get_skinlist_with_meta() instead
-Supported assignments:
- - "player:"..playername - Skins directly assigned to a player
+## skins.get_skinlist_for_player(playername)
+Get all allowed skins for player. All public and all player's private skins. If playername not given only public skins returned
-select_unassigned - Select all skins without assignment too (usually the "character_*" skins)
+## skins.get_skinlist_with_meta(key, value)
+Get all skins with metadata key is set to value. Example:
+skins.get_skinlist_with_meta("playername", playername) - Get all private skins (w.o. public) for playername
## skins.new(key, object)
@@ -73,10 +75,10 @@ The next metadata keys are usually filled
- author - The skin author
- license - THe skin texture license
- assignment - (obsolete) is "player:playername" in case the skin is assigned to be privat for a player
- - playername - Player assignment for private skin
+ - playername - Player assignment for private skin. Set false for skins not usable by all players (like NPC-Skins), true or nothing for all player skins
## skin:get_meta_string(key)
Same as get_meta() but does return "" instead of nil if the meta key does not exists
## skin:is_applicable_for_player(playername)
-Check if a skin is applicable for the player "playername". Ususally the private skins could be applied to the player only
+Returns whether this skin is applicable for player "playername" or not, like private skins
diff --git a/skin_meta_api.lua b/skin_meta_api.lua
index 1e3bd99..5ff17f1 100644
--- a/skin_meta_api.lua
+++ b/skin_meta_api.lua
@@ -72,5 +72,7 @@ end
function skin_class:is_applicable_for_player(playername)
local assigned_player = self:get_meta("playername")
- return not assigned_player or assigned_player == playername
+ return assigned_player == nil or
+ assigned_player == playername or
+ assigned_player == true
end
diff --git a/skinlist.lua b/skinlist.lua
index 889b531..0a06f5d 100644
--- a/skinlist.lua
+++ b/skinlist.lua
@@ -82,3 +82,16 @@ function skins.get_skinlist_for_player(playername)
table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
return skinslist
end
+
+-- Get skinlist selected by metadata
+function skins.get_skinlist_with_meta(key, value)
+ assert(key, "key parameter for skins.get_skinlist_with_meta() missed")
+ local skinslist = {}
+ for _, skin in pairs(skins.meta) do
+ if skin:get_meta(key) == value then
+ table.insert(skinslist, skin)
+ end
+ end
+ table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
+ return skinslist
+end