rm migration features
Browse files
src/lib/components/Pages/Pictuary.svelte
CHANGED
|
@@ -11,7 +11,6 @@
|
|
| 11 |
import PicletDetail from '../Piclets/PicletDetail.svelte';
|
| 12 |
import AddToRosterDialog from '../Piclets/AddToRosterDialog.svelte';
|
| 13 |
import ViewAll from './ViewAll.svelte';
|
| 14 |
-
import { migratePicletTypes } from '$lib/utils/typeMigration';
|
| 15 |
import { PicletType } from '$lib/types/picletTypes';
|
| 16 |
|
| 17 |
let rosterPiclets: PicletInstance[] = $state([]);
|
|
@@ -68,7 +67,6 @@
|
|
| 68 |
async function loadPiclets() {
|
| 69 |
try {
|
| 70 |
// Run type migration first time to fix any invalid types
|
| 71 |
-
await migratePicletTypes();
|
| 72 |
|
| 73 |
const allInstances = await getAllPicletInstances();
|
| 74 |
|
|
|
|
| 11 |
import PicletDetail from '../Piclets/PicletDetail.svelte';
|
| 12 |
import AddToRosterDialog from '../Piclets/AddToRosterDialog.svelte';
|
| 13 |
import ViewAll from './ViewAll.svelte';
|
|
|
|
| 14 |
import { PicletType } from '$lib/types/picletTypes';
|
| 15 |
|
| 16 |
let rosterPiclets: PicletInstance[] = $state([]);
|
|
|
|
| 67 |
async function loadPiclets() {
|
| 68 |
try {
|
| 69 |
// Run type migration first time to fix any invalid types
|
|
|
|
| 70 |
|
| 71 |
const allInstances = await getAllPicletInstances();
|
| 72 |
|
src/lib/utils/battleConversion.ts
CHANGED
|
@@ -22,7 +22,11 @@ export function picletInstanceToBattleDefinition(instance: PicletInstance): Picl
|
|
| 22 |
// Convert simple moves to full battle moves
|
| 23 |
const movepool: Move[] = instance.moves.map(move => convertBattleMoveToMove(move, instance.primaryType));
|
| 24 |
|
| 25 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const specialAbility: SpecialAbility = instance.specialAbility;
|
| 27 |
|
| 28 |
// Determine tier based on BST (Base Stat Total)
|
|
|
|
| 22 |
// Convert simple moves to full battle moves
|
| 23 |
const movepool: Move[] = instance.moves.map(move => convertBattleMoveToMove(move, instance.primaryType));
|
| 24 |
|
| 25 |
+
// All Piclets must now have special abilities
|
| 26 |
+
if (!instance.specialAbility) {
|
| 27 |
+
throw new Error('Piclet must have a special ability. Legacy Piclets are no longer supported.');
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
const specialAbility: SpecialAbility = instance.specialAbility;
|
| 31 |
|
| 32 |
// Determine tier based on BST (Base Stat Total)
|
src/lib/utils/typeMigration.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
import { db } from '../db/index';
|
| 2 |
-
import { PicletType, getTypeFromConcept } from '../types/picletTypes';
|
| 3 |
-
import type { PicletInstance } from '../db/schema';
|
| 4 |
-
|
| 5 |
-
// Migration function to fix piclets with invalid or legacy types
|
| 6 |
-
export async function migratePicletTypes(): Promise<void> {
|
| 7 |
-
console.log('Starting piclet type migration...');
|
| 8 |
-
|
| 9 |
-
try {
|
| 10 |
-
// Get all piclet instances
|
| 11 |
-
const allPiclets = await db.picletInstances.toArray();
|
| 12 |
-
let migratedCount = 0;
|
| 13 |
-
|
| 14 |
-
for (const piclet of allPiclets) {
|
| 15 |
-
let needsUpdate = false;
|
| 16 |
-
let newType: PicletType | undefined;
|
| 17 |
-
|
| 18 |
-
// Check if primaryType is invalid or missing
|
| 19 |
-
if (!piclet.primaryType || !isValidPicletType(piclet.primaryType)) {
|
| 20 |
-
// Try to determine type from concept/caption
|
| 21 |
-
if (piclet.concept) {
|
| 22 |
-
newType = getTypeFromConcept(piclet.concept, piclet.imageCaption);
|
| 23 |
-
needsUpdate = true;
|
| 24 |
-
} else {
|
| 25 |
-
// Fallback to Beast type
|
| 26 |
-
newType = PicletType.BEAST;
|
| 27 |
-
needsUpdate = true;
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
// Check for legacy string types that need mapping
|
| 32 |
-
else if (typeof piclet.primaryType === 'string' && isLegacyType(piclet.primaryType)) {
|
| 33 |
-
newType = mapLegacyType(piclet.primaryType);
|
| 34 |
-
needsUpdate = true;
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
if (needsUpdate && newType && piclet.id) {
|
| 38 |
-
await db.picletInstances.update(piclet.id, {
|
| 39 |
-
primaryType: newType
|
| 40 |
-
});
|
| 41 |
-
migratedCount++;
|
| 42 |
-
console.log(`Migrated piclet ${piclet.nickname || piclet.typeId} from "${piclet.primaryType}" to "${newType}"`);
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
console.log(`Migration complete: Updated ${migratedCount} piclets`);
|
| 47 |
-
} catch (error) {
|
| 48 |
-
console.error('Error during piclet type migration:', error);
|
| 49 |
-
}
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
function isValidPicletType(type: any): type is PicletType {
|
| 53 |
-
return Object.values(PicletType).includes(type);
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
function isLegacyType(type: string): boolean {
|
| 57 |
-
const legacyTypes = [
|
| 58 |
-
'normal', 'fire', 'water', 'electric', 'grass', 'ice',
|
| 59 |
-
'fighting', 'poison', 'ground', 'flying', 'psychic', 'bug',
|
| 60 |
-
'rock', 'ghost', 'dragon', 'dark', 'steel', 'fairy'
|
| 61 |
-
];
|
| 62 |
-
return legacyTypes.includes(type.toLowerCase());
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
function mapLegacyType(legacyType: string): PicletType {
|
| 66 |
-
const legacyTypeMap: Record<string, PicletType> = {
|
| 67 |
-
'normal': PicletType.BEAST,
|
| 68 |
-
'fire': PicletType.BEAST,
|
| 69 |
-
'water': PicletType.AQUATIC,
|
| 70 |
-
'electric': PicletType.MACHINA,
|
| 71 |
-
'grass': PicletType.FLORA,
|
| 72 |
-
'ice': PicletType.MINERAL,
|
| 73 |
-
'fighting': PicletType.BEAST,
|
| 74 |
-
'poison': PicletType.FLORA,
|
| 75 |
-
'ground': PicletType.MINERAL,
|
| 76 |
-
'flying': PicletType.BEAST,
|
| 77 |
-
'psychic': PicletType.SPACE,
|
| 78 |
-
'bug': PicletType.BUG,
|
| 79 |
-
'rock': PicletType.MINERAL,
|
| 80 |
-
'ghost': PicletType.SPACE,
|
| 81 |
-
'dragon': PicletType.BEAST,
|
| 82 |
-
'dark': PicletType.SPACE,
|
| 83 |
-
'steel': PicletType.MACHINA,
|
| 84 |
-
'fairy': PicletType.CULTURE
|
| 85 |
-
};
|
| 86 |
-
|
| 87 |
-
return legacyTypeMap[legacyType.toLowerCase()] || PicletType.BEAST;
|
| 88 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|