Files

71 lines
2.8 KiB
C#
Raw Permalink Normal View History

using System;
namespace GladiatorIdle
{
/// <summary>
/// MonoGame-Prototyp: ein Echtzeit-Duell in der Arena, mit lebendiger Darstellung.
/// Gleiche Test-Schalter wie das Hauptspiel (--shot, --lang, --class, --sim, --windowed, --size).
/// </summary>
internal static class Program
{
[STAThread]
public static void Main(string[] args)
{
L.Load();
AppSettings.Load();
AppSettings.ApplyVolumes();
DevShot.Parse(Environment.GetCommandLineArgs());
if (DevShot.Lang is L.Lang devLang) L.UseForSession(devLang);
// erster Start: Sprache des Systems (de/es, sonst en); später in den Einstellungen änderbar
else if (!DevShot.Active && !L.HasSavedLanguage)
{
string sys = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
L.Set(sys == "de" ? L.Lang.De : sys == "es" ? L.Lang.Es : L.Lang.En);
}
if (DevShot.Active) SoundManager.Enabled = false; // Testläufe stumm
if (DevShot.Playtest) { Playtest.Run(); return; }
AppDomain.CurrentDomain.UnhandledException += (_, e) => CrashLog(e.ExceptionObject as Exception);
try
{
using var game = new ArenaGame();
_game = game;
game.Run();
}
catch (Exception ex)
{
CrashLog(ex);
throw;
}
finally
{
SoundManager.StopAll();
SoundManager.Shutdown();
}
}
static ArenaGame? _game;
static bool _crashed;
/// Absturz: erst den Spielstand sichern, dann die Ursache nach %AppData%\GladiatorIdle\crash.log
/// (die neueste oben). Testläufe schreiben ins Protokoll des Laufs.
static void CrashLog(Exception? ex)
{
if (_crashed) return;
_crashed = true;
try { _game?.SaveNow(); } catch { /* Spielstand nicht sicherbar */ }
try
{
string text = $"=== {DateTime.Now:yyyy-MM-dd HH:mm:ss} {typeof(Program).Assembly.GetName().Version}\n{ex}\n\n";
if (DevShot.Active) { DevShot.Log("CRASH " + ex); return; }
string dir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GladiatorIdle");
System.IO.Directory.CreateDirectory(dir);
string file = System.IO.Path.Combine(dir, "crash.log");
string old = System.IO.File.Exists(file) ? System.IO.File.ReadAllText(file) : "";
System.IO.File.WriteAllText(file, text + (old.Length > 200_000 ? old[..200_000] : old));
}
catch { /* nichts mehr zu tun */ }
}
}
}