From 760739f62064d5e9878d5cd67cdbe89babbfd51b Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Thu, 28 Nov 2024 21:09:16 -0600 Subject: [PATCH] chore: update api with new deprecations (#3290) * chore: update api with new deprecations * fix inconsistency * fix some annotations --- sandbox/src/game.ts | 2 +- src/engine/Actions/Action/Blink.ts | 12 ++--- src/engine/Actions/Action/Flash.ts | 2 +- src/engine/Actor.ts | 17 ++---- src/engine/Collision/BodyComponent.ts | 27 ++++++++-- src/engine/Collision/ColliderComponent.ts | 2 +- src/engine/Collision/CollisionSystem.ts | 2 +- .../Collision/Detection/CollisionContact.ts | 10 ++-- .../DynamicTreeCollisionProcessor.ts | 2 +- src/engine/Collision/Detection/Pair.ts | 2 +- .../SparseHashGridCollisionProcessor.ts | 4 +- src/engine/Collision/MotionSystem.ts | 2 +- src/engine/Debug/DebugSystem.ts | 2 +- src/engine/Engine.ts | 8 +-- src/engine/EntityComponentSystem/Entity.ts | 28 +++++++--- .../EntityComponentSystem/EntityManager.ts | 12 ++--- src/engine/Graphics/GraphicsComponent.ts | 54 +++++++++++++++++-- src/engine/Graphics/GraphicsSystem.ts | 4 +- src/engine/Input/PointerAbstraction.ts | 2 +- src/engine/Input/PointerSystem.ts | 2 +- src/engine/Particles/Particles.ts | 2 +- src/engine/Scene.ts | 2 +- src/engine/Screen.ts | 41 +++++++++++--- src/engine/TileMap/IsometricMap.ts | 24 +++++++-- src/engine/Trigger.ts | 2 +- src/engine/Util/Util.ts | 3 +- src/spec/CurveActionSpec.ts | 4 +- 27 files changed, 195 insertions(+), 79 deletions(-) diff --git a/sandbox/src/game.ts b/sandbox/src/game.ts index 49e66beac..be34177ab 100644 --- a/sandbox/src/game.ts +++ b/sandbox/src/game.ts @@ -51,7 +51,7 @@ var game = new ex.Engine({ // pixelRatio: 1, // suppressPlayButton: true, pointerScope: ex.PointerScope.Canvas, - displayMode: ex.DisplayMode.Fixed, + displayMode: ex.DisplayMode.FitScreenAndFill, snapToPixel: false, // fixedUpdateFps: 30, pixelRatio: 2, diff --git a/src/engine/Actions/Action/Blink.ts b/src/engine/Actions/Action/Blink.ts index 8a3cc11b4..bdd0f836c 100644 --- a/src/engine/Actions/Action/Blink.ts +++ b/src/engine/Actions/Action/Blink.ts @@ -31,18 +31,18 @@ export class Blink implements Action { this._elapsedTime += elapsedMs; this._totalTime += elapsedMs; - if (this._graphics.visible && this._elapsedTime >= this._timeVisible) { - this._graphics.visible = false; + if (this._graphics.isVisible && this._elapsedTime >= this._timeVisible) { + this._graphics.isVisible = false; this._elapsedTime = 0; } - if (!this._graphics.visible && this._elapsedTime >= this._timeNotVisible) { - this._graphics.visible = true; + if (!this._graphics.isVisible && this._elapsedTime >= this._timeNotVisible) { + this._graphics.isVisible = true; this._elapsedTime = 0; } if (this.isComplete()) { - this._graphics.visible = true; + this._graphics.isVisible = true; } } @@ -52,7 +52,7 @@ export class Blink implements Action { public stop(): void { if (this._graphics) { - this._graphics.visible = true; + this._graphics.isVisible = true; } this._stopped = true; } diff --git a/src/engine/Actions/Action/Flash.ts b/src/engine/Actions/Action/Flash.ts index 661d63059..5610c15a8 100644 --- a/src/engine/Actions/Action/Flash.ts +++ b/src/engine/Actions/Action/Flash.ts @@ -73,7 +73,7 @@ export class Flash implements Action { public stop(): void { if (this._graphics) { - this._graphics.visible = true; + this._graphics.isVisible = true; } this._stopped = true; } diff --git a/src/engine/Actor.ts b/src/engine/Actor.ts index dbe46656a..67927f014 100644 --- a/src/engine/Actor.ts +++ b/src/engine/Actor.ts @@ -42,8 +42,6 @@ import { PointerEvent } from './Input/PointerEvent'; import { WheelEvent } from './Input/WheelEvent'; import { PointerComponent } from './Input/PointerComponent'; import { ActionsComponent } from './Actions/ActionsComponent'; -import { Raster } from './Graphics/Raster'; -import { Text } from './Graphics/Text'; import { CoordPlane } from './Math/coord-plane'; import { EventEmitter, EventKey, Handler, Subscription } from './EventEmitter'; import { Component } from './EntityComponentSystem'; @@ -541,16 +539,11 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * Sets the color of the actor's current graphic */ public get color(): Color { - return this._color; + return this.graphics.color; } public set color(v: Color) { - this._color = v.clone(); - const currentGraphic = this.graphics.current; - if (currentGraphic instanceof Raster || currentGraphic instanceof Text) { - currentGraphic.color = this._color; - } + this.graphics.color = v; } - private _color: Color; // #endregion @@ -666,7 +659,7 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia } } - this.graphics.visible = visible ?? true; + this.graphics.isVisible = visible ?? true; } public clone(): Actor { @@ -818,14 +811,14 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * If the current actor is killed, it will now not be killed. */ public unkill() { - this.active = true; + this.isActive = true; } /** * Indicates wether the actor has been killed. */ public isKilled(): boolean { - return !this.active; + return !this.isActive; } /** diff --git a/src/engine/Collision/BodyComponent.ts b/src/engine/Collision/BodyComponent.ts index f56db1ef3..b15088bf5 100644 --- a/src/engine/Collision/BodyComponent.ts +++ b/src/engine/Collision/BodyComponent.ts @@ -144,16 +144,29 @@ export class BodyComponent extends Component implements Clonable private _sleeping = false; /** * Whether this body is sleeping or not + * @deprecated use isSleeping */ public get sleeping(): boolean { + return this.isSleeping; + } + + /** + * Whether this body is sleeping or not + */ + public get isSleeping(): boolean { return this._sleeping; } /** * Set the sleep state of the body * @param sleeping + * @deprecated use isSleeping */ public setSleeping(sleeping: boolean) { + this.isSleeping = sleeping; + } + + public set isSleeping(sleeping: boolean) { this._sleeping = sleeping; if (!sleeping) { // Give it a kick to keep it from falling asleep immediately @@ -171,14 +184,14 @@ export class BodyComponent extends Component implements Clonable */ public updateMotion() { if (this._sleeping) { - this.setSleeping(true); + this.isSleeping = true; } const currentMotion = this.vel.magnitude * this.vel.magnitude + Math.abs(this.angularVelocity * this.angularVelocity); const bias = this._bodyConfig.sleepBias; this.sleepMotion = bias * this.sleepMotion + (1 - bias) * currentMotion; this.sleepMotion = clamp(this.sleepMotion, 0, 10 * this._bodyConfig.sleepEpsilon); if (this.canSleep && this.sleepMotion < this._bodyConfig.sleepEpsilon) { - this.setSleeping(true); + this.isSleeping = true; } } @@ -247,9 +260,17 @@ export class BodyComponent extends Component implements Clonable /** * Returns if the owner is active + * @deprecated use isActive */ public get active() { - return !!this.owner?.active; + return !!this.owner?.isActive; + } + + /** + * Returns if the owner is active + */ + public get isActive() { + return !!this.owner?.isActive; } /** diff --git a/src/engine/Collision/ColliderComponent.ts b/src/engine/Collision/ColliderComponent.ts index b8328c539..1f8c75a36 100644 --- a/src/engine/Collision/ColliderComponent.ts +++ b/src/engine/Collision/ColliderComponent.ts @@ -36,7 +36,7 @@ export class ColliderComponent extends Component { /** * Get the current collider geometry */ - public get() { + public get(): Collider | undefined { return this._collider; } diff --git a/src/engine/Collision/CollisionSystem.ts b/src/engine/Collision/CollisionSystem.ts index eb82a187d..53bafda97 100644 --- a/src/engine/Collision/CollisionSystem.ts +++ b/src/engine/Collision/CollisionSystem.ts @@ -86,7 +86,7 @@ export class CollisionSystem extends System { const entity = this.query.entities[entityIndex]; const colliderComp = entity.get(ColliderComponent); const collider = colliderComp?.get(); - if (colliderComp && colliderComp.owner?.active && collider) { + if (colliderComp && colliderComp.owner?.isActive && collider) { colliderComp.update(); // Flatten composite colliders diff --git a/src/engine/Collision/Detection/CollisionContact.ts b/src/engine/Collision/Detection/CollisionContact.ts index b3c5b0fcb..a1c724c3e 100644 --- a/src/engine/Collision/Detection/CollisionContact.ts +++ b/src/engine/Collision/Detection/CollisionContact.ts @@ -100,12 +100,12 @@ export class CollisionContact { const bodyA = this.bodyA; const bodyB = this.bodyB; if (bodyA && bodyB) { - if (bodyA.sleeping !== bodyB.sleeping) { - if (bodyA.sleeping && bodyA.collisionType !== CollisionType.Fixed && bodyB.sleepMotion >= bodyA.wakeThreshold) { - bodyA.setSleeping(false); + if (bodyA.isSleeping !== bodyB.isSleeping) { + if (bodyA.isSleeping && bodyA.collisionType !== CollisionType.Fixed && bodyB.sleepMotion >= bodyA.wakeThreshold) { + bodyA.isSleeping = false; } - if (bodyB.sleeping && bodyB.collisionType !== CollisionType.Fixed && bodyA.sleepMotion >= bodyB.wakeThreshold) { - bodyB.setSleeping(false); + if (bodyB.isSleeping && bodyB.collisionType !== CollisionType.Fixed && bodyA.sleepMotion >= bodyB.wakeThreshold) { + bodyB.isSleeping = false; } } } diff --git a/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts b/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts index 0917fa820..96a59cdd7 100644 --- a/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts +++ b/src/engine/Collision/Detection/DynamicTreeCollisionProcessor.ts @@ -179,7 +179,7 @@ export class DynamicTreeCollisionProcessor implements CollisionProcessor { // Retrieve the list of potential colliders, exclude killed, prevented, and self const potentialColliders = targets.filter((other) => { const body = other.owner?.get(BodyComponent); - return other.owner?.active && body.collisionType !== CollisionType.PreventCollision; + return other.owner?.isActive && body.collisionType !== CollisionType.PreventCollision; }); // clear old list of collision pairs diff --git a/src/engine/Collision/Detection/Pair.ts b/src/engine/Collision/Detection/Pair.ts index f6e2a91b4..29ba01beb 100644 --- a/src/engine/Collision/Detection/Pair.ts +++ b/src/engine/Collision/Detection/Pair.ts @@ -62,7 +62,7 @@ export class Pair { } // if either is dead short circuit - if (!bodyA.active || !bodyB.active) { + if (!bodyA.isActive || !bodyB.isActive) { return false; } diff --git a/src/engine/Collision/Detection/SparseHashGridCollisionProcessor.ts b/src/engine/Collision/Detection/SparseHashGridCollisionProcessor.ts index d68a7eb70..8fd10850a 100644 --- a/src/engine/Collision/Detection/SparseHashGridCollisionProcessor.ts +++ b/src/engine/Collision/Detection/SparseHashGridCollisionProcessor.ts @@ -309,7 +309,7 @@ export class SparseHashGridCollisionProcessor implements CollisionProcessor { } // if either is dead short circuit - if (!colliderA.owner.active || !colliderB.owner.active) { + if (!colliderA.owner.isActive || !colliderB.owner.isActive) { return false; } @@ -329,7 +329,7 @@ export class SparseHashGridCollisionProcessor implements CollisionProcessor { let proxyId = 0; for (const proxy of this.hashGrid.objectToProxy.values()) { proxy.id = proxyId++; // track proxies we've already processed - if (!proxy.owner.active || proxy.collisionType === CollisionType.PreventCollision) { + if (!proxy.owner.isActive || proxy.collisionType === CollisionType.PreventCollision) { continue; } // for every cell proxy collider is member of diff --git a/src/engine/Collision/MotionSystem.ts b/src/engine/Collision/MotionSystem.ts index f593fc8f4..424ea338c 100644 --- a/src/engine/Collision/MotionSystem.ts +++ b/src/engine/Collision/MotionSystem.ts @@ -37,7 +37,7 @@ export class MotionSystem extends System { optionalBody.updatePhysicsConfig(this.physics.config.bodies); } - if (optionalBody?.sleeping) { + if (optionalBody?.isSleeping) { continue; } diff --git a/src/engine/Debug/DebugSystem.ts b/src/engine/Debug/DebugSystem.ts index 3aba04942..8193ebe78 100644 --- a/src/engine/Debug/DebugSystem.ts +++ b/src/engine/Debug/DebugSystem.ts @@ -191,7 +191,7 @@ export class DebugSystem extends System { } if (bodySettings.showAll || bodySettings.showSleeping) { - this._graphicsContext.debug.drawText(`sleeping(${body.canSleep ? body.sleeping : 'cant sleep'})`, cursor); + this._graphicsContext.debug.drawText(`sleeping(${body.canSleep ? body.isSleeping : 'cant sleep'})`, cursor); cursor = cursor.add(lineHeight); } } diff --git a/src/engine/Engine.ts b/src/engine/Engine.ts index 53ebdf635..dce7dc423 100644 --- a/src/engine/Engine.ts +++ b/src/engine/Engine.ts @@ -296,7 +296,7 @@ export interface EngineOptions { maxFps?: number; /** - * Optionally configure a fixed update timestep in milliseconds, this can be desireable if you need the physics simulation to be very stable. When + * Optionally configure a fixed update timestep in milliseconds, this can be desirable if you need the physics simulation to be very stable. When * set the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the * simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example * there could be X updates and 1 draw each clock step. @@ -311,7 +311,7 @@ export interface EngineOptions { fixedUpdateTimestep?: number; /** - * Optionally configure a fixed update fps, this can be desireable if you need the physics simulation to be very stable. When set + * Optionally configure a fixed update fps, this can be desirable if you need the physics simulation to be very stable. When set * the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the * simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example * there could be X updates and 1 draw each clock step. @@ -471,7 +471,7 @@ export class Engine implements CanInitialize, public maxFps: number = Number.POSITIVE_INFINITY; /** - * Optionally configure a fixed update fps, this can be desireable if you need the physics simulation to be very stable. When set + * Optionally configure a fixed update fps, this can be desirable if you need the physics simulation to be very stable. When set * the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the * simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example * there could be X updates and 1 draw each clock step. @@ -486,7 +486,7 @@ export class Engine implements CanInitialize, public readonly fixedUpdateFps?: number; /** - * Optionally configure a fixed update timestep in milliseconds, this can be desireable if you need the physics simulation to be very stable. When + * Optionally configure a fixed update timestep in milliseconds, this can be desirable if you need the physics simulation to be very stable. When * set the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the * simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example * there could be X updates and 1 draw each clock step. diff --git a/src/engine/EntityComponentSystem/Entity.ts b/src/engine/EntityComponentSystem/Entity.ts index 976f8026f..65a8092b4 100644 --- a/src/engine/EntityComponentSystem/Entity.ts +++ b/src/engine/EntityComponentSystem/Entity.ts @@ -160,23 +160,39 @@ export class Entity implements OnIniti /** * Whether this entity is active, if set to false it will be reclaimed + * @deprecated use isActive */ - public active: boolean = true; + public get active(): boolean { + return this.isActive; + } + + /** + * Whether this entity is active, if set to false it will be reclaimed + * @deprecated use isActive + */ + public set active(val: boolean) { + this.isActive = val; + } + + /** + * Whether this entity is active, if set to false it will be reclaimed + */ + public isActive: boolean = true; /** * Kill the entity, means it will no longer be updated. Kills are deferred to the end of the update. * If parented it will be removed from the parent when killed. */ public kill() { - if (this.active) { - this.active = false; + if (this.isActive) { + this.isActive = false; this.unparent(); } this.emit('kill', new KillEvent(this)); } public isKilled() { - return !this.active; + return !this.isActive; } /** @@ -540,7 +556,7 @@ export class Entity implements OnIniti * @internal */ public _add(engine: Engine) { - if (!this.isAdded && this.active) { + if (!this.isAdded && this.isActive) { this.onAdd(engine); this.events.emit('add', new AddEvent(engine, this)); this._isAdded = true; @@ -554,7 +570,7 @@ export class Entity implements OnIniti * @internal */ public _remove(engine: Engine) { - if (this.isAdded && !this.active) { + if (this.isAdded && !this.isActive) { this.onRemove(engine); this.events.emit('remove', new RemoveEvent(engine, this)); this._isAdded = false; diff --git a/src/engine/EntityComponentSystem/EntityManager.ts b/src/engine/EntityComponentSystem/EntityManager.ts index c0877d222..fd7aa9af1 100644 --- a/src/engine/EntityComponentSystem/EntityManager.ts +++ b/src/engine/EntityComponentSystem/EntityManager.ts @@ -22,7 +22,7 @@ export class EntityManager { for (let entityIndex = 0; entityIndex < this.entities.length; entityIndex++) { const entity = this.entities[entityIndex]; entity.update(scene.engine, elapsed); - if (!entity.active) { + if (!entity.isActive) { this.removeEntity(entity); } } @@ -31,7 +31,7 @@ export class EntityManager { public findEntitiesForRemoval() { for (let entityIndex = 0; entityIndex < this.entities.length; entityIndex++) { const entity = this.entities[entityIndex]; - if (!entity.active) { + if (!entity.isActive) { this.removeEntity(entity); } } @@ -50,7 +50,7 @@ export class EntityManager { * @param entity */ public addEntity(entity: Entity): void { - entity.active = true; + entity.isActive = true; entity.scene = this._world.scene; if (entity && !this._entityIndex[entity.id]) { this._entityIndex[entity.id] = entity; @@ -81,8 +81,8 @@ export class EntityManager { id = idOrEntity; } const entity = this._entityIndex[id]; - if (entity && entity.active) { - entity.active = false; + if (entity && entity.isActive) { + entity.isActive = false; } if (entity && deferred) { @@ -121,7 +121,7 @@ export class EntityManager { public processEntityRemovals(): void { for (let entityIndex = 0; entityIndex < this._entitiesToRemove.length; entityIndex++) { const entity = this._entitiesToRemove[entityIndex]; - if (entity.active) { + if (entity.isActive) { continue; } this.removeEntity(entity, false); diff --git a/src/engine/Graphics/GraphicsComponent.ts b/src/engine/Graphics/GraphicsComponent.ts index d75d7a887..68053a6c0 100644 --- a/src/engine/Graphics/GraphicsComponent.ts +++ b/src/engine/Graphics/GraphicsComponent.ts @@ -9,6 +9,9 @@ import { Logger } from '../Util/Log'; import { WatchVector } from '../Math/watch-vector'; import { TransformComponent } from '../EntityComponentSystem'; import { GraphicsGroup } from '../Graphics/GraphicsGroup'; +import { Color } from '../Color'; +import { Raster } from './Raster'; +import { Text } from './Text'; /** * Type guard for checking if a Graphic HasTick (used for graphics that change over time like animations) @@ -33,6 +36,11 @@ export interface GraphicsComponentOptions { */ current?: string; + /** + * Optionally set the color of the graphics component + */ + color?: Color; + /** * Optionally set a material to use on the graphic */ @@ -101,11 +109,28 @@ export class GraphicsComponent extends Component { * Draws after the entity transform has been applied, and after all graphics component drawing */ public onPostTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsedMilliseconds: number) => void; + private _color?: Color; /** * Sets or gets wether any drawing should be visible in this component + * @deprecated use isVisible */ - public visible: boolean = true; + public get visible(): boolean { + return this.isVisible; + } + + /** + * Sets or gets wether any drawing should be visible in this component + * @deprecated use isVisible + */ + public set visible(val: boolean) { + this.isVisible = val; + } + + /** + * Sets or gets wether any drawing should be visible in this component + */ + public isVisible: boolean = true; /** * Optionally force the graphic onscreen, default false. Not recommend to use for perf reasons, only if you known what you're doing. @@ -143,6 +168,22 @@ export class GraphicsComponent extends Component { this.recalculateBounds(); } + /** + * Sets the color of the actor's current graphic + */ + public get color(): Color | undefined { + return this._color; + } + public set color(v: Color | undefined) { + if (v) { + this._color = v.clone(); + const currentGraphic = this.graphics.current; + if (currentGraphic instanceof Raster || currentGraphic instanceof Text) { + currentGraphic.color = this._color; + } + } + } + /** * Flip all graphics horizontally along the y-axis */ @@ -163,7 +204,7 @@ export class GraphicsComponent extends Component { super(); // Defaults options = { - visible: this.visible, + visible: this.isVisible, graphics: {}, ...options }; @@ -171,6 +212,7 @@ export class GraphicsComponent extends Component { const { current, anchor, + color, opacity, visible, graphics, @@ -194,12 +236,13 @@ export class GraphicsComponent extends Component { this.offset = offset ?? this.offset; this.opacity = opacity ?? this.opacity; this.anchor = anchor ?? this.anchor; + this.color = color ?? this.color; this.copyGraphics = copyGraphics ?? this.copyGraphics; this.onPreDraw = onPreDraw ?? this.onPreDraw; this.onPostDraw = onPostDraw ?? this.onPostDraw; this.onPreDraw = onPreTransformDraw ?? this.onPreTransformDraw; this.onPostTransformDraw = onPostTransformDraw ?? this.onPostTransformDraw; - this.visible = !!visible; + this.isVisible = !!visible; this._current = current ?? this._current; if (current && this._graphics[current]) { this.use(current); @@ -413,12 +456,15 @@ export class GraphicsComponent extends Component { graphics._graphics = { ...this._graphics }; graphics._options = { ...this._options }; graphics.offset = this.offset.clone(); + if (this.color) { + graphics.color = this.color.clone(); + } graphics.opacity = this.opacity; graphics.anchor = this.anchor.clone(); graphics.copyGraphics = this.copyGraphics; graphics.onPreDraw = this.onPreDraw; graphics.onPostDraw = this.onPostDraw; - graphics.visible = this.visible; + graphics.isVisible = this.isVisible; return graphics; } diff --git a/src/engine/Graphics/GraphicsSystem.ts b/src/engine/Graphics/GraphicsSystem.ts index 484868ea1..abee87429 100644 --- a/src/engine/Graphics/GraphicsSystem.ts +++ b/src/engine/Graphics/GraphicsSystem.ts @@ -94,7 +94,7 @@ export class GraphicsSystem extends System { graphics = entity.get(GraphicsComponent); // Exit if graphics set to not visible - if (!graphics.visible) { + if (!graphics.isVisible) { continue; } @@ -174,7 +174,7 @@ export class GraphicsSystem extends System { } private _drawGraphicsComponent(graphicsComponent: GraphicsComponent, transformComponent: TransformComponent) { - if (graphicsComponent.visible) { + if (graphicsComponent.isVisible) { const flipHorizontal = graphicsComponent.flipHorizontal; const flipVertical = graphicsComponent.flipVertical; diff --git a/src/engine/Input/PointerAbstraction.ts b/src/engine/Input/PointerAbstraction.ts index 11cde1fae..a657d2a34 100644 --- a/src/engine/Input/PointerAbstraction.ts +++ b/src/engine/Input/PointerAbstraction.ts @@ -55,7 +55,7 @@ export class PointerAbstraction { /** * Called internally by excalibur to keep pointers up to date * @internal - * @param pos + * @param engine */ public _updateWorldPosition(engine: Engine) { const coord = GlobalCoordinates.fromPagePosition(this.lastPagePos, engine); diff --git a/src/engine/Input/PointerSystem.ts b/src/engine/Input/PointerSystem.ts index 3521755e3..0315c0293 100644 --- a/src/engine/Input/PointerSystem.ts +++ b/src/engine/Input/PointerSystem.ts @@ -47,7 +47,7 @@ export class PointerSystem extends System { } return false; }, - () => e.active + () => e.isActive ); this._entityToPointer.set(e, pointer); const maybeGfx = e.get(GraphicsComponent); diff --git a/src/engine/Particles/Particles.ts b/src/engine/Particles/Particles.ts index 1e57146f6..73ddcf743 100644 --- a/src/engine/Particles/Particles.ts +++ b/src/engine/Particles/Particles.ts @@ -125,7 +125,7 @@ export class Particle extends Entity { } public override kill() { - if (this._emitter?.active) { + if (this._emitter?.isActive) { this._emitter.removeParticle(this); } else { super.kill(); diff --git a/src/engine/Scene.ts b/src/engine/Scene.ts index c19af98e3..77f400284 100644 --- a/src/engine/Scene.ts +++ b/src/engine/Scene.ts @@ -646,7 +646,7 @@ export class Scene implements CanInitialize, CanActiv public remove(entity: any): void { if (entity instanceof Entity) { this.emit('entityremoved', { target: entity } as any); - if (entity.active) { + if (entity.isActive) { entity.kill(); } this.world.remove(entity); diff --git a/src/engine/Screen.ts b/src/engine/Screen.ts index e1d976645..6022e6f19 100644 --- a/src/engine/Screen.ts +++ b/src/engine/Screen.ts @@ -277,7 +277,7 @@ export class Screen { private _viewportStack: ViewportDimension[] = []; private _pixelRatioOverride: number | null = null; private _displayMode: DisplayMode; - private _isFullScreen = false; + private _isFullscreen = false; private _mediaQueryList: MediaQueryList; private _isDisposed = false; private _logger = Logger.getInstance(); @@ -344,8 +344,8 @@ export class Screen { if (this._isDisposed) { return; } - this._isFullScreen = !this._isFullScreen; - this._logger.debug('Fullscreen Change', this._isFullScreen); + this._isFullscreen = !this._isFullscreen; + this._logger.debug('Fullscreen Change', this._isFullscreen); this.events.emit('fullscreen', { fullscreen: this.isFullScreen } satisfies FullScreenChangeEvent); @@ -596,9 +596,17 @@ export class Screen { /** * Returns true if excalibur is fullscreen using the browser fullscreen api + * @deprecated use isFullscreen() */ public get isFullScreen() { - return this._isFullScreen; + return this._isFullscreen; + } + + /** + * Returns true if excalibur is fullscreen using the browser fullscreen api + */ + public get isFullscreen() { + return this._isFullscreen; } /** @@ -607,8 +615,20 @@ export class Screen { * * Optionally specify a target element id to go fullscreen, by default the game canvas is used * @param elementId + * @deprecated use enterFullscreen(...) */ public goFullScreen(elementId?: string): Promise { + return this.enterFullscreen(elementId); + } + + /** + * Requests to enter fullscreen using the browser fullscreen api, requires user interaction to be successful. + * For example, wire this to a user click handler. + * + * Optionally specify a target element id to go fullscreen, by default the game canvas is used + * @param elementId + */ + public enterFullscreen(elementId?: string): Promise { if (elementId) { const maybeElement = document.getElementById(elementId); if (maybeElement) { @@ -625,8 +645,13 @@ export class Screen { /** * Requests to exit fullscreen using the browser fullscreen api + * @deprecated use exitFullscreen() */ public exitFullScreen(): Promise { + return this.exitFullscreen(); + } + + public exitFullscreen(): Promise { return document.exitFullscreen(); } @@ -650,7 +675,7 @@ export class Screen { let newX = point.x; let newY = point.y; - if (!this._isFullScreen) { + if (!this._isFullscreen) { newX -= getPosition(this._canvas).x; newY -= getPosition(this._canvas).y; } @@ -659,7 +684,7 @@ export class Screen { // if fullscreen api on it centers with black bars // we need to adjust the screen to world coordinates in this case - if (this._isFullScreen) { + if (this._isFullscreen) { if (window.innerWidth / this.aspectRatio < window.innerHeight) { const screenHeight = window.innerWidth / this.aspectRatio; const screenMarginY = (window.innerHeight - screenHeight) / 2; @@ -702,7 +727,7 @@ export class Screen { newX = (newX / this.resolution.width) * viewport.width; newY = (newY / this.resolution.height) * viewport.height; - if (this._isFullScreen) { + if (this._isFullscreen) { if (window.innerWidth / this.aspectRatio < window.innerHeight) { const screenHeight = window.innerWidth / this.aspectRatio; const screenMarginY = (window.innerHeight - screenHeight) / 2; @@ -716,7 +741,7 @@ export class Screen { } } - if (!this._isFullScreen) { + if (!this._isFullscreen) { newX += getPosition(this._canvas).x; newY += getPosition(this._canvas).y; } diff --git a/src/engine/TileMap/IsometricMap.ts b/src/engine/TileMap/IsometricMap.ts index e861c8a17..bfe99129a 100644 --- a/src/engine/TileMap/IsometricMap.ts +++ b/src/engine/TileMap/IsometricMap.ts @@ -44,7 +44,7 @@ export class IsometricTile extends Entity { */ public addGraphic(graphic: Graphic, options?: { offset?: Vector }) { this._graphics.push(graphic); - this._gfx.visible = this.map.visible; + this._gfx.isVisible = this.map.isVisible; this._gfx.opacity = this.map.opacity; if (options?.offset) { this._gfx.offset = options.offset; @@ -75,7 +75,7 @@ export class IsometricTile extends Entity { public clearGraphics() { this._graphics.length = 0; - this._gfx.visible = false; + this._gfx.isVisible = false; this._gfx.localBounds = this._recalculateBounds(); } @@ -186,7 +186,7 @@ export class IsometricTile extends Entity { this._isometricEntityComponent.elevation = map.elevation; this._gfx = this.get(GraphicsComponent); - this._gfx.visible = false; // start not visible + this._gfx.isVisible = false; // start not visible const totalWidth = this.map.tileWidth; const totalHeight = this.map.tileHeight; @@ -288,8 +288,24 @@ export class IsometricMap extends Entity implements HasNestedPointerEvents { /** * Whether tiles should be visible + * @deprecated use isVisible */ - public visible = true; + public get visible(): boolean { + return this.isVisible; + } + + /** + * Whether tiles should be visible + * @deprecated use isVisible + */ + public set visible(val: boolean) { + this.isVisible = val; + } + + /** + * Whether tiles should be visible + */ + public isVisible = true; /** * Opacity of tiles diff --git a/src/engine/Trigger.ts b/src/engine/Trigger.ts index ac225b13b..41d170536 100644 --- a/src/engine/Trigger.ts +++ b/src/engine/Trigger.ts @@ -70,7 +70,7 @@ export class Trigger extends Actor { this.action = options.action ?? (() => undefined); this.target = options.target; - this.graphics.visible = options.visible ?? false; + this.graphics.isVisible = options.visible ?? false; this.body.collisionType = CollisionType.Passive; this.events.on('collisionstart', ({ other: collider }: CollisionStartEvent) => { diff --git a/src/engine/Util/Util.ts b/src/engine/Util/Util.ts index 3c048b723..e876d4eba 100644 --- a/src/engine/Util/Util.ts +++ b/src/engine/Util/Util.ts @@ -94,7 +94,6 @@ export function omit(object: /** * Simple object check. * @param item - * @returns {boolean} */ export function isObject(item: any): item is object { return item && typeof item === 'object' && !Array.isArray(item); @@ -103,7 +102,7 @@ export function isObject(item: any): item is object { /** * Deep merge two objects. * @param target - * @param ...sources + * @param sources */ export function mergeDeep(target: T, ...sources: T[]) { if (!sources.length) { diff --git a/src/spec/CurveActionSpec.ts b/src/spec/CurveActionSpec.ts index 7d36b504f..3e1c15195 100644 --- a/src/spec/CurveActionSpec.ts +++ b/src/spec/CurveActionSpec.ts @@ -26,7 +26,7 @@ describe('A actor can curve', () => { expect(ex.CurveTo).toBeDefined(); }); - it('an actor can curveTo ', async () => { + it('an actor can curveTo ', () => { const actor = new ex.Actor({ pos: ex.vec(200, 202) }); @@ -44,7 +44,7 @@ describe('A actor can curve', () => { expect(actor.pos).toBeVector(ex.vec(100, 200)); }); - it('an actor can curveBy ', async () => { + it('an actor can curveBy ', () => { const actor = new ex.Actor({ pos: ex.vec(200, 202) });