#!/bin/bash # Pokémon Red (LÖVE2D) - double-click launcher for macOS. # # First run: decodes a user-provided .gb file, installs anything missing, # builds the game data, then launches. # Every later run: launches the game straight away. cd "$(dirname "$0")" || exit 1 say() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m !!\033[0m %s\n' "$*"; } err() { printf '\033[1;31merror:\033[0m %s\n' "$*"; } pause_exit() { # keep the Terminal window readable after a failure echo read -n 1 -s -r -p "Press any key to close this window..." echo exit "${1:-0}" } ask() { # ask "question" -> yes by default local a read -r -p "$1 [Y/n] " a case "$a" in n|N|no|NO) return 1 ;; *) return 0 ;; esac } printf '\n \033[1mPokémon Red - LÖVE2D port\033[0m\n\n' have_love() { local app version for app in ".bazinga/love12/love.app" "/Applications/love12.app" "$HOME/Applications/love12.app" \ "/Applications/love.app" "$HOME/Applications/love.app"; do [ -x "$app/Contents/MacOS/love" ] || continue version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist" 2>/dev/null || true)" printf '%s' "$version" | grep -Eq '^12(\.|$)' || continue otool -L "$app/Contents/Frameworks/love.framework/love" 2>/dev/null \ | grep -q '/Metal.framework/' && return 0 done return 1 } # ---------------------------------------------------------------- fast path if [ -f data/generated/maps.lua ] && have_love; then say "already set up, launching the game" scripts/run.sh || { err "the game failed to start"; pause_exit 1; } exit 0 fi say "first-time setup" # ------------------------------------------------------- Xcode CLT (python3) if ! command -v python3 >/dev/null 2>&1; then warn "python3 is missing; it comes with Apple's command-line tools" if ask "Install Apple's command-line tools now?"; then xcode-select --install 2>/dev/null || true echo warn "Finish the Apple installer window that just opened, then" warn "double-click Play-Mac.command again to continue." pause_exit 0 else err "cannot continue without python3" pause_exit 1 fi fi if ! have_love && ! command -v xcodebuild >/dev/null 2>&1; then warn "LÖVE 12 is not installed and Xcode is required to build it for macOS." warn "Install Xcode from the App Store, launch it once, then run this again." pause_exit 1 fi # ------------------------------------------------------------------- build echo scripts/setup.sh \ || { err "setup failed - see the messages above"; pause_exit 1; } say "setup done, launching the game" scripts/run.sh || { err "the game failed to start"; pause_exit 1; } exit 0