File size: 3,122 Bytes
ececfe6 565e57b ececfe6 b66ef35 1f2c086 b66ef35 565e57b b66ef35 5435413 ececfe6 b66ef35 ececfe6 1f2c086 d9c705e 1f2c086 d9c705e 1f2c086 b66ef35 1f2c086 b66ef35 1f2c086 5435413 60e0688 565e57b ececfe6 b66ef35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import Dexie, { type Table } from 'dexie';
import type { PicletInstance, ActivityEntry, GameState, TrainerScanProgress } from './schema';
export class PicletDatabase extends Dexie {
// Game tables
picletInstances!: Table<PicletInstance>;
activityEntries!: Table<ActivityEntry>;
gameState!: Table<GameState>;
trainerScanProgress!: Table<TrainerScanProgress>;
constructor() {
super('PicletGameDB');
// Version 1: Legacy monsters table (removed in v5)
// Version 2: Legacy monsters table with imageData (removed in v5)
// Version 3: Legacy monsters table with stats (removed in v5)
// Version 4: Add new game tables with legacy monsters
this.version(4).stores({
monsters: '++id, name, createdAt',
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt',
encounters: '++id, type, createdAt',
gameState: '++id, lastPlayed'
});
// Version 5: Remove legacy monsters table
this.version(5).stores({
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt',
encounters: '++id, type, createdAt',
gameState: '++id, lastPlayed'
});
// Version 6: Add trainer scanning progress table
this.version(6).stores({
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt',
encounters: '++id, type, createdAt',
gameState: '++id, lastPlayed',
trainerScanProgress: 'imagePath, trainerName, status, completedAt'
});
// Version 7: Move schema updated to include complete Move data (priority, flags, effects)
// No schema changes needed - just expanded interfaces, data will be preserved
this.version(7).stores({
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt',
encounters: '++id, type, createdAt',
gameState: '++id, lastPlayed',
trainerScanProgress: 'imagePath, trainerName, status, completedAt'
});
// Version 8: Discovery system - replace encounters with activity, update piclet fields
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 => {
// Migrate existing data
return tx.table('picletInstances').toCollection().modify(piclet => {
// Map old fields to new
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();
// Remove old fields
delete piclet.caught;
delete piclet.caughtAt;
delete piclet.isInRoster;
delete piclet.rosterPosition;
});
});
}
}
export const db = new PicletDatabase(); |