Skip to content

Add World.hasResource#258

Merged
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:Add-world-hasResource
Sep 17, 2025
Merged

Add World.hasResource#258
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:Add-world-hasResource

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

@waynemwashuma waynemwashuma commented Sep 17, 2025

Objective

Adds the ability to check if a resource exists in the ECS World.

Solution

The solution adds two methods to World to check for the existence of a resource without throwing an error if it doesn't exist. This is useful for conditional resource access and avoids the need for try-catch blocks.

  • Added hasResource which checks by constructor type.
  • Added hasResourceByTypeId which checks by internal type ID.
  • Both methods handle resource aliases correctly, returning true only if the aliased resource exists.

Showcase

Here’s how to use the new methods:

const world = new World();
world.setResource(new TestResource());

// Check by constructor
if (world.hasResource(TestResource)) {
  const resource = world.getResource(TestResource);
  // Use resource safely
}

// Check by TypeId
const typeId = typeid(TestResource);
if (world.hasResourceByTypeId(typeId)) {
  const resource = world.getResourceByTypeId(typeId);
}

Migration Guide

No breaking changes are introduced.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes

@waynemwashuma waynemwashuma self-assigned this Sep 17, 2025
@waynemwashuma waynemwashuma added type:enhancement New feature or request mod:ecs labels Sep 17, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 17, 2025 03:09
@waynemwashuma waynemwashuma merged commit 959e01a into wimaengine:dev Sep 17, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the Add-world-hasResource branch September 17, 2025 03:50
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