individual skins and preview functions depending on model and npc

This commit is contained in:
Sokomine 2022-07-20 21:57:33 +02:00
parent 0a52637271
commit fe4eb48822
4 changed files with 120 additions and 27 deletions

View File

@ -24,12 +24,12 @@ yl_speak_up.talk_after_spawn = true
-- diffrent NPC may use diffrent models
-- IMPORTANT: If you want to support an NPC with a diffrent model, provide
-- an entry in this array! Else setting its skin will fail horribly.
-- TODO: provide function for preview image
yl_speak_up.mesh_data = {}
yl_speak_up.mesh_data["error"] = {
texture_index = 1,
-- TODO: actually handle that and call the right formspec
can_show_wielded_items = false,
skin_preview = yl_speak_up.skin_preview_normal,
}
-- this model is used by mobs_npc
yl_speak_up.mesh_data["mobs_character.b3d"] = {
@ -37,16 +37,36 @@ yl_speak_up.mesh_data["mobs_character.b3d"] = {
texture_index = 1,
-- there is no support for capes or wielded items
can_show_wielded_items = false,
-- which function can be used to draw the skin?
skin_preview = yl_speak_up.skin_preview_normal,
}
yl_speak_up.mesh_data["skinsdb_3d_armor_character_5.b3d"] = {
-- the second texture is the skin
texture_index = 2,
-- they can wear and show capes and wield items
can_show_wielded_items = true,
-- this model needs its own preview function
skin_preview = yl_speak_up.skin_preview_skinsdb_3d_armor_character_5,
}
-- TODO: provide skin texture list for the diffrent NPC (self.name)
-- diffrent mob types may want to wear diffrent skins - even if they share the
-- same model/mesh
yl_speak_up.mob_skins = {}
-- mobs_redo usually uses 64 x 32 textures:
yl_speak_up.mob_skins["mobs_npc:npc"] = {
"mobs_npc.png", "mobs_npc2.png", "mobs_npc3.png", "mobs_npc4.png", "mobs_npc_baby.png"}
yl_speak_up.mob_skins["mobs_npc:igor"] = {
"mobs_igor.png", "mobs_igor2.png", "mobs_igor3.png", "mobs_igor4.png",
"mobs_igor5.png", "mobs_igor6.png", "mobs_igor7.png", "mobs_igor8.png"}
yl_speak_up.mob_skins["mobs_npc:trader"] = {
"mobs_trader.png", "mobs_trader2.png", "mobs_trader3.png"}
-- this here uses 64 x 64 textures:
yl_speak_up.mob_skins["yl_speak_up:human"] = {
"yl_speak_up_main_default.png"}
-- some properties from external NPC can be edited and changed (they have the self. prefix),

View File

@ -20,6 +20,25 @@ yl_speak_up.get_mesh = function(pname)
end
-- diffrent mobs (distinguished by self.name) may want to wear diffrent skins
-- even if they share the same model; find out which mob we're dealing with
yl_speak_up.get_mob_type = function(pname)
if(not(pname)) then
return "error"
end
local obj = yl_speak_up.speak_to[pname].obj
if(not(obj)) then
return "error"
end
local entity = obj:get_luaentity()
if(not(entity)) then
return "error"
end
return entity.name
end
local function cape2texture(t)
return "yl_speak_up_mask_cape.png^[combine:32x64:56,20=" .. t
end
@ -145,6 +164,8 @@ local function get_npc_capes(cape)
return rettable, retstring, retindex
end
-- TODO: this function is now kind of obsolete
local function create_preview(main_skin)
if main_skin == nil or main_skin == "" then
main_skin = "default_greyscale.png"
@ -190,6 +211,7 @@ local function create_preview(main_skin)
return skin
end
-- TODO: link that somehow for NPC that support it
yl_speak_up.get_fs_fashion_extended = function(pname)
local textures = yl_speak_up.speak_to[pname].textures
@ -301,15 +323,15 @@ yl_speak_up.input_fashion = function(player, formname, fields)
return
end
-- TODO: get that list from somewhere
local skins = {"mobs_npc.png", "mobs_npc2.png", "mobs_npc3.png", "mobs_npc4.png",
"mobs_npc_baby.png"}
local mesh = yl_speak_up.get_mesh(pname)
-- which texture from the textures list are we talking about?
-- this depends on the model!
local mesh = yl_speak_up.get_mesh(pname)
local texture_index = yl_speak_up.mesh_data[mesh].texture_index
-- which skins are available? this depends on mob_type
local mob_type = yl_speak_up.get_mob_type(pname)
local skins = yl_speak_up.mob_skins[mob_type]
local textures = yl_speak_up.speak_to[pname].textures
local skin = (textures[texture_index] or "")
local skin_index = table.indexof(skins, skin)
@ -516,16 +538,15 @@ end
-- capes and wielded items are supported by an extended formspec for those
-- NPC that can handle them
yl_speak_up.get_fs_fashion = function(pname)
-- TODO: get that list from somewhere (it may depend on the model...)
local skins = {"mobs_npc.png", "mobs_npc2.png", "mobs_npc3.png", "mobs_npc4.png",
"mobs_npc_baby.png"}
local mesh = yl_speak_up.get_mesh(pname)
-- which texture from the textures list are we talking about?
-- this depends on the model!
local mesh = yl_speak_up.get_mesh(pname)
local texture_index = yl_speak_up.mesh_data[mesh].texture_index
-- which skins are available? this depends on mob_type
local mob_type = yl_speak_up.get_mob_type(pname)
local skins = yl_speak_up.mob_skins[mob_type]
local textures = yl_speak_up.speak_to[pname].textures
local skin = (textures[texture_index] or "")
-- store the old texture so that we can go back to it
@ -548,20 +569,7 @@ yl_speak_up.get_fs_fashion = function(pname)
skin_index = ""
end
-- TODO: the preview depends on the model as well
local preview =
"image[4.5,1.8;3,3;[combine:8x9:-8,-9="..skin..":-40,-9="..skin.."]".. -- head, beard
"image[4.5,4.12;3,4.5;[combine:8x12:-20,-20="..skin.."]".. -- body
"image[4.5,8.02;1.5,4.5;[combine:4x12:-4,-20="..skin.."]".. -- left leg
"image[5.73,8.02;1.5,4.5;[combine:4x12:-4,-20="..skin.."^[transformFX]".. -- right leg
"image[3.15,4.12;1.5,4.5;[combine:4x12:-44,-20="..skin.."]".. -- left hand
"image[7.35,4.12;1.5,4.5;[combine:4x12:-44,-20="..skin.."^[transformFX]".. -- right hand
"image[10.5,1.8;3,3;[combine:8x8:-24,-8="..skin.."]".. -- back head
"image[10.5,4.12;3,4.5;[combine:8x12:-32,-20="..skin.."]".. -- body back
"image[10.5,8.02;1.5,4.5;[combine:4x12:-12,-20="..skin.."]".. -- left leg back
"image[11.73,8.02;1.5,4.5;[combine:4x12:-12,-20="..skin.."^[transformFX]".. -- right leg back
"image[9.3,4.12;1.5,4.5;[combine:4x12:-52,-20="..skin.."]".. -- left hand back
"image[12.95,4.12;1.5,4.5;[combine:4x12:-52,-20="..skin.."^[transformFX]" -- right hand back
local preview = yl_speak_up.mesh_data[mesh].skin_preview(skin)
local formspec = {
"container[0.5,4.0]",

View File

@ -26,6 +26,9 @@ yl_speak_up.fs_version = {}
yl_speak_up.custom_server_functions = {}
-- this file defines preview functions for skins - which are needed in config.lua
-- (skin preview depends on model)
dofile(modpath .. "skin_preview.lua")
-- the server-specific configuration
dofile(modpath .. "config.lua")
-- players *and* npc need privs for certain things

62
skin_preview.lua Normal file
View File

@ -0,0 +1,62 @@
-- this file contains the preview images for the skins of the NPC;
-- it does depend on the model used
-- this is a suitable version for most models/meshes that use normal player skins
-- (i.e. mobs_redo)
yl_speak_up.skin_preview_normal = function(skin)
return "image[4.5,1.8;3,3;[combine:8x9:-8,-9="..skin..":-40,-9="..skin.."]".. -- head, beard
"image[4.5,4.12;3,4.5;[combine:8x12:-20,-20="..skin.."]".. -- body
"image[4.5,8.02;1.5,4.5;[combine:4x12:-4,-20="..skin.."]".. -- left leg
"image[5.73,8.02;1.5,4.5;[combine:4x12:-4,-20="..skin.."^[transformFX]".. -- right leg
"image[3.15,4.12;1.5,4.5;[combine:4x12:-44,-20="..skin.."]".. -- left hand
"image[7.35,4.12;1.5,4.5;[combine:4x12:-44,-20="..skin.."^[transformFX]".. -- right hand
"image[10.5,1.8;3,3;[combine:8x8:-24,-8="..skin.."]".. -- back head
"image[10.5,4.12;3,4.5;[combine:8x12:-32,-20="..skin.."]".. -- body back
"image[10.5,8.02;1.5,4.5;[combine:4x12:-12,-20="..skin.."]".. -- left leg back
"image[11.73,8.02;1.5,4.5;[combine:4x12:-12,-20="..skin.."^[transformFX]".. -- right leg back
"image[9.3,4.12;1.5,4.5;[combine:4x12:-52,-20="..skin.."]".. -- left hand back
"image[12.95,4.12;1.5,4.5;[combine:4x12:-52,-20="..skin.."^[transformFX]" -- right hand back
end
-- this is a version for the yl_speak_up mobs
yl_speak_up.skin_preview_skinsdb_3d_armor_character_5 = function(main_skin)
if main_skin == nil or main_skin == "" then
main_skin = "default_greyscale.png"
end
local player_skin = "(" .. main_skin .. ")"
local skin = -- Consistent on both sizes:
--Chest
"([combine:16x32:-16,-12="..player_skin.."^[mask:yl_speak_up_mask_chest.png)^"..
--Head
"([combine:16x32:-4,-8="..player_skin.."^[mask:yl_speak_up_mask_head.png)^"..
--Hat
"([combine:16x32:-36,-8="..player_skin.."^[mask:yl_speak_up_mask_head.png)^"..
--Right Arm
"([combine:16x32:-44,-12="..player_skin.."^[mask:yl_speak_up_mask_rarm.png)^"..
--Right Leg
"([combine:16x32:0,0="..player_skin.."^[mask:yl_speak_up_mask_rleg.png)^"..
-- Left Arm
"([combine:16x32:-24,-44="..player_skin.."^[mask:(yl_speak_up_mask_rarm.png^[transformFX))^"..
--Left Leg
"([combine:16x32:-12,-32="..player_skin.."^[mask:(yl_speak_up_mask_rleg.png^[transformFX))^"..
-- Add overlays for 64x skins. these wont appear if skin is 32x because it will be cropped out
--Chest Overlay
"([combine:16x32:-16,-28="..player_skin.."^[mask:yl_speak_up_mask_chest.png)^"..
--Right Arm Overlay
"([combine:16x32:-44,-28="..player_skin.."^[mask:yl_speak_up_mask_rarm.png)^"..
--Right Leg Overlay
"([combine:16x32:0,-16="..player_skin.."^[mask:yl_speak_up_mask_rleg.png)^"..
--Left Arm Overlay
"([combine:16x32:-40,-44="..player_skin.."^[mask:(yl_speak_up_mask_rarm.png^[transformFX))^"..
--Left Leg Overlay
"([combine:16x32:4,-32="..player_skin.."^[mask:(yl_speak_up_mask_rleg.png^[transformFX))"
-- Full Preview
skin = "((("..skin..")^[resize:64x128)^[mask:yl_speak_up_transform.png)"
return "image[4.5,1.8;9,10.5;"..skin.."]"
end