Change skins engine to simple_skins

master
Tre 2017-10-31 10:02:17 -05:00
parent e4364414b6
commit 9302d8c41c
696 changed files with 545 additions and 887 deletions

4
mods/simple_skins/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*~
.previews/output
.previews/blender_out
.previews/pngcrush_output

View File

@ -0,0 +1,6 @@
default
inventory_plus?
3d_armor?
intllib?
sfinv?
unified_inventory?

View File

@ -0,0 +1 @@
Mod that allows players to set their individual skins.

296
mods/simple_skins/init.lua Normal file
View File

@ -0,0 +1,296 @@
-- Simple Skins mod for minetest (29th September 2017)
-- Adds a simple skin selector to the inventory by using
-- the default sfinv or inventory_plus when running.
-- Released by TenPlus1 and based on Zeg9's code under MIT license
skins = {}
skins.skins = {}
skins.modpath = minetest.get_modpath("simple_skins")
skins.invplus = minetest.get_modpath("inventory_plus")
skins.sfinv = minetest.get_modpath("sfinv")
skins.ui = minetest.get_modpath("unified_inventory")
-- Load support for intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
-- load skin list
skins.list = {}
skins.add = function(skin)
table.insert(skins.list, skin)
end
local id = 1
local f
while true do
f = io.open(skins.modpath .. "/textures/character_" .. id .. ".png")
if not f then break end
if id>31 then break end
f:close()
skins.add("character_" .. id)
id = id + 1
end
id = id - 1
-- load Metadata
skins.meta = {}
local f, data
for _, i in pairs(skins.list) do
skins.meta[i] = {}
f = io.open(skins.modpath .. "/meta/" .. i .. ".txt")
data = nil
if f then
data = minetest.deserialize("return {" .. f:read('*all') .. "}")
f:close()
end
data = data or {}
skins.meta[i].name = data.name or ""
skins.meta[i].author = data.author or ""
end
-- player load/save routines
skins.file = minetest.get_worldpath() .. "/simple_skins.mt"
skins.load = function()
local input = io.open(skins.file, "r")
local data = nil
if input then
data = input:read('*all')
end
if data and data ~= "" then
local lines = string.split(data, "\n")
for _, line in pairs(lines) do
data = string.split(line, ' ', 2)
skins.skins[data[1]] = data[2]
end
io.close(input)
end
end
-- load player skins now for backwards compatibility
skins.load()
-- skin selection page
skins.formspec = {}
skins.formspec.main = function(name)
local formspec = ""
if skins.invplus or skins.ui then
formspec = "size[8,8.6]"
.. "bgcolor[#08080822;true]"
end
formspec = formspec .. "label[.5,2;" .. S("Select Player Skin:") .. "]"
.. "textlist[.5,2.5;6.8,6;skins_set;"
local meta
local selected = 1
for i = 1, #skins.list do
formspec = formspec .. skins.meta[ skins.list[i] ].name .. ","
if skins.skins[name] == skins.list[i] then
selected = i
meta = skins.meta[ skins.skins[name] ]
end
end
if skins.invplus then
formspec = formspec .. ";" .. selected .. ";true]"
else
formspec = formspec .. ";" .. selected .. ";false]"
end
if meta then
if meta.name then
formspec = formspec .. "label[2,.5;" .. S("Name: ") .. meta.name .. "]"
end
if meta.author then
formspec = formspec .. "label[2,1;" .. S("Author: ") .. meta.author .. "]"
end
end
return formspec
end
-- update player skin
skins.update_player_skin = function(player)
if not player then
return
end
local name = player:get_player_name()
player:set_properties({
textures = {skins.skins[name] .. ".png"},
})
if skins.skins[name] ~= "character_1" then
player:set_attribute("simple_skins:skin", skins.skins[name])
end
end
unified_inventory.register_page("skins:skins", {
title = "Skins",
get_formspec = function(player, context)
local name = player:get_player_name()
return {formspec=skins.formspec.main(name)}
end,
})
minetest.register_on_player_receive_fields(function(player, context, fields)
local name = player:get_player_name()
local event = minetest.explode_textlist_event(fields["skins_set"])
if event.type == "CHG" then
local index = event.index
if index > id then index = id end
skins.skins[name] = skins.list[index]
skins.update_player_skin(player)
unified_inventory.set_inventory_formspec(player,"skins:skins")
end
end)
unified_inventory.register_button("skins:skins",{
type = "image",
image = "inventory_plus_skins.png",
})
-- register sfinv tab when inv+ not active
if skins.sfinv and not skins.invplus then
sfinv.register_page("skins:skins", {
title = "Skins",
get = function(self, player, context)
local name = player:get_player_name()
return sfinv.make_formspec(player, context,skins.formspec.main(name))
end,
on_player_receive_fields = function(self, player, context, fields)
local name = player:get_player_name()
local event = minetest.explode_textlist_event(fields["skins_set"])
if event.type == "CHG" then
local index = event.index
if index > id then index = id end
skins.skins[name] = skins.list[index]
skins.update_player_skin(player)
sfinv.override_page("skins:skins", {
get = function(self, player, context)
local name = player:get_player_name()
return sfinv.make_formspec(player, context,
skins.formspec.main(name))
end,
})
sfinv.set_player_inventory_formspec(player)
end
end,
})
end
-- load player skin on join
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
-- do we already have a skin in player attributes?
local skin = player:get_attribute("simple_skins:skin")
if skin then
skins.skins[name] = skin
end
-- no skin found? ok we use default
if not skins.skins[name] then
skins.skins[name] = "character_1"
end
skins.update_player_skin(player)
if skins.invplus then
inventory_plus.register_button(player,"skins", "Skin")
end
end)
-- formspec control for inventory_plus
minetest.register_on_player_receive_fields(function(player, formname, fields)
if skins.sfinv and not skins.invplus then
return
end
local name = player:get_player_name()
if fields.skins then
inventory_plus.set_inventory_formspec(player,
skins.formspec.main(name) .. "button[0,.75;2,.5;main;Back]")
end
local event = minetest.explode_textlist_event(fields["skins_set"])
if event.type == "CHG" then
local index = event.index
if index > id then index = id end
skins.skins[name] = skins.list[index]
if skins.invplus then
inventory_plus.set_inventory_formspec(player,
skins.formspec.main(name) .. "button[0,.75;2,.5;main;Back]")
end
skins.update_player_skin(player)
end
end)
-- admin command to set player skin (usually for custom skins)
minetest.register_chatcommand("setskin", {
params = "<player> <skin number>",
description = S("Admin command to set player skin"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then return end
local user, skin = string.match(param, "([^ ]+) (-?%d+)")
if not user or not skin then return end
skins.skins[user] = "character_"..tonumber(skin)
skins.update_player_skin(minetest.get_player_by_name(name))
minetest.chat_send_player(name,
"** " .. user .. S("'s skin set to") .. " character_" .. skin .. ".png")
end,
})
print (S("[MOD] Simple Skins loaded"))

View File

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 TenPlus1
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,51 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-29 07:11+0200\n"
"PO-Revision-Date: 2017-07-29 07:17+0200\n"
"Last-Translator: fat115 <fat115@framasoft.org>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.12\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: init.lua
msgid "Select Player Skin:"
msgstr "Sélectionner l'apparence du joueur :"
#: init.lua
msgid "Name: "
msgstr "Nom : "
#: init.lua
msgid "Author: "
msgstr "Auteur : "
#: init.lua
msgid "Admin command to set player skin"
msgstr "Commande admin pour définir l'apparence du joueur"
#: init.lua
msgid "'s skin set to"
msgstr ", apparence définie pour"
#: init.lua
msgid "Set player skin"
msgstr "Définir l'apparence du joueur"
#: init.lua
msgid "Close"
msgstr "Fermer"
#: init.lua
msgid "[MOD] Simple Skins loaded"
msgstr "[MOD] Simple Skins chargé"

View File

@ -0,0 +1,50 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-29 07:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: init.lua
msgid "Select Player Skin:"
msgstr ""
#: init.lua
msgid "Name: "
msgstr ""
#: init.lua
msgid "Author: "
msgstr ""
#: init.lua
msgid "Admin command to set player skin"
msgstr ""
#: init.lua
msgid "'s skin set to"
msgstr ""
#: init.lua
msgid "Set player skin"
msgstr ""
#: init.lua
msgid "Close"
msgstr ""
#: init.lua
msgid "[MOD] Simple Skins loaded"
msgstr ""

View File

@ -0,0 +1,4 @@
name = "Sam",
author = "Jordach",
description = "The default skin.",
comment = "Sam Ain't Minecraft",

View File

@ -0,0 +1,2 @@
name = "Assassin",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Harry",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Bob",
author = "Chinchow",

View File

@ -0,0 +1,2 @@
name = "Jannette",
author = "Chinchow",

View File

@ -0,0 +1,2 @@
name = "Sheriff",
author = "Chinchow",

View File

@ -0,0 +1,2 @@
name = "Sepia Sam",
author = "Hybrid Dog",

View File

@ -0,0 +1,2 @@
name = "Hybrid Sam",
author = "Hybrid Dog",

View File

@ -0,0 +1,2 @@
name = "Original Sam",
author = "Jordach",

View File

@ -0,0 +1,2 @@
name = "Unnamed",
author = "Hybrid Dog",

View File

@ -0,0 +1,3 @@
name = "VanessaE",
author = "Jordach",
comment = "Actually based from an old picture",

View File

@ -1,3 +1,3 @@
name = "Zeg9",
author = "Zeg9",
comment = "CC BY-SA 3.0",
description = "My own skin.",

View File

@ -1,3 +1,2 @@
name = "Female Sam",
author = "Jordach",
comment = "CC BY-NC-SA 3.0",

View File

@ -0,0 +1,2 @@
name = "Battlefield 3 Soldier",
author = "Jordach",

View File

@ -0,0 +1,2 @@
name = "Smooth Sam",
author = "Jordach",

View File

@ -0,0 +1,3 @@
name = "Celeron55",
author = "Jordach",
comment = "Based on a picture from the wiki.",

View File

@ -1,3 +1,2 @@
name = "Tuxedo Sam",
author = "Jordach",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +1,2 @@
name = "Iron Man MK. 7",
author = "Jordach",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +1,2 @@
name = "Jordach",
author = "Jordach",
comment = "CC BY-NC-SA 3.0",

View File

@ -0,0 +1,2 @@
name = "Max",
author = "Stuart Jones",

View File

@ -0,0 +1,2 @@
name = "Slenderman",
author = "prof_turbo",

View File

@ -0,0 +1,2 @@
name = "Strange Killer",
author = "prof_turbo",

View File

@ -1,3 +1,2 @@
name = "Alien",
author = "jmf",
comment = "CC BY-SA 3.0",

View File

@ -1,3 +1,2 @@
name = "jojoa1997",
author = "jojoa1997",
comment = "CC BY-SA 3.0",

View File

@ -0,0 +1,2 @@
name = "DrakeOfDuty",
author = "jmfApprentice Prince",

View File

@ -0,0 +1,2 @@
name = "Soldier",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "John",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Ninja",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Oerkki",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Tux",
author = "jmf",

View File

@ -0,0 +1,2 @@
name = "Black belt",
author = "jmf",

View File

@ -0,0 +1 @@
name = simple_skins

View File

@ -0,0 +1,16 @@
Simple Skins
Simple Skins mod for Minetest uses SfInv or Inventory Plus mods when available
to allow players to select a skin/texture from the list.
https://forum.minetest.net/viewtopic.php?id=9100
Change log:
- 0.6 - Updated to use Minetest 0.4.16 functions
- 0.5 - Added compatibility with default sfinv inventory, disabled /skin command for now
- 0.4 - Added /skin command to set player skin, no longer dependent on Inventory+, also /setskin command for server admin to set custom skins for player.
- 0.3 - Now works with Minetest 0.4.10+
- 0.2 - Added 3D_Armor mod compatibility
- 0.1 - Added addi's changes to highlight selected skin on list (thanks)
- 0.0 - Initial release

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

View File

Before

Width:  |  Height:  |  Size: 338 B

After

Width:  |  Height:  |  Size: 338 B

View File

@ -0,0 +1 @@
Vlad 32

View File

@ -1 +0,0 @@
generate_previews.sh: 45: generate_previews.sh: pngcrush: not found

View File

@ -1,20 +0,0 @@
minetest-u_skins
================
Skins mod for minetest unified_inventory by Dean Montgomery - feel free to merge it into skinsdb or unified_inventory git.
Requires latest unified_inventory from:
https://github.com/minetest-technic/unified_inventory
This is the "u_skindb" branch, it is ment to download the skins from addi's skin database (http://minetest.fensta.bplaced.net).
To re-download the latest skins you may want to run:
"./update_from_db.py" OR
"./update_from_db2.py"
script, then "./generate_previews.sh" before using the mod.
Credits:
MirceaKitsune (WTFPL) + bundled script by Zeg9 (WTFPL too):
skin_previews.blend
RealyBadAngel unified_inventory and Zeg9 skinsdb

View File

@ -1,48 +0,0 @@
#!/bin/sh
# This script is used to generate the previews needed by the mod
# It requires blender with the latest python API (2.6x is tested)
# A script that works with older blenders and, maybe, without python, is available in older commits.
# This script can also use pngcrush and imagemagick to reduce output size,
# please enable them if you want to push to the git repository of the mod.
# Pngcrush output will be written to .previews/pngcrush_output
# Warning: any file in .previews/ and u_skins/textures might be deleted without asking.
PNGCRUSH=true
IMAGEMAGICK=true
cd .previews
rm ../u_skins/textures/*_preview*.png # Remove all previous previews
/home/caleb/Blender/blender2.69/blender -b skin_previews.blend --python-text "Generate previews" > /dev/null
if $IMAGEMAGICK
then echo "Stripping metadata from generated files..."
else echo "Moving files..."
fi
rm -rf output # remove my output
mkdir -p output
for i in blender_out/character_*_00.png;
do
out_name=$(basename $i | sed -e 's/_00.png//g')
out_file=output/"$out_name"_preview.png
if $IMAGEMAGICK
then
convert -strip $i $out_file
else
mv $i $out_file
fi
done
for i in blender_out/character_*_01.png;
do
out_name=$(basename $i | sed -e 's/_01.png//g')
out_file=output/"$out_name"_preview_back.png
if $IMAGEMAGICK
then
convert -strip $i $out_file
else
mv $i $out_file
fi
done
if $PNGCRUSH
then
echo "Running pngcrush..."
pngcrush -d ../u_skins/textures/ output/*_preview*.png 2> pngcrush_output
else mv output/*_preview*.png ../u_skins/textures/
fi
echo "Done !"

View File

@ -1,59 +0,0 @@
#!/bin/bash
SPRITES=$(find -regextype sed -regex '.*/player_[0-9]\{1,\}.png' | sort -V)
MODELS=$(find -regextype sed -regex '.*/character_[0-9]\{1,\}.png' | sort -V)
function ask_for_meta {
convert $2 -scale 100x200 /tmp/skins_set_meta
SNAME=$(basename $1)
SNAME=${SNAME%.*}
METAFILE=u_skins/meta/$SNAME.txt
FORCE=$3
if $FORCE || ! [ -f $METAFILE ]
then
echo $METAFILE
YADOUT=$(yad --form --image=/tmp/skins_set_meta --field $SNAME:LBL --field=Name --field=Author --field=Description --field=Comment)
if [ -z "$YADOUT" ]; then exit; fi # canceled
OIFS="$IFS"
IFS='|'
read -a VALUES <<< "$YADOUT"
IFS="$OIFS"
NAME=${VALUES[1]}
AUTHOR=${VALUES[2]}
DESCRIPTION=${VALUES[3]}
COMMENT=${VALUES[4]}
if [ -n "$NAME" ] && [ -n "$AUTHOR" ]
then
echo -n > $METAFILE # clear it
echo 'name = "'$NAME'",' >> $METAFILE
echo 'author = "'$AUTHOR'",' >> $METAFILE
# only write description and comment if they are specified
if [ -n "$DESCRIPTION" ]
then
echo 'description = "'$DESCRIPTION'",' >> $METAFILE
fi
if [ -n "$COMMENT" ]
then
echo 'comment = "'$COMMENT'",' >> $METAFILE
fi
echo "Saved !"
fi
fi
}
if [ -z $1 ]
then
for i in $SPRITES
do
ask_for_meta $i $i false
done
for i in $MODELS
do
ask_for_meta $i ${i%.*}_preview.png false
done
else
if [ -f ${1%.*}_preview.png ]
then
ask_for_meta $1 ${1%.*}_preview.png true
else
ask_for_meta $1 $1 true
fi
fi
rm /tmp/skins_set_meta

View File

@ -1,2 +0,0 @@
unified_inventory?
default

View File

@ -1,151 +0,0 @@
-- Unified Skins for Minetest - based modified Bags from unfied_inventory and skins from inventory_plus
-- Copyright (c) 2012 cornernote, Dean Montgomery
-- License: GPLv3
u_skins = {}
u_skins.type = { SPRITE=0, MODEL=1 }
u_skins.pages = {}
u_skins.u_skins = {}
u_skins.get_type = function(texture)
if not texture then return end
if string.sub(texture,0,string.len("character")) == "character" then
return u_skins.type.MODEL
end
if string.sub(texture,0,string.len("player")) == "player" then
return u_skins.type.SPRITE
end
end
u_skins.modpath = minetest.get_modpath("u_skins")
dofile(u_skins.modpath.."/skinlist.lua")
dofile(u_skins.modpath.."/meta.lua")
dofile(u_skins.modpath.."/players.lua")
u_skins.update_player_skin = function(player)
local name = player:get_player_name()
if u_skins.get_type(u_skins.u_skins[name]) == u_skins.type.SPRITE then
player:set_properties({
visual = "upright_sprite",
textures = {u_skins.u_skins[name]..".png",u_skins.u_skins[name].."_back.png"},
visual_size = {x=1, y=2},
})
elseif u_skins.get_type(u_skins.u_skins[name]) == u_skins.type.MODEL then
player:set_properties({
visual = "mesh",
textures = {u_skins.u_skins[name]..".png"},
visual_size = {x=1, y=1},
})
end
u_skins.save()
end
-- Display Current Skin
unified_inventory.register_page("u_skins", {
get_formspec = function(player)
local name = player:get_player_name()
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"
if u_skins.get_type(u_skins.u_skins[name]) == u_skins.type.MODEL then
formspec = formspec
.. "image[0,.75;1,2;"..u_skins.u_skins[name].."_preview.png]"
.. "image[1,.75;1,2;"..u_skins.u_skins[name].."_preview_back.png]"
.. "label[6,.5;Raw texture:]"
.. "image[6,1;2,1;"..u_skins.u_skins[name]..".png]"
else
formspec = formspec
.. "image[0,.75;1,2;"..u_skins.u_skins[name]..".png]"
.. "image[1,.75;1,2;"..u_skins.u_skins[name].."_back.png]"
end
local meta = u_skins.meta[u_skins.u_skins[name]]
if meta then
if meta.name then
formspec = formspec .. "label[2,.5;Name: "..meta.name.."]"
end
if meta.author then
formspec = formspec .. "label[2,1;Author: "..meta.author.."]"
end
if meta.description then
formspec = formspec .. "label[2,1.5;"..meta.description.."]"
end
if meta.comment then
formspec = formspec .. 'label[2,2;"'..meta.comment..'"]'
end
end
formspec = formspec .. "button[.75,3;6.5,.5;u_skins_page_0;Change]"
return {formspec=formspec}
end,
})
unified_inventory.register_button("u_skins", {
type = "image",
image = "u_skins_button.png",
})
-- Create all of the skin-picker pages.
for x = 0, math.floor(#u_skins.list/16+1) do
unified_inventory.register_page("u_skins_page_"..x, {
get_formspec = function(player)
local page = u_skins.pages[player:get_player_name()]
if page == nil then page = 0 end
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"
local index = 0
local skip = 0 -- Skip u_skins, used for pages
-- skin thumbnails
for i, skin in ipairs(u_skins.list) do
if skip < page*16 then skip = skip + 1 else
if index < 16 then
formspec = formspec .. "image_button["..(index%8)..","..((math.floor(index/8))*2)..";1,2;"..skin
if u_skins.get_type(skin) == u_skins.type.MODEL then
formspec = formspec .. "_preview"
end
formspec = formspec .. ".png;u_skins_set_"..i..";]"
end
index = index +1
end
end
-- prev next page buttons
if page > 0 then
formspec = formspec .. "button[0,4;1,.5;u_skins_page_"..(page-1)..";<<]"
else
formspec = formspec .. "button[0,4;1,.5;u_skins_page_"..page..";<<]"
end
formspec = formspec .. "button[.75,4;6.5,.5;u_skins_page_"..page..";Page "..(page+1).."/"..math.floor(#u_skins.list/16+1).."]" -- a button is used so text is centered
if index > 16 then
formspec = formspec .. "button[7,4;1,.5;u_skins_page_"..(page+1)..";>>]"
else
formspec = formspec .. "button[7,4;1,.5;u_skins_page_"..page..";>>]"
end
return {formspec=formspec}
end,
})
end
-- click button handlers
minetest.register_on_player_receive_fields(function(player,formname,fields)
if fields.u_skins then
unified_inventory.set_inventory_formspec(player,"craft")
end
for field, _ in pairs(fields) do
if string.sub(field,0,string.len("u_skins_set_")) == "u_skins_set_" then
u_skins.u_skins[player:get_player_name()] = u_skins.list[tonumber(string.sub(field,string.len("u_skins_set_")+1))]
u_skins.update_player_skin(player)
unified_inventory.set_inventory_formspec(player,"u_skins")
end
if string.sub(field,0,string.len("u_skins_page_")) == "u_skins_page_" then
u_skins.pages[player:get_player_name()] = tonumber(string.sub(field,string.len("u_skins_page_")+1))
unified_inventory.set_inventory_formspec(player,"u_skins_page_"..u_skins.pages[player:get_player_name()])
end
end
end)
-- set defaults
minetest.register_on_joinplayer(function(player)
if not u_skins.u_skins[player:get_player_name()] then
u_skins.u_skins[player:get_player_name()] = "character_1"
end
u_skins.update_player_skin(player)
end)

View File

@ -1,15 +0,0 @@
u_skins.meta = {}
for _, i in ipairs(u_skins.list) do
u_skins.meta[i] = {}
local f = io.open(u_skins.modpath.."/meta/"..i..".txt")
local data = nil
if f then
data = minetest.deserialize("return {"..f:read('*all').."}")
f:close()
end
data = data or {}
u_skins.meta[i].name = data.name or ""
u_skins.meta[i].author = data.author or ""
u_skins.meta[i].description = data.description or nil
u_skins.meta[i].comment = data.comment or nil
end

View File

@ -1,3 +0,0 @@
name = "Sam 0",
author = "Jordach",
comment = "CC BY-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Ladyvioletkitty",
author = "lordphoenixmh",
comment = "CC BY 4.0",

View File

@ -1,3 +0,0 @@
name = "4&deg;district",
author = "Ferdi Napoli",
comment = "CC BY-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Chop",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Franklin",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Trevor",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Bart Simpson",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Creeper",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "War Machine",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Gangnam Style",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Sonic The Hedgehog",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Semmett9",
author = "Infinatum",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Charizard",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Scarlet Spider-man",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

View File

@ -1,3 +0,0 @@
name = "Ferdi Napoli",
author = "Ferdi Napoli",
comment = "CC BY-NC-SA 3.0",

Some files were not shown because too many files have changed in this diff Show More