Skip to content

@web-engine-dev/resources


@web-engine-dev/resources / defineResource

Function: defineResource()

defineResource<T>(name): ResourceDescriptor<T>

Define a new resource type

Type Parameters

T

T

Parameters

name

string

The name of the resource

Returns

ResourceDescriptor<T>

A ResourceDescriptor for the resource type

Example

ts
interface GameConfig {
  difficulty: 'easy' | 'normal' | 'hard';
  soundEnabled: boolean;
}

const GameConfigResource = defineResource<GameConfig>('GameConfig');

// Insert
resources.insert(GameConfigResource, { difficulty: 'normal', soundEnabled: true });

// Access
const config = resources.get(GameConfigResource);

Proprietary software. All rights reserved.