Skip to content

Commit

Permalink
skinlist: Allow textures containing '-' characters
Browse files Browse the repository at this point in the history
Fixes issue #110
Thanks to Bastrabun for the code suggestion
  • Loading branch information
SmallJoker committed Sep 28, 2024
1 parent df62f20 commit 3cf80c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion skinlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local dbgprint = false and print or function() end
function skins.register_skin(path, filename)
-- 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"
sep: "." (new) or "_" (legacy)
Expand Down
1 change: 1 addition & 0 deletions textures/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ List of accepted texture names

Public skin available for all users:
character.[number or name].png
^ The allowed characters in "[number or name]" are "[A-z0-9_.-]+".

One or multiple private skins for player "[nick]":
player.[nick].png
Expand Down
7 changes: 4 additions & 3 deletions unittest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ local function run_unittest()

-- -----
-- `.`: Simple register + retrieve operations
skins.register_skin(PATH, "player.DotSep.png")
skins.register_skin(PATH, "player._DotSep_666_.1.png")
assert(skins.register_skin(PATH, "player.DotSep.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_666_.1"))
assert(get_skin("player.DotSep.1") == nil)
assert(get_skin("character._DotSep_With-Dash-"))

-- -----
-- Ambiguous skin names (filenames without extension). Register + retrieve
Expand Down Expand Up @@ -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_1") == "player._Com_Pat_42.1")


error("Unittest passed! Please disable them now.")
end

Expand Down

0 comments on commit 3cf80c9

Please sign in to comment.