File size: 1,457 Bytes
ececfe6 b66ef35 ececfe6 b66ef35 ececfe6 b66ef35 ececfe6 b66ef35 ececfe6 d9c705e b66ef35 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 |
import Dexie, { type Table } from 'dexie';
import type { Monster, PicletInstance, Encounter, GameState } from './schema';
export class PicletDatabase extends Dexie {
// Legacy table
monsters!: Table<Monster>;
// New game tables
picletInstances!: Table<PicletInstance>;
encounters!: Table<Encounter>;
gameState!: Table<GameState>;
constructor() {
super('PicletGameDB');
this.version(1).stores({
monsters: '++id, name, createdAt'
});
// Version 2: Add imageData field
this.version(2).stores({
monsters: '++id, name, createdAt'
}).upgrade(tx => {
// No data migration needed, just schema update
return tx.table('monsters').toCollection().modify(monster => {
monster.imageData = monster.imageData || null;
});
});
// Version 3: Add stats field
this.version(3).stores({
monsters: '++id, name, createdAt'
}).upgrade(tx => {
// No data migration needed, just schema update
return tx.table('monsters').toCollection().modify(monster => {
monster.stats = monster.stats || null;
});
});
// Version 4: Add new game tables
this.version(4).stores({
monsters: '++id, name, createdAt',
picletInstances: '++id, typeId, nickname, isInRoster, rosterPosition, caughtAt',
encounters: '++id, type, createdAt',
gameState: '++id, lastPlayed'
});
}
}
export const db = new PicletDatabase(); |