diff options
-rw-r--r-- | init.lua | 26 | ||||
-rw-r--r-- | players.lua | 56 | ||||
-rw-r--r-- | skinlist.lua | 2 |
3 files changed, 24 insertions, 60 deletions
@@ -6,11 +6,7 @@ skins = {} skins.modpath = minetest.get_modpath("skins") -skins.file = minetest.get_worldpath().."/skins.mt" skins.default = "character_1" -skins.pages = {} -skins.skins = {} -skins.file_save = false skins.type = { SPRITE=0, MODEL=1, ERROR=99 } skins.get_type = function(texture) @@ -33,30 +29,8 @@ end dofile(skins.modpath.."/skinlist.lua") dofile(skins.modpath.."/players.lua") - -skins.update_player_skin = function(player) - local name = player:get_player_name() - - if not skins.is_skin(skins.skins[name]) then - skins.skins[name] = skins.default - end - player:set_properties({ - textures = {skins.skins[name]..".png"}, - }) -end - -- Unified inventory page/integration if minetest.get_modpath("unified_inventory") then dofile(skins.modpath.."/unified_inventory_page.lua") end --- Change skin on join - reset if invalid -minetest.register_on_joinplayer(function(player) - local player_name = player:get_player_name() - if not skins.is_skin(skins.skins[player_name]) then - skins.skins[player_name] = skins.default - end - skins.update_player_skin(player) -end) - - diff --git a/players.lua b/players.lua index e4f8842..f73f899 100644 --- a/players.lua +++ b/players.lua @@ -1,40 +1,30 @@ -skins.load_players = function() - local file = io.open(skins.file, "r") - if file then - for line in file:lines() do - local data = string.split(line, " ", 2) - skins.skins[data[1]] = data[2] - end - io.close(file) +-- get current skin +skins.get_player_skin = function(player) + local skin = player:get_attribute("skin") + if not skins.is_skin(skin) then + skin = skins.default end + return skin end -skins.load_players() -local ttime = 0 -minetest.register_globalstep(function(t) - ttime = ttime + t - if ttime < 360 then --every 6min' - return +-- Set skin +skins.set_player_skin = function(player, skin) + if skin == skins.default then + skin = "" end - ttime = 0 - skins.save() -end) - -minetest.register_on_shutdown(function() skins.save() end) + player:set_attribute("skin", skin) + skins.update_player_skin(player) +end -skins.save = function() - if not skins.file_save then - return - end - skins.file_save = false - local output = io.open(skins.file, "w") - for name, skin in pairs(skins.skins) do - if name and skin then - if skin ~= skins.default then - output:write(name.." "..skin.."\n") - end - end - end - io.close(output) +-- update visuals +skins.update_player_skin = function(player) + local skin = skins.get_player_skin(player) + player:set_properties({ + textures = {skins.list[skin]}, + }) end +-- Update skin on join +minetest.register_on_joinplayer(function(player) + skins.update_player_skin(player) +end) diff --git a/skinlist.lua b/skinlist.lua index c42d7ea..b38246f 100644 --- a/skinlist.lua +++ b/skinlist.lua @@ -15,7 +15,7 @@ for _, fn in pairs(skins_dir_list) do if file then local data = string.split(file:read("*all"), "\n", 3) file:close() - table.insert(skins.list, name) + skins.list[name] = fn skins.meta[name] = {} skins.meta[name].name = data[1] skins.meta[name].author = data[2] |