This commit is contained in:
2026-04-03 14:44:13 +02:00
parent 3c6c6ae749
commit 1fe9197b9b
19 changed files with 2351 additions and 246 deletions
+236
View File
@@ -0,0 +1,236 @@
import React, { useState, useEffect } from 'react'
import { Search, Download, Trash2, ExternalLink, Package, Filter, CheckCircle2, XCircle, ChevronRight, X } from 'lucide-react'
import { launcherService, type Mod, type GameVersion } from '../services/LauncherService'
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
import { motion, AnimatePresence } from 'framer-motion'
function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
interface ModsSectionProps {
version: GameVersion
}
const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
const [activeTab, setActiveTab] = useState<'installed' | 'discover'>('installed')
const [searchQuery, setSearchQuery] = useState('')
const [mods, setMods] = useState<Mod[]>([])
const [isInstallDialogOpen, setIsInstallDialogOpen] = useState(false)
const [selectedModForInstall, setSelectedModForInstall] = useState<Mod | null>(null)
const [selectedVersionsForInstall, setSelectedVersionsForInstall] = useState<string[]>([])
const [allVersions, setAllVersions] = useState<GameVersion[]>([])
useEffect(() => {
const loadMods = async () => {
if (activeTab === 'installed') {
const m = await launcherService.getInstalledMods(version.id)
setMods(m)
} else {
const m = await launcherService.discoverMods(searchQuery)
setMods(m)
}
}
loadMods()
}, [activeTab, version.id, searchQuery])
useEffect(() => {
const loadAllVersions = async () => {
const v = await launcherService.getVersions()
setAllVersions(v)
}
loadAllVersions()
}, [])
const handleToggleMod = async (modId: string) => {
await launcherService.toggleMod(modId)
const m = await launcherService.getInstalledMods(version.id)
setMods(m)
}
const openInstallDialog = (mod: Mod) => {
setSelectedModForInstall(mod)
setSelectedVersionsForInstall([version.id])
setIsInstallDialogOpen(true)
}
const handleInstall = async () => {
if (selectedModForInstall && selectedVersionsForInstall.length > 0) {
await launcherService.installMod(selectedModForInstall, selectedVersionsForInstall)
setIsInstallDialogOpen(false)
if (activeTab === 'installed') {
const m = await launcherService.getInstalledMods(version.id)
setMods(m)
}
}
}
const toggleVersionSelection = (versionId: string) => {
setSelectedVersionsForInstall(prev =>
prev.includes(versionId)
? prev.filter(v => v !== versionId)
: [...prev, versionId]
)
}
return (
<div className="max-w-6xl mx-auto h-full flex flex-col gap-6">
<div className="flex items-center justify-between">
<div className="flex items-center gap-1 p-1 bg-saturn-panel border border-saturn-border rounded-lg">
<button
onClick={() => setActiveTab('installed')}
className={cn("px-4 py-1.5 text-sm font-medium rounded-md transition-all", activeTab === 'installed' ? "bg-white/5 text-white" : "text-saturn-text-secondary hover:text-white")}
>
Installed Mods
</button>
<button
onClick={() => setActiveTab('discover')}
className={cn("px-4 py-1.5 text-sm font-medium rounded-md transition-all", activeTab === 'discover' ? "bg-white/5 text-white" : "text-saturn-text-secondary hover:text-white")}
>
Discover
</button>
</div>
<div className="relative group">
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-saturn-text-secondary group-focus-within:text-saturn-accent transition-colors" />
<input
type="text"
placeholder={activeTab === 'installed' ? "Search installed mods..." : "Search CurseForge/Modrinth..."}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="bg-saturn-panel border border-saturn-border rounded-lg pl-10 pr-4 py-2 text-sm w-64 focus:outline-none focus:border-saturn-accent/50 focus:ring-1 focus:ring-saturn-accent/50 transition-all"
/>
</div>
</div>
<div className="flex-1 overflow-y-auto pr-2">
<div className="grid grid-cols-1 gap-3">
{mods.map(mod => (
<motion.div
layout
key={mod.id}
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
className="panel p-4 flex items-center gap-4 hover:border-white/10 transition-colors"
>
<div className="w-12 h-12 rounded-lg bg-zinc-800 border border-saturn-border flex items-center justify-center shrink-0">
<Package size={24} className="text-saturn-text-secondary" />
</div>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<h3 className="font-bold text-sm truncate">{mod.name}</h3>
<span className="text-[10px] text-saturn-text-secondary font-medium px-1.5 py-0.5 rounded bg-white/5">v{mod.version}</span>
<span className="text-[10px] text-saturn-text-secondary">by {mod.author}</span>
</div>
<p className="text-xs text-saturn-text-secondary mt-1 truncate max-w-xl">{mod.description}</p>
</div>
<div className="flex items-center gap-3">
{activeTab === 'installed' ? (
<>
<button
onClick={() => handleToggleMod(mod.id)}
className={cn("flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-medium transition-all", mod.enabled ? "bg-green-500/10 text-green-400 border border-green-500/20" : "bg-red-500/10 text-red-400 border border-red-500/20")}
>
{mod.enabled ? <CheckCircle2 size={14} /> : <XCircle size={14} />}
{mod.enabled ? 'Enabled' : 'Disabled'}
</button>
<button className="p-2 text-saturn-text-secondary hover:text-red-400 transition-colors">
<Trash2 size={16} />
</button>
</>
) : (
<button
onClick={() => openInstallDialog(mod)}
className="flex items-center gap-2 px-4 py-1.5 bg-saturn-accent/10 text-saturn-accent hover:bg-saturn-accent hover:text-white rounded-md text-xs font-bold transition-all border border-saturn-accent/20"
>
<Download size={14} />
INSTALL
</button>
)}
</div>
</motion.div>
))}
{mods.length === 0 && (
<div className="h-64 flex flex-col items-center justify-center text-saturn-text-secondary opacity-50">
<Package size={48} className="mb-4" strokeWidth={1} />
<p>No mods found.</p>
</div>
)}
</div>
</div>
{/* Install Dialog */}
<AnimatePresence>
{isInstallDialogOpen && selectedModForInstall && (
<div className="fixed inset-0 bg-black/80 backdrop-blur-sm z-[100] flex items-center justify-center p-6">
<motion.div
initial={{ scale: 0.9, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }}
className="bg-saturn-panel border border-saturn-border rounded-xl w-full max-w-md shadow-2xl overflow-hidden"
>
<div className="p-6 border-b border-saturn-border flex items-center justify-between">
<div>
<h2 className="text-lg font-bold">Install {selectedModForInstall.name}</h2>
<p className="text-xs text-saturn-text-secondary">Select versions to install this mod to.</p>
</div>
<button onClick={() => setIsInstallDialogOpen(false)} className="text-saturn-text-secondary hover:text-white">
<X size={20} />
</button>
</div>
<div className="p-6 space-y-3 max-h-64 overflow-y-auto">
{allVersions.map(v => {
const isSupported = selectedModForInstall.supportedVersions.includes(v.id)
const isSelected = selectedVersionsForInstall.includes(v.id)
return (
<div
key={v.id}
onClick={() => isSupported && toggleVersionSelection(v.id)}
className={cn(
"flex items-center justify-between p-3 rounded-lg border transition-all cursor-pointer",
isSelected ? "bg-saturn-accent/10 border-saturn-accent/50" : "bg-white/5 border-transparent hover:border-white/10",
!isSupported && "opacity-40 cursor-not-allowed grayscale"
)}
>
<div className="flex items-center gap-3">
<div className={cn("w-5 h-5 rounded border flex items-center justify-center transition-all", isSelected ? "bg-saturn-accent border-saturn-accent" : "border-saturn-border")}>
{isSelected && <CheckCircle2 size={14} className="text-white" />}
</div>
<span className="text-sm font-medium">{v.name}</span>
</div>
{!isSupported && <span className="text-[10px] text-red-400 font-bold uppercase">Unsupported</span>}
</div>
)
})}
</div>
<div className="p-6 bg-white/5 flex gap-3">
<button
onClick={() => setIsInstallDialogOpen(false)}
className="flex-1 py-2 text-sm font-medium hover:bg-white/5 rounded-lg transition-colors"
>
Cancel
</button>
<button
onClick={handleInstall}
disabled={selectedVersionsForInstall.length === 0}
className="flex-1 py-2 text-sm font-bold bg-saturn-accent hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed rounded-lg transition-all shadow-lg shadow-saturn-accent/20"
>
Confirm Install
</button>
</div>
</motion.div>
</div>
)}
</AnimatePresence>
</div>
)
}
export default ModsSection
+110
View File
@@ -0,0 +1,110 @@
import React, { useState } from 'react'
import { Play, Loader2, Info, ExternalLink } from 'lucide-react'
import { launcherService, type GameVersion } from '../services/LauncherService'
import { motion } from 'framer-motion'
interface PlaySectionProps {
version: GameVersion
}
const PlaySection: React.FC<PlaySectionProps> = ({ version }) => {
const [isLaunching, setIsLaunching] = useState(false)
const [launchStatus, setLaunchStatus] = useState('')
const handleLaunch = async () => {
setIsLaunching(true)
setLaunchStatus('Preparing...')
// Simulate launch steps
setTimeout(() => setLaunchStatus('Verifying assets...'), 500)
setTimeout(() => setLaunchStatus('Applying Saturn optimizations...'), 1200)
const result = await launcherService.launchGame(version.id)
if (result.success) {
setLaunchStatus('Game running')
// In a real app, we might minimize or close the launcher here
}
setTimeout(() => {
setIsLaunching(false)
setLaunchStatus('')
}, 3000)
}
return (
<div className="h-full flex flex-col items-center justify-center max-w-4xl mx-auto text-center">
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
className="mb-12"
>
<h1 className="text-6xl font-black tracking-tighter mb-2 bg-gradient-to-b from-white to-white/40 bg-clip-text text-transparent">
SATURN
</h1>
<p className="text-saturn-text-secondary text-lg tracking-widest font-light uppercase">
Fabric-Only Optimization Client
</p>
</motion.div>
<div className="w-full grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
<div className="panel p-6 flex flex-col items-center gap-3">
<div className="w-10 h-10 rounded-full bg-white/5 flex items-center justify-center text-saturn-accent">
<Info size={20} />
</div>
<div>
<p className="text-xs text-saturn-text-secondary uppercase tracking-wider font-bold">Instance</p>
<p className="text-sm font-medium">Saturn Default</p>
</div>
</div>
<div className="panel p-6 flex flex-col items-center gap-3 border-saturn-accent/30 bg-saturn-accent/5">
<div className="w-10 h-10 rounded-full bg-saturn-accent/20 flex items-center justify-center text-saturn-accent">
<Play size={20} fill="currentColor" />
</div>
<div>
<p className="text-xs text-saturn-text-secondary uppercase tracking-wider font-bold">Current Version</p>
<p className="text-sm font-medium">{version.name}</p>
</div>
</div>
<div className="panel p-6 flex flex-col items-center gap-3">
<div className="w-10 h-10 rounded-full bg-white/5 flex items-center justify-center text-saturn-accent">
<ExternalLink size={20} />
</div>
<div>
<p className="text-xs text-saturn-text-secondary uppercase tracking-wider font-bold">Modloader</p>
<p className="text-sm font-medium">Fabric Loader</p>
</div>
</div>
</div>
<div className="relative group">
<div className="absolute -inset-1 bg-gradient-to-r from-blue-600 to-cyan-500 rounded-lg blur opacity-25 group-hover:opacity-50 transition duration-1000 group-hover:duration-200"></div>
<button
onClick={handleLaunch}
disabled={isLaunching}
className="relative btn-primary px-16 py-4 text-xl flex items-center gap-3 min-w-[240px] justify-center"
>
{isLaunching ? (
<>
<Loader2 size={24} className="animate-spin" />
<span>{launchStatus}</span>
</>
) : (
<>
<Play size={24} fill="currentColor" />
<span>PLAY</span>
</>
)}
</button>
</div>
<div className="mt-12 text-saturn-text-secondary text-xs max-w-md">
<p>Saturn Client is not affiliated with Mojang AB. Use at your own risk. Performance may vary based on hardware.</p>
</div>
</div>
)
}
export default PlaySection
+156
View File
@@ -0,0 +1,156 @@
import React, { useState, useEffect } from 'react'
import { Cpu, MemoryStick, Save, RefreshCcw, Info, AlertTriangle } from 'lucide-react'
import { launcherService, type LauncherSettings } from '../services/LauncherService'
import { motion } from 'framer-motion'
const SettingsSection: React.FC = () => {
const [settings, setSettings] = useState<LauncherSettings | null>(null)
const [isSaving, setIsSaving] = useState(false)
const [saveStatus, setSaveStatus] = useState('')
useEffect(() => {
const loadSettings = async () => {
const s = await launcherService.getSettings()
setSettings(s)
}
loadSettings()
}, [])
const handleSave = async () => {
if (!settings) return
setIsSaving(true)
setSaveStatus('Saving...')
await launcherService.updateSettings(settings)
setTimeout(() => {
setIsSaving(false)
setSaveStatus('Settings saved')
setTimeout(() => setSaveStatus(''), 2000)
}, 1000)
}
const handleReset = async () => {
// In a real app, this would reset to defaults in the service
const defaultSettings: LauncherSettings = {
jvmArguments: '-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200',
maxMemory: 4096,
}
setSettings(defaultSettings)
}
if (!settings) return null
return (
<div className="max-w-4xl mx-auto h-full flex flex-col gap-8">
<div className="flex items-center justify-between border-b border-saturn-border pb-6">
<div>
<h1 className="text-2xl font-bold">Performance Settings</h1>
<p className="text-sm text-saturn-text-secondary">Configure how Saturn Client interacts with your hardware.</p>
</div>
<div className="flex items-center gap-3">
<button
onClick={handleReset}
className="p-2 text-saturn-text-secondary hover:text-white transition-colors"
title="Reset to Defaults"
>
<RefreshCcw size={20} />
</button>
<button
onClick={handleSave}
disabled={isSaving}
className="btn-primary flex items-center gap-2 py-2 px-6 text-sm font-bold"
>
<Save size={16} />
{saveStatus || 'SAVE SETTINGS'}
</button>
</div>
</div>
<div className="grid grid-cols-1 gap-8">
{/* Memory Allocation */}
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
className="panel p-6 space-y-6"
>
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-saturn-accent/10 flex items-center justify-center text-saturn-accent">
<MemoryStick size={18} />
</div>
<h2 className="text-lg font-bold">Memory Allocation</h2>
</div>
<div className="space-y-4">
<div className="flex justify-between items-center">
<span className="text-sm font-medium">Maximum Memory (RAM)</span>
<span className="text-lg font-bold text-saturn-accent">{(settings.maxMemory / 1024).toFixed(1)} GB</span>
</div>
<input
type="range"
min="1024"
max="16384"
step="512"
value={settings.maxMemory}
onChange={(e) => setSettings({ ...settings, maxMemory: parseInt(e.target.value) })}
className="w-full h-2 bg-saturn-border rounded-lg appearance-none cursor-pointer accent-saturn-accent"
/>
<div className="flex justify-between text-[10px] text-saturn-text-secondary font-bold uppercase tracking-widest">
<span>1 GB</span>
<span>4 GB</span>
<span>8 GB</span>
<span>12 GB</span>
<span>16 GB</span>
</div>
<div className="p-3 bg-blue-500/5 border border-blue-500/10 rounded-lg flex gap-3">
<Info size={16} className="text-blue-400 shrink-0 mt-0.5" />
<p className="text-xs text-blue-300/80 leading-relaxed">
Allocating too much memory can cause system instability, while too little can lead to performance issues or crashes. 4GB - 8GB is recommended for most users.
</p>
</div>
</div>
</motion.div>
{/* JVM Arguments */}
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.1 }}
className="panel p-6 space-y-6"
>
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-saturn-accent/10 flex items-center justify-center text-saturn-accent">
<Cpu size={18} />
</div>
<h2 className="text-lg font-bold">Custom JVM Arguments</h2>
</div>
<div className="space-y-4">
<p className="text-xs text-saturn-text-secondary leading-relaxed">
Advanced flags for the Java Virtual Machine. Saturn Client includes optimized defaults, but you can override them here.
</p>
<textarea
value={settings.jvmArguments}
onChange={(e) => setSettings({ ...settings, jvmArguments: e.target.value })}
className="w-full h-32 bg-saturn-bg border border-saturn-border rounded-lg p-4 text-sm font-mono text-saturn-text-secondary focus:outline-none focus:border-saturn-accent/50 focus:ring-1 focus:ring-saturn-accent/50 transition-all resize-none"
placeholder="-XX:+UseG1GC..."
/>
<div className="p-3 bg-yellow-500/5 border border-yellow-500/10 rounded-lg flex gap-3">
<AlertTriangle size={16} className="text-yellow-500 shrink-0 mt-0.5" />
<p className="text-xs text-yellow-500/80 leading-relaxed">
Incorrect JVM arguments can prevent the game from starting. Only modify if you know what you're doing.
</p>
</div>
</div>
</motion.div>
</div>
</div>
)
}
export default SettingsSection