Skip to content

Commit

Permalink
feat(): Add the missing options to TATUI (#46)
Browse files Browse the repository at this point in the history
* slowly getting there

* better

* i m getting stronger

* version bump and credit myself

* untested

* dam case sensitiviness

* works correctly but cant detect

* works as intented

* Disable pretty printing on save to make regexes work

---------

Co-authored-by: Callan Barrett <callan@zoocar.org>
  • Loading branch information
asturur and wizzomafizzo authored Apr 15, 2024
1 parent 7a93aee commit 409ae3e
Showing 3 changed files with 137 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/mister.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
- [Probe for Serial Devices (probe\_device)](#probe-for-serial-devices-probe_device)
- [Exit Game When Token Is Removed (exit\_game)](#exit-game-when-token-is-removed-exit_game)
- [Exit Game Core Blocklist (exit\_game\_blocklist)](#exit-game-core-blocklist-exit_game_blocklist)
- [Exit Game Delay (exit\_game\_delay)](#exit-game-delay-exit_game_delay)
- [Mappings Database](#mappings-database)

## Installation
@@ -159,7 +160,7 @@ With this configuration, removing a token will not exit the game when using the

The core name is the same as the name that shows on the left sidebar of the OSD when in a core.

### Exit Game Delay
### Exit Game Delay (exit_game_delay)

| Key | Default Value |
|-----------------------|---------------|
4 changes: 4 additions & 0 deletions pkg/config/user.go
Original file line number Diff line number Diff line change
@@ -174,6 +174,10 @@ func (c *UserConfig) SaveConfig() error {
defer c.mu.Unlock()

cfg := ini.Empty()

ini.PrettyEqual = false
ini.PrettyFormat = false

err := cfg.ReflectFrom(c)
if err != nil {
return err
135 changes: 131 additions & 4 deletions scripts/taptui/taptui.sh
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

title="TapTo"
scriptdir="$(dirname "$(readlink -f "${0}")")"
version="0.5"
version="0.6"
fullFileBrowser="false"
basedir="/media"
sdroot="${basedir}/fat"
@@ -998,6 +998,132 @@ _probeSetting() {
esac
}

_exitGameSetting() {
local menuOptions selected
menuOptions=(
"Enable" "Return to menu core when the card is removed" "off"
"Disable" "Do not return to menu core when the card is removed" "off"
)

[[ -f "${settings}" ]] || echo "[tapto]" > "${settings}" || { _error "Can't create settings file" ; return 1 ; }

# Check if probe_device is set to "no" in the settings
if grep -q "^exit_game=no" "${settings}"; then
# If exit_game is "no", set the corresponding radio button to "on"
menuOptions[5]="on" # Disable option is selected
else
# If exit_game is not "no", set the corresponding radio button to "on"
menuOptions[2]="on" # Enable option is selected
fi

selected="$(_radiolist -- "${menuOptions[@]}" )"
case "${selected}" in
Enable)
if grep -q "^exit_game=" "${settings}"; then
sed -i "s/^exit_game=.*/exit_game=yes/" "${settings}"
else
echo "exit_game=yes" >> "${settings}"
fi
;;
Disable)
if grep -q "^exit_game=" "${settings}"; then
sed -i "s/^exit_game=.*/exit_game=no/" "${settings}"
else
echo "exit_game=no" >> "${settings}"
fi
;;
esac
}

_exitGameBlocklistSetting() {
local menuOptions selected customString
menuOptions=(
"Disable" "All cores will exit when a card is removed" "off"
"Enable" "Enter a custom list of core names" "off"
)

[[ -f "${settings}" ]] || echo "[tapto]" > "${settings}" || { _error "Can't create settings file" ; return 1 ; }

if ! grep -q "^exit_game_blocklist=" "${settings}"; then
menuOptions[2]="on"
elif grep -q "^exit_game_blocklist=\"\"" "${settings}"; then
menuOptions[2]="on"
else
menuOptions[5]="on"
fi

if grep -q "^exit_game_blocklist=\"..*\"" "${settings}"; then
customString="$(grep "^exit_game_blocklist=" "${settings}" | cut -d '"' -f 2)"
menuOptions[4]="Enter a custom list of core names, current value: ${customString}"
fi

selected="$(_radiolist -- "${menuOptions[@]}" )"
case "${selected}" in
Disable)
if grep -q "^exit_game_blocklist=" "${settings}"; then
sed -i "s/^exit_game_blocklist=.*/exit_game_blocklist=\"\"/" "${settings}"
else
echo "exit_game_blocklist=\"\"" >> "${settings}"
fi
;;
Enable)

customString="$(_inputbox "Enter core list, comma separated (SNES, GENESIS)" "${customString}")"
if grep -q "^exit_game_blocklist=" "${settings}"; then
sed -i "s/^exit_game_blocklist=.*/exit_game_blocklist=\"${customString}\"/" "${settings}"
else
echo "exit_game_blocklist=\"${customString}\"" >> "${settings}"
fi
;;
esac
}

_exitGameDelaySetting() {
local menuOptions selected customString delayInSeconds exitcode
menuOptions=(
"Disable" "Set the delay to 0" "off"
"Enable" "Enter a custom delay in seconds" "off"
)

[[ -f "${settings}" ]] || echo "[tapto]" > "${settings}" || { _error "Can't create settings file" ; return 1 ; }

if grep -q "^exit_game_delay=[1-9][0-9]*" "${settings}"; then
menuOptions[5]="on"
else
menuOptions[2]="on"
fi

if grep -q "^exit_game_delay=.*" "${settings}"; then
customString="$(grep "^exit_game_delay=" "${settings}" | cut -d '=' -f 2)"
menuOptions[4]="Change the delay in seconds, current value: ${customString}"
fi

selected="$(_radiolist -- "${menuOptions[@]}" )"
case "${selected}" in
Disable)
if grep -q "^exit_game_delay=" "${settings}"; then
sed -i "s/^exit_game_delay=.*/exit_game_delay=0/" "${settings}"
else
echo 'exit_game_delay=0' >> "${settings}"
fi
;;
Enable)

while true; do
delayInSeconds="$(_inputbox "Enter delay in seconds" "${customString}")"
exitcode="${?}"; [[ "${exitcode}" -ge 1 ]] && { "${FUNCNAME[0]}" ; return ; }
[[ "${delayInSeconds}" == +([0-9]*) ]] && break
_error "${delayInSeconds} is not a positive number"
done
if grep -q "^exit_game_delay=" "${settings}"; then
sed -i "s/^exit_game_delay=.*/exit_game_delay=${delayInSeconds}/" "${settings}"
else
echo "exit_game_delay=${delayInSeconds}" >> "${settings}"
fi
;;
esac
}

_About() {
local about
read -rd '' about <<_EOF_
@@ -1010,9 +1136,10 @@ Whats New? Get involved? Need help?
${nfcjokes[$((RANDOM % ${#nfcjokes[@]}))]}
Gaz ${underline}github.com/symm${noUnderline}
Wizzo ${underline}github.com/wizzomafizzo${noUnderline}
Ziggurat ${underline}github.com/sigboe${noUnderline}
Gaz ${underline}github.com/symm${noUnderline}
Wizzo ${underline}github.com/wizzomafizzo${noUnderline}
Ziggurat ${underline}github.com/sigboe${noUnderline}
Andrea Bogazzi ${underline}github.com/asturur${noUnderline}
License: GPL v3.0
${underline}github.com/wizzomafizzo/tapto/blob/main/LICENSE${noUnderline}

0 comments on commit 409ae3e

Please sign in to comment.