From 5233294b267ab8839b17bd5402588bf67c2fdd87 Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 7 May 2026 19:38:05 +0200 Subject: [PATCH] Detect muOS board for keybindings --- engine/controls.py | 15 ++++++++++ mice.sh | 68 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/engine/controls.py b/engine/controls.py index 386520c..827a58e 100644 --- a/engine/controls.py +++ b/engine/controls.py @@ -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", diff --git a/mice.sh b/mice.sh index 6c540e5..4b6676e 100755 --- a/mice.sh +++ b/mice.sh @@ -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