Repository navigation
PWA3: Remember pinned work areas per settlement in a local file - #10
Merged
Merged
Conversation
Pins used to reset on every load, map exit and co-op resync. They now come back when any save of the same settlement loads. They are read from Documents/Timberborn/PersistentWorkAreas/Pins.txt (the game's UserDataFolder), never from or into the save, so each co-op player keeps their own and nothing changes what BeaverBuddies sends on a join or resync. - PinStore (Unity-free, linked into the checks) owns the file format: one line per settlement with its escaped name and the pinned buildings' entity ids. The save keeps each entity id, so a pin finds the reloaded building by id, not by the runtime object. A missing, corrupt or unrecognized file remembers nothing, and damaged lines are skipped. Only the 100 most recently changed settlements are kept, because a co-op guest's settlement is renamed after the host's map on every join. - PinFile reads the file and swaps in a rewritten copy. - PinSet now marks itself changed on every pin, unpin, clear or deletion. WorkAreaService writes the file from UpdateSingleton after a change (a new game's pins wait until the settlement is named), and restores the pins once at PostLoad through EntityRegistry.GetEntity and Supports. Leaving the map, loading and a renderer failure save a pending change first and never erase the file. - No save, tick or persistence interface is added. A new check asserts that no mod type implements one and that the mod never references the game's save writers. Display only: nothing reaches the simulation or the save. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…vice wiring Review follow-ups for the per-settlement pin file. - Loading a settlement now moves its entry to the top of the pin file (at the first update, with its remembered ids unchanged). The 100-settlement cap therefore evicts by last use, not last change, so throwaway co-op guest settlements no longer push out a settlement whose pins were set once and never changed. - A failed write keeps the change pending and is retried 10 seconds later and again on leaving the map; only the first failure per map is logged. Before, the change was marked saved before the write, so one failure lost it until the next pin change. - A pin file this version cannot read (a newer format, or damage) is copied to Pins.txt.bak before it is replaced, and the header comment says how a later format stays readable by this one. - The service's own wiring is now checked outside the game. RestorePins takes the pinnability test (PostLoad passes Supports, which needs live game objects), and UpdateSingleton only reads Time.unscaledTime and hands it to UpdateAt. New checks on the live instance cover restore through the game's EntityRegistry (drawn, not counted as a change, nothing written at load), the first update keeping ids this save lacks, and the frame update saving with nothing to draw and retrying after a failure. New game-free checks cover the move-to-top, the cap by last use, the backup copy, and a hand-edited file with a repeated settlement and repeated or empty ids. - README gives the location relative to the Saves folder (macOS differs) and says a guest's pins usually do not come back. VALIDATION adds the in-map file, exit-to-desktop and older-then-newest-save steps. Display only: nothing reaches the simulation or the save. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
kramsey458
changed the base branch from
claude/planting-tool-ranges
to
main
September 22, 2026 16:43
- WorkAreaService constructor: keep PWA2's ILoc alongside PWA3's EntityRegistry and SettlementReferenceService, and keep the localized clear button next to the pin-file restore in PostLoad. - tests/Program.cs: keep the PinStore checks above the game-free split, raise GameChecks to 65, and allow the pin file's format, file names and argument-check text in the hard-coded UI text check. Full run: 142/142; no-argument run: 77 passed, 65 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pinned work areas used to reset on every load, map exit and co-op resync. With this PR, each settlement's pins are remembered on the player's own computer, in
PersistentWorkAreas\Pins.txtnext to the TimberbornSavesfolder (on Windows,Documents\Timberborn\PersistentWorkAreas\Pins.txt). They come back when any save of that settlement loads.Pins are never read from or written into the save, and no save, tick or persistence interface is added. Each co-op player therefore keeps their own pins, and nothing changes in what BeaverBuddies sends on a join or resync. The feature is display only.
Items
PWA3: restore pins from a local per-settlement file (stretch)
What changed
PinStore(new, Unity-free, linked intotests/Checks.csproj) defines the file format:EntityIdGUIDs, separated by tabs.PinFilewrites to a temporary file, then swaps it in withFile.ReplaceorFile.Move, so an interrupted write never leaves half a file. If the existing file has an unrecognized header (a newer format, or damage), it is first copied toPins.txt.bak.PinSet.Changedis set by everySetorClearthat changes the set. That covers pin, unpin, clear, deletion and dropped pins without separate bookkeeping.WorkAreaService:PostLoad, pins are restored once throughEntityRegistry.GetEntityplusSupports. Restoring does not count as a change, so the file keeps any remembered buildings this particular save lacks.Reset(called fromDisposeon the loading screen, and on a renderer failure) saves any pending change first, then forgets the pins in memory only. Leaving the map never erases the file.UpdateSingletonnow only readsTime.unscaledTimeand passes it toUpdateAt(now).RestorePinstakes the pinnability test as a parameter. Both changes let the checks run the real wiring outside the game.PostLoad, in the frame update, and inDispose/Reset.OnDeleted, which can fire inside a tick, only sets the in-memoryChangedflag.Tests that prove it (
tests/Program.cs, 38 new checks)PinSet.Changedmarking.Restoreresolves by id, drops unknown ids, removes duplicates and respectsSupports.PinFileon a temporary folder: no file, round-trip with folder creation, move-to-top on disk, and a corrupt or newer-format file replaced with a.bakcopy and no.tmpleft behind.WorkAreaServiceinstance, with a temporary pin file and the game's realSettlementReferenceService,SettlementReferenceandEntityRegistrytypes (9):Resetsaves the pending change and never erases the file.EntityRegistrypins only this settlement's pinnable buildings, adds them to the outline planner, and writes nothing at load.UpdateAtsaves even with nothing to draw, and retries a failed write after 10 seconds.Fail before, pass after
PinStore,PinFileandPinSet.Changedare missing (CS0103, CS0246 and CS1061). Reverting onlyWorkAreaService.csfails at the first live-instance pin check.Changedset, or skips the planner;Resetskips the pending save;.bak, or a.bakof every file;PostLoadnot callingRestorePins(Supports), or passing_ => true(in-game steps 1 and 4 below). The third is the temp-file swap, which cannot be checked cheaply.Tests
build.ps1thentests/Checks.csprojwith game filesThe checks write only to
%TEMP%, never to the real Documents folder.Co-op impact
SettlementReference.SettlementName:ClientConnectionService.LoadMap), so a guest's pins usually do not come back. The name changes with every resync. Rejoining the very same host save file would bring them back, which is harmless.UpdateSingletonthrough the same path as manual pins. Only the timing is new: the first frame after a load.Proposed CHANGELOG lines
PersistentWorkAreas\Pins.txtnext to your TimberbornSavesfolder, and come back when you load that settlement. They are never written into the save, so each co-op player keeps their own.Needs in-game / two-player testing
Pins.txtlists one more id. Press Clear pinned areas: the line disappears.Pins.txtexists, and noPins.txt.tmpis left behind.Player.loghas no[PersistentWorkAreas] Pinned areas not ...warnings.Review
Three adversarial reviewers approved (determinism and lockstep; save compatibility and cross-mod interaction; is the test real). Each rebuilt the branch and reproduced 126/126 at 30f2a64.
Fixed in bce50b0
_pins.Changed = falseat the end of restore was untested, and it protects the older-save behaviour. Also untested: restore feeding the planner, and the frame update saving at all.RestorePinsnow takes the pinnability test, andUpdateSingletonpasses the clock toUpdateAt, so the live-instance checks run both. The reviewer's surviving mutants N2 to N6 are now killed.Pins.txt.bakfirst, and the header comment says how a later format should stay readable.Savesfolder, because macOS's UserDataFolder is~/Documents/Documents/Timberborn. "A guest's pins do not come back" is softened to "usually".Declined or deferred
Random, so after hosting the same save twice, a remembered id could name a different building. This is unconfirmed, display only and rare. The cross-settlement "guest fallback" that would widen it was not adopted. Storing a template name next to each id was not added, because it needs live components to test. It is recorded here as a known limitation.docs/website. Not edited, because the site describes the released 1.0.0 build. Its last change was dfd40ac (Docs: finish the 1.0.0 wording pass #5), not the release commit as an earlier note said. At release, update these pages:faq.html(#saves, "Pins aren't saved at all", and the reset answer);index.html:167;install.html:135, plus the Uninstalling paragraph at line 138, which should mention thePersistentWorkAreaspin folder;troubleshooting.html:145,207.The "38 checks" counts in README and VALIDATION are also release-time edits (135 on this stack).
Merge notes for the other open PRs
CI: run the pin-logic checks without the game on GitHub Actions #7 (checks-ci). git merges it cleanly, and its
args.Length == 0guard lands correctly, after all game-free checks. This corrects an earlier note that said the PinStore checks would be skipped in CI. ItsGameChecks = 27must become 58 on this stack, or the full run fails its count guard. The no-argument run then reports 77 game-free checks.PWA2: Localize the work-area panel and clear-button text #8 (localize-ui). It conflicts in
source/WorkAreaService.cs: constructor parameters (ILocplusEntityRegistryandSettlementReferenceService) andNotify. Its "No hard-coded English UI text" check will also flag this PR's non-UI literals:"Persistent Work Areas pins v1","PersistentWorkAreas","Pins.txt",".tmp",".bak");"D";ArgumentExceptiontext and itsnameof;": "in the two warnings.Whichever PR lands second must teach
IsCodeabout these literals.🤖 Generated with Claude Code