Browse Source

Autogenerate skin previews and other @GreenDimond changes

pull/46/head
GreenDimond bell07 1 year ago
parent
commit
918df53f3b
17 changed files with 77 additions and 11 deletions
  1. +6
    -3
      formspecs.lua
  2. +10
    -0
      init.lua
  3. +0
    -3
      meta/character.txt
  4. +53
    -2
      skin_meta_api.lua
  5. +5
    -2
      skinlist.lua
  6. BIN
      textures/character.png
  7. BIN
      textures/character_preview.png
  8. BIN
      textures/inventory_plus_skins.png
  9. +2
    -1
      textures/readme.txt
  10. BIN
      textures/skindb_mask_chest.png
  11. BIN
      textures/skindb_mask_head.png
  12. BIN
      textures/skindb_mask_rarm.png
  13. BIN
      textures/skindb_mask_rleg.png
  14. BIN
      textures/skindb_transform.png
  15. BIN
      textures/skins_button.png
  16. BIN
      textures/ui_misc_form.png
  17. +1
    -0
      unified_inventory_page.lua

+ 6
- 3
formspecs.lua 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



+ 10
- 0
init.lua 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

+ 0
- 3
meta/character.txt View File

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

+ 53
- 2
skin_meta_api.lua 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

+ 5
- 2
skinlist.lua 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


BIN
textures/character.png View File

Before After
Width: 64  |  Height: 32  |  Size: 1.6KB

BIN
textures/character_preview.png View File

Before After
Width: 16  |  Height: 32  |  Size: 604B

BIN
textures/inventory_plus_skins.png View File

Before After
Width: 16  |  Height: 16  |  Size: 673B

+ 2
- 1
textures/readme.txt 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

BIN
textures/skindb_mask_chest.png View File

Before After
Width: 16  |  Height: 32  |  Size: 114B

BIN
textures/skindb_mask_head.png View File

Before After
Width: 16  |  Height: 32  |  Size: 139B

BIN
textures/skindb_mask_rarm.png View File

Before After
Width: 16  |  Height: 32  |  Size: 118B

BIN
textures/skindb_mask_rleg.png View File

Before After
Width: 16  |  Height: 32  |  Size: 118B

BIN
textures/skindb_transform.png View File

Before After
Width: 64  |  Height: 128  |  Size: 191B

BIN
textures/skins_button.png View File

Before After
Width: 32  |  Height: 32  |  Size: 309B Width: 10  |  Height: 10  |  Size: 250B

BIN
textures/ui_misc_form.png View File

Before After
Width: 712  |  Height: 623  |  Size: 5.3KB Width: 712  |  Height: 623  |  Size: 6.0KB

+ 1
- 0
unified_inventory_page.lua 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)


Loading…
Cancel
Save