forked from AhmedKJ/Co-op-on-Linux
-
Notifications
You must be signed in to change notification settings - Fork 6
/
create-new-profile.sh
executable file
·51 lines (43 loc) · 2.43 KB
/
create-new-profile.sh
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
#!/usr/bin/env sh
#
DIALOG=zenity
DIR_CO_OP=$PWD
if type "kdialog" > /dev/null; then
GAMERUN=$(kdialog --title="Select game executable/launch script" --getopenfilename)
else
GAMERUN=$(zenity --title="Select game executable/launch script" --file-selection)
fi
DEFAULT_RES=$(xdpyinfo | awk '/dimensions/{print $2}')
MULTIWINDOW=$($DIALOG --title="Separate Windows Per Player?" --list --radiolist --column "Pick" --column "Option" TRUE "Splitscreen Window" FALSE "Separate Windows")
if [ "$MULTIWINDOW" = "Separate Windows" ]; then
NUM_WINDOWS=$($DIALOG --title="Number of windows" --entry --text="Enter the total number of windows (for example: 2)" --entry-text=2)
declare -a MW_WIDTHS
declare -a MW_HEIGHTS
for i in $(seq 0 $((NUM_WINDOWS - 1))); do
RESOLUTION=$($DIALOG --title="Resolution" --entry --text="Enter screen resolution for player $(($i + 1)) ( for example: 1280x720 ) " --entry-text=$DEFAULT_RES)
MW_WIDTHS[$i]=$(printf $RESOLUTION | awk -F "x" '{print $1}')
MW_HEIGHTS[$i]=$(printf $RESOLUTION | awk -F "x" '{print $2}')
done
elif [ "$MULTIWINDOW" = "Splitscreen Window" ]; then
RESOLUTION=$($DIALOG --title="Resolution" --entry --text="Enter screen resolution ( for example: 1280x720 ) " --entry-text=$DEFAULT_RES)
WIDTH=$(printf $RESOLUTION | awk -F "x" '{print $1}')
HEIGHT=$(printf $RESOLUTION | awk -F "x" '{print $2}')
fi
name=$($DIALOG --title="Profile name" --entry --text="Enter a name for the profile" --entry-text="name")
mkdir -p "$DIR_CO_OP"/profiles
echo "#!/bin/bash" > "$DIR_CO_OP/profiles/$name.sh"
if [ "$MULTIWINDOW" = "Separate Windows" ]; then
echo "export MULTIWINDOW=1" >> "$DIR_CO_OP/profiles/$name.sh"
echo "export NUM_WINDOWS=$NUM_WINDOWS" >> "$DIR_CO_OP/profiles/$name.sh"
for i in $(seq 0 $((NUM_WINDOWS - 1))); do
echo "export WIDTH$(($i + 1))=${MW_WIDTHS[$i]}" >> "$DIR_CO_OP/profiles/$name.sh"
echo "export HEIGHT$(($i + 1))=${MW_HEIGHTS[$i]}" >> "$DIR_CO_OP/profiles/$name.sh"
done
elif [ "$MULTIWINDOW" = "Splitscreen Window" ]; then
echo "export WIDTH=$WIDTH" >> "$DIR_CO_OP/profiles/$name.sh"
echo "export HEIGHT=$HEIGHT" >> "$DIR_CO_OP/profiles/$name.sh"
fi
echo "export GAMERUN='$GAMERUN'" >> "$DIR_CO_OP/profiles/$name.sh"
echo "../Co-Op-On-Linux.sh" >> "$DIR_CO_OP/profiles/$name.sh"
chmod +x "$DIR_CO_OP/profiles/$name.sh"
zenity --info --text "Preset created! To load it go to the preset folder and execute its script"