Added custom skins mod
2
mods/simple_skins/depends.txt
Normal file
@ -0,0 +1,2 @@
|
||||
inventory_plus
|
||||
3d_armor
|
122
mods/simple_skins/init.lua
Normal 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)
|
90
mods/simple_skins/texture_manager.py
Executable 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()
|
BIN
mods/simple_skins/textures/inventory_plus_skins.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
mods/simple_skins/textures/preview_1.png
Normal file
After Width: | Height: | Size: 782 B |
BIN
mods/simple_skins/textures/preview_10.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
mods/simple_skins/textures/preview_100.png
Normal file
After Width: | Height: | Size: 728 B |
BIN
mods/simple_skins/textures/preview_101.png
Normal file
After Width: | Height: | Size: 734 B |
BIN
mods/simple_skins/textures/preview_102.png
Normal file
After Width: | Height: | Size: 776 B |
BIN
mods/simple_skins/textures/preview_103.png
Normal file
After Width: | Height: | Size: 875 B |
BIN
mods/simple_skins/textures/preview_104.png
Normal file
After Width: | Height: | Size: 750 B |
BIN
mods/simple_skins/textures/preview_105.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_106.png
Normal file
After Width: | Height: | Size: 790 B |
BIN
mods/simple_skins/textures/preview_107.png
Normal file
After Width: | Height: | Size: 474 B |
BIN
mods/simple_skins/textures/preview_108.png
Normal file
After Width: | Height: | Size: 558 B |
BIN
mods/simple_skins/textures/preview_109.png
Normal file
After Width: | Height: | Size: 562 B |
BIN
mods/simple_skins/textures/preview_11.png
Normal file
After Width: | Height: | Size: 668 B |
BIN
mods/simple_skins/textures/preview_110.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_111.png
Normal file
After Width: | Height: | Size: 560 B |
BIN
mods/simple_skins/textures/preview_112.png
Normal file
After Width: | Height: | Size: 919 B |
BIN
mods/simple_skins/textures/preview_113.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
mods/simple_skins/textures/preview_114.png
Normal file
After Width: | Height: | Size: 771 B |
BIN
mods/simple_skins/textures/preview_115.png
Normal file
After Width: | Height: | Size: 984 B |
BIN
mods/simple_skins/textures/preview_116.png
Normal file
After Width: | Height: | Size: 584 B |
BIN
mods/simple_skins/textures/preview_117.png
Normal file
After Width: | Height: | Size: 438 B |
BIN
mods/simple_skins/textures/preview_118.png
Normal file
After Width: | Height: | Size: 827 B |
BIN
mods/simple_skins/textures/preview_119.png
Normal file
After Width: | Height: | Size: 732 B |
BIN
mods/simple_skins/textures/preview_12.png
Normal file
After Width: | Height: | Size: 802 B |
BIN
mods/simple_skins/textures/preview_120.png
Normal file
After Width: | Height: | Size: 679 B |
BIN
mods/simple_skins/textures/preview_121.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_122.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_123.png
Normal file
After Width: | Height: | Size: 528 B |
BIN
mods/simple_skins/textures/preview_124.png
Normal file
After Width: | Height: | Size: 858 B |
BIN
mods/simple_skins/textures/preview_125.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_126.png
Normal file
After Width: | Height: | Size: 755 B |
BIN
mods/simple_skins/textures/preview_127.png
Normal file
After Width: | Height: | Size: 882 B |
BIN
mods/simple_skins/textures/preview_128.png
Normal file
After Width: | Height: | Size: 648 B |
BIN
mods/simple_skins/textures/preview_129.png
Normal file
After Width: | Height: | Size: 615 B |
BIN
mods/simple_skins/textures/preview_13.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_130.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/simple_skins/textures/preview_131.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
mods/simple_skins/textures/preview_132.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_133.png
Normal file
After Width: | Height: | Size: 680 B |
BIN
mods/simple_skins/textures/preview_134.png
Normal file
After Width: | Height: | Size: 669 B |
BIN
mods/simple_skins/textures/preview_135.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_136.png
Normal file
After Width: | Height: | Size: 809 B |
BIN
mods/simple_skins/textures/preview_137.png
Normal file
After Width: | Height: | Size: 777 B |
BIN
mods/simple_skins/textures/preview_138.png
Normal file
After Width: | Height: | Size: 957 B |
BIN
mods/simple_skins/textures/preview_139.png
Normal file
After Width: | Height: | Size: 871 B |
BIN
mods/simple_skins/textures/preview_14.png
Normal file
After Width: | Height: | Size: 767 B |
BIN
mods/simple_skins/textures/preview_140.png
Normal file
After Width: | Height: | Size: 850 B |
BIN
mods/simple_skins/textures/preview_15.png
Normal file
After Width: | Height: | Size: 720 B |
BIN
mods/simple_skins/textures/preview_16.png
Normal file
After Width: | Height: | Size: 768 B |
BIN
mods/simple_skins/textures/preview_17.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_18.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_19.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_2.png
Normal file
After Width: | Height: | Size: 220 B |
BIN
mods/simple_skins/textures/preview_20.png
Normal file
After Width: | Height: | Size: 676 B |
BIN
mods/simple_skins/textures/preview_21.png
Normal file
After Width: | Height: | Size: 803 B |
BIN
mods/simple_skins/textures/preview_22.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_23.png
Normal file
After Width: | Height: | Size: 1013 B |
BIN
mods/simple_skins/textures/preview_24.png
Normal file
After Width: | Height: | Size: 501 B |
BIN
mods/simple_skins/textures/preview_25.png
Normal file
After Width: | Height: | Size: 998 B |
BIN
mods/simple_skins/textures/preview_26.png
Normal file
After Width: | Height: | Size: 614 B |
BIN
mods/simple_skins/textures/preview_27.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
mods/simple_skins/textures/preview_28.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
mods/simple_skins/textures/preview_29.png
Normal file
After Width: | Height: | Size: 933 B |
BIN
mods/simple_skins/textures/preview_3.png
Normal file
After Width: | Height: | Size: 544 B |
BIN
mods/simple_skins/textures/preview_30.png
Normal file
After Width: | Height: | Size: 665 B |
BIN
mods/simple_skins/textures/preview_31.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_32.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/simple_skins/textures/preview_33.png
Normal file
After Width: | Height: | Size: 955 B |
BIN
mods/simple_skins/textures/preview_34.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/simple_skins/textures/preview_35.png
Normal file
After Width: | Height: | Size: 714 B |
BIN
mods/simple_skins/textures/preview_36.png
Normal file
After Width: | Height: | Size: 858 B |
BIN
mods/simple_skins/textures/preview_37.png
Normal file
After Width: | Height: | Size: 725 B |
BIN
mods/simple_skins/textures/preview_38.png
Normal file
After Width: | Height: | Size: 679 B |
BIN
mods/simple_skins/textures/preview_39.png
Normal file
After Width: | Height: | Size: 694 B |
BIN
mods/simple_skins/textures/preview_4.png
Normal file
After Width: | Height: | Size: 997 B |
BIN
mods/simple_skins/textures/preview_40.png
Normal file
After Width: | Height: | Size: 617 B |
BIN
mods/simple_skins/textures/preview_41.png
Normal file
After Width: | Height: | Size: 852 B |
BIN
mods/simple_skins/textures/preview_42.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
mods/simple_skins/textures/preview_43.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
mods/simple_skins/textures/preview_44.png
Normal file
After Width: | Height: | Size: 680 B |
BIN
mods/simple_skins/textures/preview_45.png
Normal file
After Width: | Height: | Size: 659 B |
BIN
mods/simple_skins/textures/preview_46.png
Normal file
After Width: | Height: | Size: 616 B |
BIN
mods/simple_skins/textures/preview_47.png
Normal file
After Width: | Height: | Size: 808 B |
BIN
mods/simple_skins/textures/preview_48.png
Normal file
After Width: | Height: | Size: 928 B |
BIN
mods/simple_skins/textures/preview_49.png
Normal file
After Width: | Height: | Size: 634 B |
BIN
mods/simple_skins/textures/preview_5.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_50.png
Normal file
After Width: | Height: | Size: 887 B |
BIN
mods/simple_skins/textures/preview_51.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
mods/simple_skins/textures/preview_52.png
Normal file
After Width: | Height: | Size: 723 B |
BIN
mods/simple_skins/textures/preview_53.png
Normal file
After Width: | Height: | Size: 792 B |
BIN
mods/simple_skins/textures/preview_54.png
Normal file
After Width: | Height: | Size: 541 B |
BIN
mods/simple_skins/textures/preview_55.png
Normal file
After Width: | Height: | Size: 813 B |
BIN
mods/simple_skins/textures/preview_56.png
Normal file
After Width: | Height: | Size: 815 B |
BIN
mods/simple_skins/textures/preview_57.png
Normal file
After Width: | Height: | Size: 630 B |
BIN
mods/simple_skins/textures/preview_58.png
Normal file
After Width: | Height: | Size: 633 B |
BIN
mods/simple_skins/textures/preview_59.png
Normal file
After Width: | Height: | Size: 863 B |