Skip to content

Commit

Permalink
chore: update api with new deprecations (#3290)
Browse files Browse the repository at this point in the history
* chore: update api with new deprecations

* fix inconsistency

* fix some annotations
  • Loading branch information
eonarheim authored Nov 29, 2024
1 parent 548b085 commit 760739f
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 79 deletions.
2 changes: 1 addition & 1 deletion sandbox/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/engine/Actions/Action/Blink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action/Flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 5 additions & 12 deletions src/engine/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

/**
Expand Down
27 changes: 24 additions & 3 deletions src/engine/Collision/BodyComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,29 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>
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
Expand All @@ -171,14 +184,14 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>
*/
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;
}
}

Expand Down Expand Up @@ -247,9 +260,17 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>

/**
* 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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Collision/ColliderComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ColliderComponent extends Component {
/**
* Get the current collider geometry
*/
public get() {
public get(): Collider | undefined {
return this._collider;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Collision/CollisionSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/engine/Collision/Detection/CollisionContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Collision/Detection/Pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Collision/MotionSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class MotionSystem extends System {
optionalBody.updatePhysicsConfig(this.physics.config.bodies);
}

if (optionalBody?.sleeping) {
if (optionalBody?.isSleeping) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Debug/DebugSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export interface EngineOptions<TKnownScenes extends string = any> {
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.
Expand All @@ -311,7 +311,7 @@ export interface EngineOptions<TKnownScenes extends string = any> {
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.
Expand Down Expand Up @@ -471,7 +471,7 @@ export class Engine<TKnownScenes extends string = any> 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.
Expand All @@ -486,7 +486,7 @@ export class Engine<TKnownScenes extends string = any> 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.
Expand Down
28 changes: 22 additions & 6 deletions src/engine/EntityComponentSystem/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,39 @@ export class Entity<TKnownComponents extends Component = any> 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;
}

/**
Expand Down Expand Up @@ -540,7 +556,7 @@ export class Entity<TKnownComponents extends Component = any> 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;
Expand All @@ -554,7 +570,7 @@ export class Entity<TKnownComponents extends Component = any> 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;
Expand Down
Loading

0 comments on commit 760739f

Please sign in to comment.