skinlist: Allow textures containing '-' characters

Fixes issue #110
Thanks to Bastrabun for the code suggestion
This commit is contained in:
SmallJoker 2024-09-28 11:10:44 +02:00
parent df62f2042d
commit 3cf80c9272
3 changed files with 6 additions and 4 deletions

View File

@ -6,7 +6,7 @@ local dbgprint = false and print or function() end
function skins.register_skin(path, filename) function skins.register_skin(path, filename)
-- See "textures/readme.txt" for allowed formats -- See "textures/readme.txt" for allowed formats
local prefix, sep, identifier, extension = filename:match("^(%a+)([_.])([%w_.]+)%.(%a+)$") local prefix, sep, identifier, extension = filename:match("^(%a+)([_.])([%w_.-]+)%.(%a+)$")
--[[ --[[
prefix: "character" or "player" prefix: "character" or "player"
sep: "." (new) or "_" (legacy) sep: "." (new) or "_" (legacy)

View File

@ -6,6 +6,7 @@ List of accepted texture names
Public skin available for all users: Public skin available for all users:
character.[number or name].png character.[number or name].png
^ The allowed characters in "[number or name]" are "[A-z0-9_.-]+".
One or multiple private skins for player "[nick]": One or multiple private skins for player "[nick]":
player.[nick].png player.[nick].png

View File

@ -9,12 +9,14 @@ local function run_unittest()
-- ----- -- -----
-- `.`: Simple register + retrieve operations -- `.`: Simple register + retrieve operations
skins.register_skin(PATH, "player.DotSep.png") assert(skins.register_skin(PATH, "player.DotSep.png"))
skins.register_skin(PATH, "player._DotSep_666_.1.png") assert(skins.register_skin(PATH, "player._DotSep_666_.1.png"))
assert(skins.register_skin(PATH, "character._DotSep_With-Dash-.png"))
assert(get_skin("player.DotSep")) assert(get_skin("player.DotSep"))
assert(get_skin("player._DotSep_666_.1")) assert(get_skin("player._DotSep_666_.1"))
assert(get_skin("player.DotSep.1") == nil) assert(get_skin("player.DotSep.1") == nil)
assert(get_skin("character._DotSep_With-Dash-"))
-- ----- -- -----
-- Ambiguous skin names (filenames without extension). Register + retrieve -- Ambiguous skin names (filenames without extension). Register + retrieve
@ -42,7 +44,6 @@ local function run_unittest()
assert(get_skin("player_Com_Pat_42") == "player._Com_Pat_42") assert(get_skin("player_Com_Pat_42") == "player._Com_Pat_42")
assert(get_skin("player_Com_Pat_42_1") == "player._Com_Pat_42.1") assert(get_skin("player_Com_Pat_42_1") == "player._Com_Pat_42.1")
error("Unittest passed! Please disable them now.") error("Unittest passed! Please disable them now.")
end end