using System.Numerics; using Raylib_cs; namespace OnekoOnline; static class OnekoOnline { public static readonly ConfigFile Config = new("config.conf"); public static Net.Server? Server; public static Net.Client? Client; public static readonly int WindowX = 320; public static readonly int WindowY = 240; public static readonly int WindowScale = Config.GetValue("WindowScale", 2); public static Vector2 Resolution => new(WindowX, WindowY); public static readonly bool SpectatorMode = Config.GetValue("SpectatorMode", false); public static readonly bool HostServer = Config.GetValue("HostServer", false); public static readonly bool TransparentWindow = Config.GetValue("TransparentWindow", false); public static Font DefaultFont; public static string AppTitle { get => _appTitle; set { Raylib.SetWindowTitle(value); _appTitle = value; } } static string _appTitle = "Oneko Online"; public static void Main() { if (TransparentWindow) Raylib.SetConfigFlags(ConfigFlags.TransparentWindow); Raylib.InitWindow(WindowX*WindowScale, WindowY*WindowScale, AppTitle); Raylib.SetTargetFPS(30); Raylib.HideCursor(); MouseLocal LocalMouse = new(); if (!SpectatorMode) {OnekoLocal LocalOneko = new();} RenderTexture2D RenderTexture = Raylib.LoadRenderTexture(WindowX, WindowY); int port = Config.GetValue("ServerPort", 42069); string serverPassword = Config.GetValue("ServerPassword", ""); if (HostServer) { Server = new(port, Config.GetValue("ServerMaxUsers", 32)); Client = new("127.0.0.1", port, serverPassword); } else { string Address = Config.GetValue("ServerIP", "pond.sarahduck.ca"); if (string.IsNullOrEmpty(Address)) { Console.WriteLine("Server IP empty or invalid, you're offline."); AppTitle = "Oneko Offline"; } else Client = new(Address, port, serverPassword); } Net.Client.UserConnected += OnekoNet.SpawnNetNeko; Net.Client.UserConnected += MouseNet.SpawnNetMouse; DefaultFont = Raylib.LoadFont("misc/MPlusBitmap.fnt"); Color BackgroundColor = Color.Gray; if (TransparentWindow) BackgroundColor = BackgroundColor with {A = 0}; while (!Raylib.WindowShouldClose()) { //Poll networking Client?.Poll(); Server?.Poll(); Raylib.BeginTextureMode(RenderTexture); Raylib.ClearBackground(BackgroundColor); Raylib.DrawTextEx(DefaultFont, "こんにちは", new(17,18), 11, 0, Color.White); Raylib.DrawText(AppTitle, 10, 9, 8, Color.White); Drawable.DrawAll(); Raylib.EndTextureMode(); Raylib.BeginDrawing(); if (TransparentWindow) Raylib.ClearBackground(Color.Blank); //Dunno why, but it renders upside down, so I flip it here Raylib.DrawTexturePro(RenderTexture.Texture, new Rectangle(0f,0f,WindowX,-WindowY), new Rectangle(0,0,WindowX*WindowScale,WindowY*WindowScale), Vector2.Zero,0f,Color.White); Raylib.EndDrawing(); } Client?.Disconnect(); Server?.Disconnect(); Drawable.DisposeAll(); Raylib.CloseWindow(); Config.SaveFile(); } }