README
¶
Hearthkeeper: an idle game template
An idle game built with NSGo and github.com/nsgo-dev/game. You keep a fire alive: stoking it gathers embers, generators make embers every second, upgrades multiply them and automate the fuel, the hearth keeps earning while the game is closed, scattering the ashes restarts the run for a lasting bonus, and lighting the Everflame wins. A fire left without fuel goes out, which loses the run.
It shows:
idle.Numberfor every amount, so costs and production run past float64 without changing the code, andidle.Formatfor writing them in short (1.23M), letter, scientific and engineering notation.idle.Offlinefor progress while the game is closed or in the background, capped and at half rate, replayed in fixed steps so the fire can run dry while you are away just as it can while you watch.save.Storefor a versioned JSON save in the app's storage, with a backup copy and a check that refuses a save the game cannot use.gameuifor the shop drawn on the canvas, with spatial focus navigation for the keyboard and controllers, and touch and mouse presses on the same widgets.game.yaml's input map binding keys and controller buttons to actions, and a fixed-stepgame.Loop.- Headless
nsgotesttests that play the game to a win and to a loss with touch, mouse, keyboard and a controller.
The game's settings live in game.yaml, its project file. Edit the name and identifier there before shipping it, then write them into nsgo.yaml and check the project:
go run github.com/nsgo-dev/game/cmd/gameproject sync
go run github.com/nsgo-dev/game/cmd/gameproject check
Playing
| Keyboard | Controller | Touch and mouse | |
|---|---|---|---|
| Stoke the fire | Space | West (X on Xbox, □ on PlayStation) | Tap the hearth |
| Move the focus | Arrow keys or W, A, S, D | D-pad | |
| Press the focused control | Enter | South (A, ✕) | Tap the control |
| Close a card | Enter or Escape | South or East | Its button |
| Switch the notation | N | North (Y, △) | The button at the top right |
Buy the Bellows and the Coal Chute early: until the fire feeds itself, it burns out within a hundred seconds unless you stoke it, and leaving it unfed while away loses the run too.
Running and testing
Run with hot reload on your desktop:
go tool nsgo dev
Run on other targets:
go tool nsgo dev -target web
go tool nsgo dev -target ios_simulator
go tool nsgo dev -target android
Run the headless tests, and vet across platforms:
go tool nsgo test ./...
go tool nsgo check -target macos,windows,linux,android,web
Build release artifacts into dist/:
go tool nsgo build -target macos_arm64,windows_x64,linux_x64,web
Layout
hearth.yaml: the balance. Fuel, generators, upgrades, prestige, the goal and the offline rules are all here, versioned and checked when the game starts; change the numbers here rather than in code.data.go: reads, checks and writeshearth.yaml.sim.go: the rules, with no view and no clock: stoking, buying, production, fuel, prestige, winning and the offline replay. Everything else calls into it.save.go: the save slot, by generator and upgrade id so reorderinghearth.yamlkeeps saves.game.go: the NSGo side: the loop, the input actions, saving, crediting time away and the native HUD and cards.shop.go: thegameuishop on the canvas and the drawn hearth.game.yaml,project.go: the project file, with the virtual resolution and the input map, andProject.main.go: the entry point.*_test.go: the rules and the balance (sim_test.go), the data file (data_test.go), playthroughs with every input (game_test.go) and the project file (project_test.go).
Where to change it
- New generator or upgrade: add it to
hearth.yaml; the shop shows it. A new kind of upgrade effect is a constant indata.go, a case invalidate, and a line wheresim.goapplies it. - Pace:
TestBalanceReachesTheGoalplays the game with a simple strategy and fails when the goal comes too early or too late, so it tells you what a change tohearth.yamldid. - New saved state: add a field to
savedGame, raisesaveVersionand register a migration withsave.WithMigration. - Art: replace
drawFlameinshop.go, or thegameuitheme innewShop.