Skip to content

Add ChessgroundAssets Swift package#92

Merged
veloce merged 3 commits into
lichess-org:mainfrom
r3econ:ios-spm-package-with-image-resources
Apr 13, 2026
Merged

Add ChessgroundAssets Swift package#92
veloce merged 3 commits into
lichess-org:mainfrom
r3econ:ios-spm-package-with-image-resources

Conversation

@r3econ

@r3econ r3econ commented Apr 13, 2026

Copy link
Copy Markdown

Adds a Swift Package Manager package that exposes the same board textures, piece images, and theme colour data that the Dart side already ships — so iOS/macOS native targets (e.g. WidgetKit extensions) can consume them without a copy script.

What's included

Package.swift — SPM manifest at the repo root. Declares a single ChessgroundAssets library targeting iOS 16+ / macOS 13+.

swift/Sources/ChessgroundAssets/

  • ChessgroundAssets.swift — exposes ChessgroundAssets.bundle for loading assets: Image("board_wood2", bundle: ChessgroundAssets.bundle)
  • ChessboardTheme.swift — public ChessboardTheme struct that maps Dart theme names to light/dark square colours, last-move highlight colour, board image name, and piece set. Mirrors the ChessboardColorScheme constants in board_color_scheme.dart.
  • Assets.xcassets/ — generated Xcode asset catalog: 21 board texture imagesets and 468 piece imagesets (39 sets × 12 pieces, each with 1x/2x/3x).

scripts/gen-swift-xcassets.sh — regenerates the asset catalog from assets/ whenever boards or piece sets change. No Flutter tooling needed — reads directly from the repo. Run it and commit the result before cutting a new release tag.

.gitignore — added .build/ and .swiftpm/ (SPM artifacts generated at the repo root).

README.md — new "Swift Package (iOS/macOS)" section documenting the dependency, asset naming conventions, ChessboardTheme API, and how to maintain the xcassets.

Motivation

The lichess mobile app's WidgetKit extension previously copied assets out of the pub cache via a shell script, creating a fragile coupling between the iOS build and Flutter tooling. With this package, the extension declares a normal SPM dependency on this repo — assets are versioned alongside the Dart package and consumers just update the SPM version tag when chessground is upgraded.

Asset naming

Type Pattern Example
Board texture board_{name} board_blueMarble, board_wood3
Piece image piece_{set}_{color}{kind} piece_staunty_wK, piece_california_bQ

name matches the ChessboardColorScheme Dart constant. set is the camelCase PieceSet enum .name value. The mono piece set is excluded (non-standard file layout).

@veloce

veloce commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

Looks good! Thanks you very much.

@veloce veloce merged commit 79be6bb into lichess-org:main Apr 13, 2026
1 check passed
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