space-game/src/stores/levelRegistry.ts
Michael Mainguy b4baa2beba
All checks were successful
Build / build (push) Successful in 1m44s
Migrate to cloud-only level system using Supabase
Remove all local level storage concepts and load levels exclusively from
Supabase cloud. Simplifies LevelRegistry from 380+ lines to ~50 lines.
Uses CloudLevelEntry directly throughout the codebase instead of wrapper
types like LevelDirectoryEntry.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 17:26:24 -06:00

55 lines
1.4 KiB
TypeScript

import { writable } from 'svelte/store';
import { LevelRegistry } from '../levels/storage/levelRegistry';
import type { LevelConfig } from '../levels/config/levelConfig';
import type { CloudLevelEntry } from '../services/cloudLevelService';
export interface LevelRegistryState {
isInitialized: boolean;
levels: Map<string, CloudLevelEntry>;
}
function createLevelRegistryStore() {
const registry = LevelRegistry.getInstance();
const initial: LevelRegistryState = {
isInitialized: false,
levels: new Map(),
};
const { subscribe, set, update } = writable<LevelRegistryState>(initial);
// Initialize registry
(async () => {
try {
await registry.initialize();
update(state => ({
...state,
isInitialized: true,
levels: registry.getAllLevels(),
}));
} catch (error) {
console.error('[LevelRegistryStore] Failed to initialize:', error);
}
})();
return {
subscribe,
getLevel: (levelId: string): LevelConfig | null => {
return registry.getLevel(levelId);
},
getLevelEntry: (levelId: string): CloudLevelEntry | null => {
return registry.getLevelEntry(levelId);
},
refresh: async () => {
registry.reset();
await registry.initialize();
update(state => ({
...state,
levels: registry.getAllLevels(),
}));
},
};
}
export const levelRegistryStore = createLevelRegistryStore();