File size: 1,147 Bytes
ececfe6
1f2c086
ececfe6
b66ef35
1f2c086
b66ef35
 
 
ececfe6
 
b66ef35
ececfe6
1f2c086
d9c705e
1f2c086
d9c705e
1f2c086
b66ef35
1f2c086
b66ef35
 
 
 
 
 
1f2c086
 
 
 
 
 
 
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
import Dexie, { type Table } from 'dexie';
import type { PicletInstance, Encounter, GameState } from './schema';

export class PicletDatabase extends Dexie {
  // Game tables
  picletInstances!: Table<PicletInstance>;
  encounters!: Table<Encounter>;
  gameState!: Table<GameState>;

  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'
    });
  }
}

export const db = new PicletDatabase();