Autogenerate skin previews and other @GreenDimond changes

This commit is contained in:
GreenDimond 2019-04-02 17:18:17 -07:00 committed by bell07
parent 664a4a8d81
commit 918df53f3b
17 changed files with 77 additions and 11 deletions

View File

@ -16,11 +16,14 @@ function skins.get_skin_info_formspec(skin)
local m_name = skin:get_meta_string("name")
local m_author = skin:get_meta_string("author")
local m_license = skin:get_meta_string("license")
local m_format = skin:get_meta("format")
-- overview page
local formspec = "image[0,.75;1,2;"..skin:get_preview().."]"
local raw_size = m_format == "1.8" and "2,2" or "2,1"
local formspec = "image[0.8,.6;1,2;"..minetest.formspec_escape(skin:get_preview()).."]"
if texture then
formspec = formspec.."label[6,.5;"..S("Raw texture")..":]"
.."image[6,1;2,1;"..skin:get_texture().."]"
.."image[6,1;"..raw_size..";"..texture.."]"
end
if m_name ~= "" then
formspec = formspec.."label[2,.5;"..S("Name")..": "..minetest.formspec_escape(m_name).."]"
@ -63,7 +66,7 @@ function skins.get_skin_selection_formspec(player, context, y_delta)
y = y_delta
end
formspec = formspec.."image_button["..x..","..y..";1,2;"..
skin:get_preview()..";skins_set$"..i..";]"..
minetest.formspec_escape(skin:get_preview())..";skins_set$"..i..";]"..
"tooltip[skins_set$"..i..";"..minetest.formspec_escape(skin:get_meta_string("name")).."]"
end

View File

@ -82,3 +82,13 @@ player_api.register_model("skinsdb_3d_armor_character_5.b3d", {
sit = {x=81, y=160},
},
})
-- Register default character.png if not part of this mod
local default_skin_obj = skins.get(skins.default)
if not default_skin_obj then
default_skin_obj = skins.new(skins.default)
default_skin_obj:set_texture("character.png")
default_skin_obj:set_meta("format", '1.0')
default_skin_obj:set_meta("_sort_id", 0)
default_skin_obj:set_meta("name", "Sam")
end

View File

@ -1,3 +0,0 @@
Sam 0
Jordach
CC BY-SA 3.0

View File

@ -56,7 +56,58 @@ function skin_class:set_preview(value)
end
function skin_class:get_preview()
return self._preview or "player.png"
if self._preview then
return self._preview
end
local player_skin = "("..self:get_texture()..")"
local skin = ""
-- Consistent on both sizes:
--Chest
skin = skin .. "([combine:16x32:-16,-12=" .. player_skin .. "^[mask:skindb_mask_chest.png)^"
--Head
skin = skin .. "([combine:16x32:-4,-8=" .. player_skin .. "^[mask:skindb_mask_head.png)^"
--Hat
skin = skin .. "([combine:16x32:-36,-8=" .. player_skin .. "^[mask:skindb_mask_head.png)^"
--Right Arm
skin = skin .. "([combine:16x32:-44,-12=" .. player_skin .. "^[mask:skindb_mask_rarm.png)^"
--Right Leg
skin = skin .. "([combine:16x32:0,0=" .. player_skin .. "^[mask:skindb_mask_rleg.png)^"
-- 64x skins have non-mirrored arms and legs
local left_arm
local left_leg
if self:get_meta("format") == "1.8" then
left_arm = "([combine:16x32:-24,-44=" .. player_skin .. "^[mask:(skindb_mask_rarm.png^[transformFX))^"
left_leg = "([combine:16x32:-12,-32=" .. player_skin .. "^[mask:(skindb_mask_rleg.png^[transformFX))^"
else
left_arm = "([combine:16x32:-44,-12=" .. player_skin .. "^[mask:skindb_mask_rarm.png^[transformFX)^"
left_leg = "([combine:16x32:0,0=" .. player_skin .. "^[mask:skindb_mask_rleg.png^[transformFX)^"
end
-- Left Arm
skin = skin .. left_arm
--Left Leg
skin = skin .. left_leg
-- Add overlays for 64x skins. these wont appear if skin is 32x because it will be cropped out
--Chest Overlay
skin = skin .. "([combine:16x32:-16,-28=" .. player_skin .. "^[mask:skindb_mask_chest.png)^"
--Right Arm Overlay
skin = skin .. "([combine:16x32:-44,-28=" .. player_skin .. "^[mask:skindb_mask_rarm.png)^"
--Right Leg Overlay
skin = skin .. "([combine:16x32:0,-16=" .. player_skin .. "^[mask:skindb_mask_rleg.png)^"
--Left Arm Overlay
skin = skin .. "([combine:16x32:-40,-44=" .. player_skin .. "^[mask:(skindb_mask_rarm.png^[transformFX))^"
--Left Leg Overlay
skin = skin .. "([combine:16x32:4,-32=" .. player_skin .. "^[mask:(skindb_mask_rleg.png^[transformFX))"
-- Full Preview
skin = "(((" .. skin .. ")^[resize:64x128)^[mask:skindb_transform.png)"
return skin
end
function skin_class:apply_skin_to_player(player)
@ -133,6 +184,6 @@ end
function skin_class:is_applicable_for_player(playername)
local assigned_player = self:get_meta("playername")
return assigned_player == nil or assigned_player == true or
return minetest.check_player_privs(playername, {server=true}) or assigned_player == nil or assigned_player == true or
(assigned_player:lower() == playername:lower())
end

View File

@ -1,9 +1,12 @@
local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
for _, fn in pairs(skins_dir_list) do
local name, sort_id, assignment, is_preview, playername
local nameparts = string.gsub(fn, "[.]", "_"):split("_")
local nameparts = {
fn:match("^%w+"),
fn:gsub("^%w+_", ""):gsub("%.%w+$", ""),
fn:match("%w+$"),
}
-- check allowed prefix and file extension
if (nameparts[1] == 'player' or nameparts[1] == 'character') and

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 673 B

View File

@ -7,6 +7,7 @@ One or multiple private skins for player "nick":
player_[nick].png or
player_[nick]_[number-or-name].png
Preview files for public and private skins:
Preview files for public and private skins.
Optional, overrides the generated preview
character_*_preview.png or
player_*_*_preview.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 B

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -12,6 +12,7 @@ unified_inventory.register_page("skins", {
unified_inventory.register_button("skins", {
type = "image",
image = "skins_button.png",
tooltip = "Skins",
})
local function get_formspec(player)