-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaria-randomizer.sh
194 lines (161 loc) · 5.58 KB
/
varia-randomizer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
## Grab ini-reading functions from retropie
#readonly rootdir="/opt/retropie"
#source "$rootdir/lib/inifuncs.sh"
source "/opt/retropie/supplementary/varia-randomizer/functions.sh"
PARAMS_FILE=/opt/retropie/supplementary/varia-randomizer/varia-settings-parameters.ini
parameter_names=()
parameter_friendly_names=()
parameter_values=()
#parameter_default_values=()
parameter_friendly_values=()
arguments=()
myarray=()
function read_params_file()
{
let i=0
while IFS=$'\n' read -r line_data; do
echo $line_data
IFS='=' read -ra EQUAL_SPLIT <<< "$line_data"
IFS='|' read -ra PIPE_SPLIT <<< "${EQUAL_SPLIT[0]}"
parameter_names+=("${PIPE_SPLIT[0]}")
parameter_friendly_names+=("${PIPE_SPLIT[1]}")
IFS=';' read -ra SEMIC_SPLIT <<< "${EQUAL_SPLIT[1]}"
IFS='|' read -ra PIPE_SPLIT <<< "${SEMIC_SPLIT[0]}"
# parameter_default_values+=("${PIPE_SPLIT[1]}")
parameter_values+=("${PIPE_SPLIT[0]}")
parameter_friendly_values+=("${PIPE_SPLIT[1]}")
echo "${PIPE_SPLIT[1]}"
# Parse “${line_data}” to produce content
# that will be stored in the array.
# (Assume content is stored in a variable
# named 'array_element'.)
# ...
myarray[i]="${array_element}" # Populate array.
((++i))
done < $PARAMS_FILE
}
# Docuemnt this to include 1 param
function generate_sub_menu()
{
[[ "$1" ]] || fatalError "js_select: missing argument: \"index\""
index=$1
line_data2=$(sed "${index}q;d" $PARAMS_FILE)
IFS='=' read -ra EQUAL_SPLIT2 <<< "$line_data2"
IFS=';' read -ra SEMIC_SPLIT2 <<< "${EQUAL_SPLIT2[1]}"
sub_options=()
sub_options_friendly=()
for i in "${!SEMIC_SPLIT2[@]}"
do
IFS='|' read -ra PIPE_SPLIT2 <<< "${SEMIC_SPLIT2[$i]}"
sub_options_friendly+=($i "${PIPE_SPLIT2[1]}")
sub_options+=($i "${PIPE_SPLIT2[0]}")
done
cmd=(dialog \
--title " Submenu " \
--menu "Submenu description" 19 80 12
)
choice=$("${cmd[@]}" "${sub_options_friendly[@]}" 2>&1 >/dev/tty)
if [[ -n "$choice" ]]; then
parameter_values[$((index-1))]="${sub_options[$((choice*2+1))]}"
parameter_friendly_values[$((index-1))]="${sub_options_friendly[$((choice*2+1))]}"
fi
} #end sub_menu
## Copys and checks the local rom
function check_rom() {
user="$SUDO_USER"
[[ -z "$user" ]] && user="$(id -un)"
local home="$(eval echo ~$user)"
home="$(find /home -type d -name RetroPie -print -quit 2> /dev/null)"
mkdir -p $home/../.varia-randomizer
#chmod 777 $home/../.varia-randomizer
local romPath="$home/../.varia-randomizer/rom.smc"
if [ ! -f "$romPath" ]; then
dialog --infobox "Searching for Super Metroid Rom..." 19 80
hasRom "snes" "Super Metroid" "SuperMetroid.smc"
if [[ "$?" == "1" ]]; then
dialog --infobox "Copying Original Super Metroid Rom..." 19 80
sleep 1
copyRom "snes" "Super Metroid" "SuperMetroid.smc" "$romPath"
else
dialog --title "Error" --msgbox "Cannot find 'Super Metroid' in xml gamelist" 19 80
exit
fi
if [ ! -f "$romPath" ]; then
dialog --title "Error" --msgbox "Failed to copy super metroid source rom" 19 80
exit
fi
fi
}
# Choose between global config, system specific config, toggle byname
function generate_menu() {
while true; do
# Remake options
options=()
for i in "${!parameter_names[@]}"
do
newIndex=$((i+1))
options+=($newIndex "${parameter_friendly_names[$i]} - ${parameter_friendly_values[$i]}")
done
options+=("G" "Generate")
# Show dialog
cmd=(dialog --title " Generate Rom " --menu "Varia Randomizer Rom. Randomize your rom with the varia randomizer" 19 80 12)
choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
if [[ -n "$choice" ]]; then
if [[ "$choice" == "G" ]]; then
generate
dialog --title "Generated" --msgbox "Good Luck!\n\nMay the odds be ever in your favour!\n\nYou may want to restart EmulationStation to update description metadata" 19 80
exit
else
generate_sub_menu $choice
fi
else
break
fi
done
} # end of main_menu()
function generate() {
dialog --infobox "Generating Random Rom..." 19 80
# Generate single argument string
string_args=""
for i in "${!parameter_names[@]}"
do
string_args="${string_args} ${parameter_names[$i]} ${parameter_values[$i]}"
done
# Generate
/bin/bash /opt/retropie/supplementary/varia-randomizer/varia-randomizer-generate.sh $string_args
}
function main_menu() {
## check file exists for install
while true; do
generate_menu
done
}
function install_menu() {
local options_games=()
local randomizer_ids=()
local systems=()
local file_extensions=()
local game_names=()
local randomizer_names=()
let i=0
while IFS=$'\n' read -r line_data; do
echo $line_data
IFS='|' read -ra PIPE_SPLIT <<< "$line_data"
randomizer_ids+=("${PIPE_SPLIT[0]}")
systems+=("${PIPE_SPLIT[1]}")
file_extensions+=("${PIPE_SPLIT[2]}")
game_names+=("${PIPE_SPLIT[3]}")
randomizer_names+=("${PIPE_SPLIT[4]}")
options_games+=($i "${PIPE_SPLIT[4]} - ${PIPE_SPLIT[3]}")
((++i))
done < $CONFIG_FILE
# Show dialog
cmd=(dialog \
--title " Select an option " \
--menu "Ranomizer Menu" 19 80 12)
choice=$("${cmd[@]}" "${options_games[@]}" 2>&1 >/dev/tty)
}
check_rom
read_params_file
generate_menu