|
|
import Dexie, { type Table } from 'dexie'; |
|
|
import type { PicletInstance, ActivityEntry, GameState, TrainerScanProgress } from './schema'; |
|
|
|
|
|
export class PicletDatabase extends Dexie { |
|
|
|
|
|
picletInstances!: Table<PicletInstance>; |
|
|
activityEntries!: Table<ActivityEntry>; |
|
|
gameState!: Table<GameState>; |
|
|
trainerScanProgress!: Table<TrainerScanProgress>; |
|
|
|
|
|
constructor() { |
|
|
super('PicletGameDB'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.version(4).stores({ |
|
|
monsters: '++id, name, createdAt', |
|
|
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt', |
|
|
encounters: '++id, type, createdAt', |
|
|
gameState: '++id, lastPlayed' |
|
|
}); |
|
|
|
|
|
|
|
|
this.version(5).stores({ |
|
|
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt', |
|
|
encounters: '++id, type, createdAt', |
|
|
gameState: '++id, lastPlayed' |
|
|
}); |
|
|
|
|
|
|
|
|
this.version(6).stores({ |
|
|
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt', |
|
|
encounters: '++id, type, createdAt', |
|
|
gameState: '++id, lastPlayed', |
|
|
trainerScanProgress: 'imagePath, trainerName, status, completedAt' |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.version(7).stores({ |
|
|
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt', |
|
|
encounters: '++id, type, createdAt', |
|
|
gameState: '++id, lastPlayed', |
|
|
trainerScanProgress: 'imagePath, trainerName, status, completedAt' |
|
|
}); |
|
|
|
|
|
|
|
|
this.version(8).stores({ |
|
|
picletInstances: '++id, typeId, objectName, isCanonical, canonicalId, isInCollection, collectedAt, tier', |
|
|
activityEntries: '++id, type, createdAt, picletTypeId, discovererName, rarity', |
|
|
gameState: '++id, lastPlayed, lastActivityRefresh', |
|
|
trainerScanProgress: 'imagePath, trainerName, status, completedAt' |
|
|
}).upgrade(tx => { |
|
|
|
|
|
return tx.table('picletInstances').toCollection().modify(piclet => { |
|
|
|
|
|
piclet.objectName = piclet.typeId || 'unknown'; |
|
|
piclet.isCanonical = false; |
|
|
piclet.isInCollection = piclet.caught || false; |
|
|
piclet.collectedAt = piclet.caughtAt || new Date(); |
|
|
piclet.scanCount = 1; |
|
|
piclet.discoveredAt = piclet.caughtAt || new Date(); |
|
|
|
|
|
delete piclet.caught; |
|
|
delete piclet.caughtAt; |
|
|
delete piclet.isInRoster; |
|
|
delete piclet.rosterPosition; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
export const db = new PicletDatabase(); |