summaryrefslogtreecommitdiff
path: root/set_meta.sh
blob: 1db43cd9adc5bf4740c045b78ad3119f683fc900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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