Added custom skins mod

This commit is contained in:
Billy S 2018-12-25 21:09:24 -05:00
parent 8aa1f80bd2
commit 9d7f5e6cbd
284 changed files with 214 additions and 0 deletions

View File

@ -0,0 +1,2 @@
inventory_plus
3d_armor

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

@ -0,0 +1,122 @@
skins = {}
skins.skins = {}
skins.skin_path = minetest.get_modpath("simple_skins").."/textures/"
skins.pages = {}
local storage = minetest.get_mod_storage()
local playersStr = storage:get_string("players")
if playersStr == "" then
skins.players = {}
else
skins.players = minetest.deserialize(playersStr)
end
skins.save = function()
local pStr = minetest.serialize(skins.players)
storage:set_string("players", pStr)
end
skins.add = function(skinNum)
skins.skins[skinNum] = {
texture = "texture_" .. skinNum .. ".png",
preview = "preview_" .. skinNum .. ".png"
}
end
skins.show_page = function(player, pagenum)
minetest.show_formspec(player:get_player_name(), "skins_page" .. pagenum, skins.pages[pagenum])
end
skins.set_player_skin = function(player)
local n = player:get_player_name()
local skinNum = skins.players[n]
if skinNum == nil then return end
local skinTex = skins.skins[skinNum].texture
minetest.chat_send_all(skinTex)
-- Use functions from 3d_armor to prevent conflicts
armor.textures[n].skin = skinTex
armor:update_player_visuals(player)
end
-- Load skins
local num = 1
while true do
local skinName = "texture_" .. num .. ".png"
local skinF = io.open(skins.skin_path .. skinName)
if skinF then
skinF:close()
skins.add(num)
num = num + 1
else
break
end
end
-- Generate pages
local offset = 0.2
local itemWidth = 1
local itemHeight = itemWidth * 2
local itemsPerRow = 7
local itemsPerColumn = 2
local itemsPerPage = itemsPerRow * itemsPerColumn
local numPages = math.ceil(#skins.skins / (itemsPerPage))
local texNum = 1
local pageFs
local p
local c
local r
local x
local y
for p = 1, numPages do
pageFs = "size[8.6,5.4]" ..
"button[0.2,4.6;1,1;back;<]" ..
"button[7.4,4.6;1,1;forward;>]"
for c = 0, itemsPerColumn - 1 do
for r = 0, itemsPerRow - 1 do
if skins.skins[texNum] == nil then
break
end
x = r * (itemWidth + offset) + offset
y = c * (itemHeight + offset) + offset
pageFs = pageFs .. "image_button[" .. x .. "," .. y .. ";" .. itemWidth .. "," .. itemHeight .. ";" .. skins.skins[texNum].preview .. ";skin" .. texNum .. ";]"
texNum = texNum + 1
end
end
skins.pages[p] = pageFs
end
minetest.register_on_joinplayer(function(p)
inventory_plus.register_button(p, "skins")
skins.set_player_skin(p)
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.skins then
skins.show_page(player, 1)
elseif formname:find("^skins_page%d+$") then
local pageNum = tonumber(formname:sub(11, -1))
if fields.back then
if pageNum > 1 then
pageNum = pageNum - 1
skins.show_page(player, pageNum)
end
elseif fields.forward then
if pageNum < #skins.pages then
pageNum = pageNum + 1
skins.show_page(player, pageNum)
end
else
local firstItem = itemsPerPage * (pageNum - 1)
local lastItem = firstItem + itemsPerPage
for i = firstItem, lastItem do
if fields["skin" .. i] then
skins.players[player:get_player_name()] = i
skins.set_player_skin(player)
skins.save()
break
end
end
end
end
end)

View File

@ -0,0 +1,90 @@
#! /usr/bin/env python3
from shutil import copyfile
from PIL import Image
import PIL
import sys
import os
texPath = os.path.abspath("textures")
def generatePreview(skinPath):
img = Image.open(skinPath)
scaleX = round(img.size[0] / 64)
scaleY = round(img.size[1] / 32)
headFrontBox = (8 * scaleX, 8 * scaleX, 16 * scaleY, 16 * scaleY)
chestFrontBox = (20 * scaleX, 20 * scaleX, 28 * scaleY, 32 * scaleY)
armFrontBox = (44 * scaleX, 20 * scaleX, 48 * scaleY, 32 * scaleY)
legsFront = (4 * scaleX, 20 * scaleX, 12 * scaleY, 32 * scaleY)
preview = Image.new("RGBA", [16 * scaleX, 32 * scaleY])
headFront = img.crop(headFrontBox)
chestFront = img.crop(chestFrontBox)
armFrontLeft = img.crop(armFrontBox)
armFrontRight = armFrontLeft.transpose(PIL.Image.FLIP_LEFT_RIGHT)
legsFront = img.crop(legsFront)
preview.paste(headFront, (4 * scaleX, 0 * scaleY))
preview.paste(chestFront, (4 * scaleX, 8 * scaleY))
preview.paste(armFrontLeft, (0 * scaleX, 8 * scaleY))
preview.paste(armFrontRight, (12 * scaleX, 8 * scaleY))
preview.paste(legsFront, (4 * scaleX, 20 * scaleY))
return preview
def help():
print("This script is used to add textures and generate preview images for textures.")
print("Commands:")
print("add <texture path> Adds texture at <path>")
print("makepreviews Generates previews for all textures currently added")
print("help Displays this help message")
args = sys.argv[1:]
if len(args) == 0:
help()
sys.exit()
cmd = args[0]
if cmd == "add":
if len(args) < 2:
help()
sys.exit()
else:
# Get and copy skin
pathes = args[1:]
for path in pathes:
# Get current name of skin
name = os.path.basename(path)
# Get new name of skin
numSkins = 0
for s in os.listdir(texPath):
if s.startswith("texture_") and s.endswith(".png"):
numSkins += 1
newname = "texture_{0}.png".format(numSkins + 1)
newpath = os.path.join(texPath, newname)
print("Adding {0} as {1} ...".format(name, newname))
# Copy skin over
copyfile(path, newpath)
# Check skin size
skin = Image.open(newpath)
ratio = skin.size[0] / skin.size[1]
if ratio == 1: # MineCraft skin
print ("Found MineCraft skin ({0}x{1})".format(*skin.size))
box = (0, 0, skin.size[0], skin.size[0] / 2)
skin = skin.crop(box)
skin.save(newpath)
print ("Cropped to {0}x{1}".format(box[2], box[3]))
elif ratio != 2:
print("Warning: Found skin with strange dimensions ({0}x{1})".format(*skin.size))
print("Done")
elif cmd == "makepreviews":
for t in os.listdir(texPath):
if t.startswith("texture_"):
name = t[8:]
absPath = os.path.join(texPath, t)
preview = generatePreview(absPath)
previewPath = os.path.join(texPath, "preview_" + name)
preview.save(previewPath)
print("Generated preview for " + t)
else:
help()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 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: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 998 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 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: 955 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

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