-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration code to player skins using '.' delimiters (#105)
Previously, the players would have their selected skin reset after renaming the skin textures to the dot separator. This commit implements skin name migration to ease the transition for server owners. See 'skins.__fuzzy_match_skin_name' for a detailed explanation.
- Loading branch information
1 parent
71f803e
commit 11bb5ba
Showing
5 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
local function get_skin(skin_name) | ||
local skin = skins.get(skin_name) | ||
or skins.__fuzzy_match_skin_name("(unittest)", skin_name, true) | ||
return skin and skin:get_key() or nil | ||
end | ||
|
||
local function run_unittest() | ||
local PATH = ":UNITTEST:" | ||
|
||
-- ----- | ||
-- `.`: Simple register + retrieve operations | ||
skins.register_skin(PATH, "player.DotSep.png") | ||
skins.register_skin(PATH, "player._DotSep_666_.1.png") | ||
|
||
assert(get_skin("player.DotSep")) | ||
assert(get_skin("player._DotSep_666_.1")) | ||
assert(get_skin("player.DotSep.1") == nil) | ||
|
||
-- ----- | ||
-- Ambiguous skin names (filenames without extension). Register + retrieve | ||
skins.new("player_AmbSki") | ||
skins.new("player_AmbSki_1") | ||
skins.new("player_AmbSki_666_1") | ||
|
||
assert(get_skin("player_AmbSki")) | ||
assert(get_skin("player_AmbSki_") == nil) | ||
assert(get_skin("player_AmbSki_1")) | ||
assert(get_skin("player_AmbSki_666_1")) | ||
-- There are no `__` patterns as they were silently removed by string.split | ||
|
||
|
||
-- ----- | ||
-- Mod Storage backwards compatibility | ||
-- Match the old `_` notation to `.`-separated skins | ||
skins.register_skin(PATH, "player.ComPat42.png") | ||
skins.register_skin(PATH, "player.ComPat42.5.png") | ||
skins.register_skin(PATH, "player._Com_Pat_42.png") | ||
skins.register_skin(PATH, "player._Com_Pat_42.1.png") | ||
|
||
assert(get_skin("player_ComPat42") == "player.ComPat42") | ||
assert(get_skin("player_ComPat42_5") == "player.ComPat42.5") | ||
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 | ||
|
||
run_unittest() | ||
|