diff options
Diffstat (limited to 'content-system/registry/singleton.ts')
| -rw-r--r-- | content-system/registry/singleton.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/content-system/registry/singleton.ts b/content-system/registry/singleton.ts new file mode 100644 index 0000000..d8a556e --- /dev/null +++ b/content-system/registry/singleton.ts @@ -0,0 +1,25 @@ +import type { ContentRegistry } from '@hollowdark/content-system/registry/registry' + +let instance: ContentRegistry | null = null + +/** Record the registry populated during session startup. */ +export function setContentRegistry(registry: ContentRegistry): void { + instance = registry +} + +/** + * Access the shared content registry. Throws if called before the + * loading pipeline has populated it — simulation code should never run + * until initial load is complete. + */ +export function getContentRegistry(): ContentRegistry { + if (instance === null) { + throw new Error('Content registry not initialised. Initial load must complete first.') + } + return instance +} + +/** True once the registry has been populated. */ +export function hasContentRegistry(): boolean { + return instance !== null +} |
