Skip to content

Commit

Permalink
fix: Add warning to catch multiple versions of excalibur
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 23, 2024
1 parent 2588006 commit b5cafe9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Add warning if World.add() falls through! This is caused by multiple versions of Excalibur usually
- Fixed CollidePolygonPolygon crash with some defense against invalid separation
- Fixed issue with PostProcessor where it would not run correctly if no actors present

Expand Down
18 changes: 18 additions & 0 deletions src/engine/EntityComponentSystem/World.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Scene } from '../Scene';
import { Logger } from '../Util/Log';
import { Component, ComponentCtor } from './Component';
import { Entity } from './Entity';
import { EntityManager } from './EntityManager';
Expand All @@ -12,6 +13,7 @@ import { TagQuery } from './TagQuery';
* The World is a self-contained entity component system for a particular context.
*/
export class World {
private _logger = Logger.getInstance();
public queryManager: QueryManager = new QueryManager(this);
public entityManager: EntityManager = new EntityManager(this);
public systemManager: SystemManager = new SystemManager(this);
Expand Down Expand Up @@ -61,11 +63,19 @@ export class World {
add(entityOrSystem: Entity | System | SystemCtor<System>): void {
if (entityOrSystem instanceof Entity) {
this.entityManager.addEntity(entityOrSystem);
return;
}

if (entityOrSystem instanceof System || isSystemConstructor(entityOrSystem)) {
this.systemManager.addSystem(entityOrSystem);
return;
}

this._logger.warn(
`Could not add entity/system ${(entityOrSystem as any).constructor.name} to Excalibur!\n\n` +
`If this looks like an Excalibur type, this can be caused by 2 versions of excalibur being included on the page.\n\n` +
`Check your bundler settings to make sure this is not the case! Excalibur has ESM & UMD bundles be sure one 1 is loaded.`
);
}

/**
Expand All @@ -88,11 +98,19 @@ export class World {
remove(entityOrSystem: Entity | System, deferred = true): void {
if (entityOrSystem instanceof Entity) {
this.entityManager.removeEntity(entityOrSystem, deferred);
return;
}

if (entityOrSystem instanceof System) {
this.systemManager.removeSystem(entityOrSystem);
return;
}

this._logger.warn(
`Could not remove entity/system ${(entityOrSystem as any).constructor.name} to Excalibur!\n\n` +
`If this looks like an Excalibur type, this can be caused by 2 versions of excalibur being included on the page.\n\n` +
`Check your bundler settings to make sure this is not the case! Excalibur has ESM & UMD bundles be sure one 1 is loaded.`
);
}

get entities() {
Expand Down

0 comments on commit b5cafe9

Please sign in to comment.