import { useState, useRef } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { useUI, useAudio, useConfig } from "../../context/LauncherContext"; import { OptionsService } from "../../services/OptionsService"; import { OptionsFile } from "../../types/options"; const BUTTONS: Record = { 0x00: "NONE", 0x01: "A", 0x02: "B", 0x03: "X", 0x04: "Y", 0x05: "D-Pad Left", 0x06: "D-Pad Right", 0x07: "D-Pad Up", 0x08: "D-Pad Down", 0x09: "RB", 0x0A: "LB", 0x0B: "RT", 0x0C: "LT", 0x0D: "RS", 0x0E: "LS" }; export default function OptionsEditorView() { const { setActiveView } = useUI(); const { playPressSound, playBackSound } = useAudio(); const { animationsEnabled } = useConfig(); const [opt, setOpt] = useState(null); const [notification, setNotification] = useState<{ message: string, type: "success" | "error" } | null>(null); const fileInputRef = useRef(null); const [activeTab, setActiveTab] = useState<"settings" | "skins" | "actions">("settings"); const showNotification = (message: string, type: "success" | "error" = "success") => { setNotification({ message, type }); setTimeout(() => setNotification(null), 3000); }; const handleFileLoad = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; playPressSound(); const buffer = await file.arrayBuffer(); try { const parsed = OptionsService.readOptions(buffer); setOpt(parsed); showNotification(`Loaded options.dat`); } catch (err: unknown) { console.error("Failed to parse Options", err); showNotification(err instanceof Error ? err.message : "Failed to parse Options", "error"); } e.target.value = ""; }; const handleSaveOptions = () => { if (!opt) return; playPressSound(); try { const buffer = OptionsService.serializeOptions(opt); const blob = new Blob([buffer]); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "options.dat"; a.click(); URL.revokeObjectURL(url); showNotification("Options Saved"); } catch (err: unknown) { showNotification("Failed to save", "error"); } }; const updateSetting = (field: keyof OptionsFile, value: string | number | boolean | number[]) => { if (!opt) return; setOpt({ ...opt, [field]: value }); }; const updateAction = (field: keyof OptionsFile["actions"], value: number) => { if (!opt) return; setOpt({ ...opt, actions: { ...opt.actions, [field]: value } }); }; const updateFavSkin = (idx: number, value: number) => { if (!opt) return; const newFav = [...opt.favoriteSkins]; newFav[idx] = value; setOpt({ ...opt, favoriteSkins: newFav }); }; return (

Options Editor

{!opt ? (

Open settings.dat to begin

) : (
{(["settings", "skins", "actions"] as const).map(tab => ( ))}
{activeTab === "settings" && (
{Object.keys(opt).filter(k => k !== "actions" && k !== "rawData" && k !== "chosenSkin" && k !== "playerCape" && k !== "favoriteSkins" && k !== "endianness").map((k) => { const val = opt[k as keyof OptionsFile]; if (typeof val === "boolean") { return (
)}
{notification && ( {notification.message} )} ); }