Skip to content

Smart Sync: keep Owned blueprints the same across PCs (#567) - #598

Draft
Osiris-DevWorks wants to merge 1 commit into
release/3.1.0from
claude/project-thread-vswdni
Draft

Osiris-DevWorks wants to merge 1 commit into
release/3.1.0from
claude/project-thread-vswdni

Conversation

@Osiris-DevWorks

Copy link
Copy Markdown
Owner

Requested by Amr · project thread

Closes #567.

What it does

Blueprints earned on one PC now show as Owned on the others. The player picks a folder their cloud app already syncs (Google Drive for Desktop, OneDrive, Dropbox, a NAS) in Config > Smart Sync, and picks the same folder on their other PCs. Smart Citizen makes no network calls itself.

  • One file per PC. Each PC writes only <folder>\Smart Citizen Sync\machine-<8 random hex>.json and reads all of them, so the cloud app never has to resolve a conflict. Files are written in one step (atomic_io). A conflicted copy the cloud app makes anyway is read like the rest.
  • Newest change per blueprint wins. Each entry holds owned or not and when it changed (UTC, microseconds). Moving a blueprint back to Available is a change too, so the next sync does not bring it back. What a PC already owned when it first turns sync on goes in at the epoch, so any real change on any PC beats it.
  • When it runs. At startup, 3 s after every Owned change (scan, overlay, tracker click, starter seed: all end in _recompute_owned), whenever a QFileSystemWatcher sees another PC's file change, and at close for a change still waiting. The read/merge/write runs on SmartSyncWorker; the owned set is only written on the GUI thread.
  • What syncs: the owned set and the starter seed marker (union of loc keys). Not the log-scan watermark, paths, caches, user.ini or global.ini. Each PC still builds its own global.ini.

Changes

  • src/utils/smart_sync.py (new, Qt-free): ledger record / baseline / merge, file encode / decode, sync().
  • src/utils/settings.py: smart_sync/folder, machine_id, owned_ledger, last_written, all in PROFILE_EXCLUDE_KEYS so a backup restored on another PC never brings this PC's id. set_owned_items records into the ledger while sync is on. import_values adds a backup's owned set while sync is on instead of replacing it (a replace would read as every newer blueprint moved back, and sync would spread that to every PC). With sync off, Import behaves as before.
  • src/gui/workers.py: SmartSyncWorker (errors at WARNING, so no error box).
  • src/gui/main_window.py: the sync hooks, _take_smart_sync_result (merges the local ledger once more so a change made during the sync wins), close handling.
  • src/gui/config_tab.py: Smart Sync group: folder field (read-only), Browse, Turn Off, status line. Retranslates.
  • UI strings (13 keys) in every language, English in ht, AI text in at. HELP.md bullet in every language.
  • CLAUDE.md, src/utils/CLAUDE.md, src/gui/CLAUDE.md, tests/CLAUDE.md entries.

Decisions worth a look

  1. No pull right before Apply. The design said "pull before Apply". The folder watcher pulls as soon as another PC's file lands, so Apply already sees it, without making Apply wait on a cloud folder. Easy to add if wanted.
  2. Copied portable folder. Two installs with the same id would write one file. If this PC's file has a newer updated than it last wrote, it takes a new id and keeps merging.
  3. Mixed languages. Owned names are display names. Two PCs in different game languages will each rename the other's names on load (Blueprint Tracker: Owned names stay in the language they were added in #569), which shows up as extra churn in the files. Each PC's own list stays right. Keying the ledger by loc key would fix it; left for later.
  4. Clocks. Newest-wins trusts each PC's clock. Windows keeps them in sync, so this should be fine.

Tests

  • tests/test_smart_sync.py: 47 tests (core, settings, worker on a real thread, the window's result handling). All pass locally.
  • Full suite run locally on Linux before and after the change: the same 942 Windows-only failures in both runs, no new ones. CI on Windows is the real check.

Manual test (two PCs, or two data folders on one PC)

  1. PC A: Config > Smart Sync > Browse, pick a folder in Google Drive / OneDrive. Status shows "Last synced at ...".
  2. PC B: pick the same folder. PC A's owned blueprints appear on B's Blueprint Tracker.
  3. Own a new blueprint on B. Within a few seconds of the cloud app syncing, it shows on A.
  4. Move a blueprint back to Available on A. It leaves B's Owned list too and stays gone.
  5. Turn Off on one PC: its list stays as it is.

The tester Test Plan (test_plan.py) still covers 3.0.0. I left that to the pre-release refresh.


Generated by Claude Code

Share the owned blueprints through a folder the player's cloud app
already syncs. Each PC writes only its own machine-<id>.json in a
'Smart Citizen Sync' folder and reads everyone's; the newest change per
blueprint wins, so a blueprint moved back to Available stays there.

- src/utils/smart_sync.py: Qt-free ledger, merge and folder sync
- AppSettings: smart_sync/* keys (excluded from backups), the ledger
  recorded by set_owned_items, Import Settings adds while sync is on
- SmartSyncWorker; MainWindow syncs at startup, after Owned changes,
  when the folder changes, and pushes a pending change at close
- Config tab: Smart Sync folder picker, Turn Off, status line
- UI strings and HELP in every language (AI text for non-English)
- tests/test_smart_sync.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011hqxFfzZY3bs9NpC8k6upk
@Osiris-DevWorks Osiris-DevWorks self-assigned this Nov 20, 2026
@Osiris-DevWorks Osiris-DevWorks mentioned this pull request Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants