Game rendering depends on an imported asset set derived from original Civilization files (TER257.PIC, SP257.PIC).
Without imported assets, gameplay options are hidden and import is the primary onboarding flow.
src/js/UI/components/ImportAssetsWindow.ts- UI flow for selecting source files and triggering extraction.
src/js/UI/AssetStore.ts- IndexedDB-backed storage and in-memory cache of extracted assets.
@civ-clone/civ1-asset-extractor- External package that performs sprite extraction from source files.
- User opens Import Assets from main menu.
- UI validates selected filenames against extractor definitions (
extract-data.json). - For each file:
- Reads binary string via
FileReader. - Runs
extractSprites(...)with matching definitions. - Receives records
{ name, uri }.
- Reads binary string via
- Records are persisted via
assetStore.set(record)into IndexedDB storeciv-clone-assets. assetStore.hasAllAssets()validates required set.- On success, page reloads to reinitialize UI with assets present.
AssetStore extends generic Store wrapper and provides:
- Persistent storage (
idb) keyed by assetname. - In-memory caches:
- raw asset records
HTMLImageElementinstances- scaled canvas results (
getScaled)
- Required-asset list (
#requiredAssets) used as runtime readiness check.
- Main menu checks
assetStore.hasAllAssets()to gate gameplay options. - Renderer sets custom cursor using scaled imported asset.
- Map and window components resolve image assets from
AssetStoreby canonical path.
- Missing required files produces explicit translated error in import window.
- Optional "replace existing" allows re-extracting even if assets exist.
- Browser-specific caveat: Brave fingerprinting can distort imported visuals (noted in README).
- Required asset list is static and large, so any mismatch in naming/path conventions fails readiness.
- Isolate extraction, validation, and persistence into a dedicated asset service module.
- Version the asset schema (to support future tilesets/asset packs).
- Move required-asset manifest to declarative data file instead of hardcoded class field.
- Preserve IndexedDB caching, but add migration strategy for asset format changes.