Skip to content

Add optional resource getters to World - #362

Merged
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:optional-resource
Aug 26, 2026
Merged

Add optional resource getters to World#362
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:optional-resource

Conversation

@waynemwashuma

Copy link
Copy Markdown
Collaborator

Objective

Introduce optional resource getters that allow resources to be retrieved without throwing when they do not exist.

Solution

Added optional variants of the World resource getter APIs while preserving resource alias resolution.

Changes Made

  • Added World.getOptionalResource() for type-based lookups.
  • Added World.getOptionalResourceByTypeId() for type ID lookups.

Why This Approach

Required getters continue to assert when a resource is missing, while optional getters return undefined.

Showcase

Before

const resource = world.getResource(TestResource)
// Throws when the resource does not exist

After

const resource = world.getOptionalResource(TestResource)

if (resource !== undefined) {
  // Use the resource
}

Migration Guide

No migration required.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Aug 26, 2026
@waynemwashuma waynemwashuma added the type:enhancement New feature or request label Aug 26, 2026
@waynemwashuma
waynemwashuma merged commit 1dc16fb into wimaengine:dev Aug 26, 2026
7 checks passed
@waynemwashuma
waynemwashuma deleted the optional-resource branch August 26, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:ecs type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant