onegameCookbook
onegame cookbook
Short recipes for common onegame tasks, each with complete code you can copy.
Recipes
Automated game testing with scenariosWrite game tests as YAML scenarios that click, press keys, send commands and step frames, then check state, UI, sounds and pictures, and run them headless in CI with onegame test.Record and replay a gameRecord a run of a C# game to a file, replay it later and check every tick’s state hash, and find the first tick where a code change makes the game behave differently.Screenshot tests for a gameCapture frames of a C# game headless, compare them with reference images at a tolerance in a scenario, update the references when a change is intended, and capture a sequence of frames.Deterministic simulation in C#Keep a game’s simulation deterministic with fixed-point numbers and named random streams, and let the analyzers turn floats, clocks, System.Random and view writes into compile errors.Test a game from C#Write xUnit tests for a C# game with onegame’s test API: drive a headless game by id and command, run scenario files, and prove determinism with RunTwice, SnapshotRestore and Replay.Start tests from fixtures and snapshotsGive tests a ready-made world with named fixtures, save a running game as a snapshot, and start a scenario from either, instead of playing up to the interesting moment every time.Client/server sync with a dedicated serverMake a C# game with a dedicated server, export the server as a NativeAOT program, run it with two clients over UDP and WebSocket on a simulated network, and check that every replica agrees with the server.Client-side predictionShow a player’s command on their own screen at once while the server decides, with predicted commands, a predicted world beside the replica, and rollback when the server disagrees.Drive a running game over MCPControl a running Debug build of a C# game from an MCP client or a script: read state, click by id, step time, send commands, load fixtures and capture frames over the onegame live-control protocol.Build a game screen with the UI kitBuild a C# game screen from the onegame component kit: a table of items bound to synced state, a primary button, a confirm dialog, a theme with your own accent, and scenarios that click through it.Controller and keyboard navigationMake a game screen playable with a gamepad and a keyboard: a default focus, d-pad movement, confirm and back, focus that stays inside a dialog, and scenarios that play the screen with a controller.Check UI contrastCheck a game UI theme against WCAG 2.x AA contrast from the command line or a test, read which token pairs fail, and pick an accent that passes.Export for Linux, Windows and macOSPackage a C# game for Linux, Windows and macOS with onegame export: NativeAOT where the host allows it, a folder and an archive per target, and a JSON report of every file to check in CI.Ship a game for Steam and the Steam DeckExport a C# game for Steam on Linux and Windows with the Steamworks library beside it, and build a Linux program that starts on the Steam Deck’s runtime.Export for the web, Android and iOSWhat the web, Android and iOS exports need at onegame 1.1.2: an engine checkout for all three, plus the Android SDK or a Mac with Xcode, and what each export produces.