space-game/src/stores/levelRegistry.ts
Michael Mainguy eccf101b73
All checks were successful
Build / build (push) Successful in 1m20s
Implement Svelte-based UI architecture with component system
Major refactoring of the UI layer to use Svelte components:
- Replace inline HTML with modular Svelte components
- Add authentication system with UserProfile component
- Implement navigation store for view management
- Create comprehensive settings and controls screens
- Add level editor with JSON validation
- Implement progression tracking system
- Update level configurations and base station model

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 15:01:17 -06:00

60 lines
1.7 KiB
TypeScript

import { writable, get } from 'svelte/store';
import { LevelRegistry, type LevelDirectoryEntry } from '../levels/storage/levelRegistry';
import type { LevelConfig } from '../levels/config/levelConfig';
export interface LevelRegistryState {
isInitialized: boolean;
defaultLevels: Map<string, { config: LevelConfig | null; directoryEntry: LevelDirectoryEntry; isDefault: boolean }>;
customLevels: Map<string, { config: LevelConfig | null; directoryEntry: LevelDirectoryEntry; isDefault: boolean }>;
}
function createLevelRegistryStore() {
const registry = LevelRegistry.getInstance();
const initial: LevelRegistryState = {
isInitialized: false,
defaultLevels: new Map(),
customLevels: new Map(),
};
const { subscribe, set, update } = writable<LevelRegistryState>(initial);
// Initialize registry
(async () => {
await registry.initialize();
update(state => ({
...state,
isInitialized: true,
defaultLevels: registry.getDefaultLevels(),
customLevels: registry.getCustomLevels(),
}));
})();
return {
subscribe,
getLevel: async (levelId: string): Promise<LevelConfig | null> => {
return await registry.getLevel(levelId);
},
refresh: async () => {
await registry.initialize();
update(state => ({
...state,
defaultLevels: registry.getDefaultLevels(),
customLevels: registry.getCustomLevels(),
}));
},
deleteCustomLevel: (levelId: string): boolean => {
const success = registry.deleteCustomLevel(levelId);
if (success) {
update(state => ({
...state,
customLevels: registry.getCustomLevels(),
}));
}
return success;
},
};
}
export const levelRegistryStore = createLevelRegistryStore();