Skip to content

Feature: Integrate SBN v2 encoding with base-85 codec and compound history support#28

Open
itadrous73 wants to merge 12 commits intomainfrom
WASN01
Open

Feature: Integrate SBN v2 encoding with base-85 codec and compound history support#28
itadrous73 wants to merge 12 commits intomainfrom
WASN01

Conversation

@itadrous73
Copy link
Copy Markdown
Collaborator

@itadrous73 itadrous73 commented Apr 14, 2026

Integrates the SBN v2 encoder/decoder across the desktop and mobile applications,
replacing all v1 encoding call sites while maintaining full backward compatibility
with existing v1 puzzle strings and saved data. This is tracked by branch WASN01.

What changed

  • All encodeToSbn() calls replaced with encodeToSbnV2() (9 call sites)
  • All universalImport() calls replaced with universalImportV2() (2 call sites)
  • encodeURIComponent() added to desktop URL construction for base-85 URL safety
  • sbn.js added to both desktop and mobile script loading
  • Mobile service worker updated to cache sbn.js for offline/PWA support
  • Service worker VERSION bumped.

Why

SBN v2 provides:

  • Base-85 encoding (6.41 bits/char vs 6.00) for ~6% smaller region strings
  • 4-cell annotation packing (3⁴=81 ≤ 85) for ~25% smaller annotation strings
  • Compound history entries that preserve atomic undo/redo groups — importing a
    shared puzzle where placeStarAndAutoX modified 9 cells now undoes as a single
    step instead of 9 individual steps
  • Unlimited grid dimensions (plain decimal vs lookup table)

Backward compatibility

  • v1 strings (start with letters, e.g. AA2e...) are auto-detected by
    universalImportV2() and delegated to the existing universalImport()
  • v1 strings with numeric dim codes (4499, i.e. 4×4 through 9×9 boards)
    are disambiguated from v2 via a length check: the main part (before ~) is
    compared against the minimum v2 string length for that candidate dimension.
    Since v2 dim-44+ requires 594+ chars and a v1 4×4 string is at most ~14 chars,
    the gap is unambiguous
  • v2 strings (start with digits, e.g. 10B...) are decoded natively
  • Old localStorage saves load via v1 fallback; re-saving writes v2 format
  • All v1 function definitions and constants (SBN_CODE_TO_DIM_MAP, etc.) are
    kept intact — nothing was removed
  • decodeSbn() calls for puzzle file loading are untouched (different contract)

Updated version number to 2.3.1 and added SBN v2 script.
Updated the API documentation and improved the updateUrlWithSbn function to use encodeURIComponent for SBN strings.
Updated the API management script for the Star Battle application to version 1.2.1, including improvements to puzzle fetching, importing, and exporting functionalities.
@itadrous73 itadrous73 self-assigned this Apr 14, 2026
Enhanced backward compatibility check for SBN v1 dimension codes.
Enhanced backward compatibility for v1 dimension codes in universalImportV2 function.
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