1
0
mirror of https://github.com/SmallJoker/minetest-u_skinsdb.git synced 2024-11-12 21:30:17 +01:00
This commit is contained in:
dmonty2 2014-03-16 22:25:18 -07:00
parent 039f49f408
commit 5e58108006
5 changed files with 198 additions and 0 deletions

48
generate_previews.sh Executable file
View File

@ -0,0 +1,48 @@
#!/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
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 !"

0
modpack.txt Normal file
View File

59
set_meta.sh Executable file
View File

@ -0,0 +1,59 @@
#!/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

46
update_from_db.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/python3
from http.client import HTTPConnection
import json
import base64
server = "minetest.fensta.bplaced.net"
skinsdir = "u_skins/textures/"
metadir = "u_skins/meta/"
i = 1
pages = 0
c = HTTPConnection(server)
def addpage(page):
global i, pages
print( "Page: "+str(page))
try:
c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
r = c.getresponse()
except StandardError:
c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
r = c.getresponse()
if r.status != 200:
print("Error", r.status)
exit(r.status)
data = r.read().decode()
l = json.loads(data)
if not l["success"]:
print("Success != True")
exit(1)
pages = int(l["pages"])
for s in l["skins"]:
f = open(skinsdir+"character_"+str(i)+".png",'wb')
f.write(base64.b64decode(s["img"]))
f.close()
f = open(metadir+"character_"+str(i)+".txt",'w')
f.write('name = "'+s["name"]+'",\n')
f.write('author = "'+s["author"]+'",\n')
f.write('comment = "'+s["license"]+'",\n')
f.close()
i = i + 1
addpage(1)
if pages > 1:
for p in range(pages-1):
addpage(p+2)
print("Skins have been updated. Please run ./generate_previews.sh")

45
update_from_db2.py Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/python3
#from http.client import HTTPConnection
import json
import base64
import requests
server = "minetest.fensta.bplaced.net"
skinsdir = "u_skins/textures/"
metadir = "u_skins/meta/"
i = 1
pages = 0
#c = HTTPConnection(server)
def addpage(page):
global i, pages
print( "Page: "+str(page))
try:
#c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
#r = c.getresponse()
r = requests.get("http://"+str(server)+"/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
except StandardError:
print("Error", r.status)
exit(r.status)
data = r.text
l = json.loads(data)
if not l["success"]:
print("Success != True")
exit(1)
pages = int(l["pages"])
for s in l["skins"]:
f = open(skinsdir+"character_"+str(i)+".png",'wb')
f.write(base64.b64decode(s["img"]))
f.close()
f = open(metadir+"character_"+str(i)+".txt",'w')
f.write('name = "'+s["name"]+'",\n')
f.write('author = "'+s["author"]+'",\n')
f.write('comment = "'+s["license"]+'",\n')
f.close()
i = i + 1
addpage(1)
if pages > 1:
for p in range(pages-1):
addpage(p+2)
print("Skins have been updated. Please run ./generate_previews.sh")