Detect muOS board for keybindings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# This file contains the Controls class, which is responsible for handling user input.
|
||||
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -79,6 +80,20 @@ def _profile_candidates(profile_name):
|
||||
|
||||
|
||||
def _detect_linux_hardware_profile():
|
||||
muos_config_path = Path("/opt/muos/device/current/config.ini")
|
||||
if muos_config_path.exists():
|
||||
parser = configparser.ConfigParser()
|
||||
try:
|
||||
parser.read(muos_config_path, encoding="utf-8")
|
||||
board_name = parser.get("board", "name", fallback="").strip().casefold()
|
||||
except (configparser.Error, OSError):
|
||||
board_name = ""
|
||||
|
||||
if "rg40xx" in board_name:
|
||||
return "rg40xx", f"muos:{board_name}"
|
||||
if "r36s" in board_name:
|
||||
return "r36s", f"muos:{board_name}"
|
||||
|
||||
hints = []
|
||||
for path_like in [
|
||||
"/proc/device-tree/model",
|
||||
|
||||
@@ -1,7 +1,67 @@
|
||||
#!/bin/sh
|
||||
eval "$(/home/ark/miniconda3/bin/conda shell.bash hook)"
|
||||
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
|
||||
find_game_dir() {
|
||||
for candidate in \
|
||||
"$SCRIPT_DIR" \
|
||||
"$SCRIPT_DIR/mice" \
|
||||
/roms/ports/mice \
|
||||
/root/mice \
|
||||
"$HOME/mice"; do
|
||||
if [ -f "$candidate/rats.py" ]; then
|
||||
printf '%s\n' "$candidate"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
find_conda() {
|
||||
for candidate in \
|
||||
/home/ark/miniconda3/bin/conda \
|
||||
/root/miniconda3/bin/conda \
|
||||
"$HOME/miniconda3/bin/conda" \
|
||||
/usr/bin/conda; do
|
||||
if [ -x "$candidate" ]; then
|
||||
printf '%s\n' "$candidate"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
detect_keybindings_profile() {
|
||||
if [ -f /opt/muos/device/current/config.ini ]; then
|
||||
board_name=$(sed -n 's/^name = //p' /opt/muos/device/current/config.ini | head -n 1 | tr '[:upper:]' '[:lower:]')
|
||||
case "$board_name" in
|
||||
*rg40xx*)
|
||||
printf 'rg40xx\n'
|
||||
return 0
|
||||
;;
|
||||
*r36s*)
|
||||
printf 'r36s\n'
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
GAMEDIR=$(find_game_dir)
|
||||
CONDABIN=$(find_conda)
|
||||
|
||||
export MICE_PROJECT_ROOT="$GAMEDIR"
|
||||
|
||||
if [ -z "${MICE_KEYBINDINGS_PROFILE:-}" ]; then
|
||||
MICE_KEYBINDINGS_PROFILE=$(detect_keybindings_profile || true)
|
||||
export MICE_KEYBINDINGS_PROFILE
|
||||
fi
|
||||
|
||||
eval "$($CONDABIN shell.bash hook)"
|
||||
conda activate myenv
|
||||
cd /roms/ports/mice/
|
||||
#git pull
|
||||
|
||||
cd "$GAMEDIR"
|
||||
python rats.py
|
||||
sleep 3
|
||||
|
||||
Reference in New Issue
Block a user