diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a54fb5ce5..d4298755fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,19 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Breaking Changes - Behavior change - TileMap now uses 'separate' as the `compositeStrategy` as a better default. Commonly TileMap is used to build levels, so this default aligns with the common use. +- Removed old legacy `ex.EasingFunctions` in favor of the [0, 1] common easing functions +- Removed EaseTo/EaseBy/actor.actions.(easeTo|easeBy) Action in favor of MoveTo/MoveBy/actor.actions.(moveTo|moveBy) Action with easing support +- Removed `body.sleeping` in favor of `isSleeping` +- Removed `entity.active` in favor of `isActive` +- Removed `actor.getGlobalPos()` in favor of `actor.globalPos` getter/setter +- Removed `actor.getGlobalRotation()` in favor of `actor.globalRotation` getter/setter +- Removed `actor.getGlobalScale()` in favor of `actor.globalScale` getter/setter +- Removed `BoundingBox.draw` in favor of `BoundingBox.debug` +- Removed typo in `engine.isFullScreen` now `engine.isFullscreen` +- Removed unused `tag-query.ts` +- Removed `world.queryTags`, `world.query(...)` can query tags +- Removed `Animation.durationPerFrameMs` in favor of `Animation.durationPerFrame` +- Removed `Vector.size` in favor of `Vector.magnitude` ### Deprecated diff --git a/site/docs/02-fundamentals/05-transitions.mdx b/site/docs/02-fundamentals/05-transitions.mdx index eb22597c58..06dab086cd 100644 --- a/site/docs/02-fundamentals/05-transitions.mdx +++ b/site/docs/02-fundamentals/05-transitions.mdx @@ -106,7 +106,7 @@ const transition = new ex.Transition({ /** * Optionally specify a easing function, by default linear */ - easing: ex.EasingFunctions.Linear, + easing: ex.linear, /** * Optionally specify a transition direction, by default 'out' * @@ -226,4 +226,4 @@ export class CrossFade extends Transition { this.graphics.opacity = progress; } } -``` \ No newline at end of file +``` diff --git a/site/docs/04-graphics/examples/animation-coords.ts b/site/docs/04-graphics/examples/animation-coords.ts index cfd28c9c53..75e64f36a9 100644 --- a/site/docs/04-graphics/examples/animation-coords.ts +++ b/site/docs/04-graphics/examples/animation-coords.ts @@ -24,7 +24,7 @@ const runSheet = ex.SpriteSheet.fromImageSource({ const runAnim = ex.Animation.fromSpriteSheetCoordinates({ spriteSheet: runSheet, - durationPerFrameMs: 200, + durationPerFrame: 200, frameCoordinates: [ {x: 1, y: 0}, {x: 2, y: 0}, diff --git a/src/engine/actions/action-context.ts b/src/engine/actions/action-context.ts index 2c1210b94e..a34b5a03e0 100644 --- a/src/engine/actions/action-context.ts +++ b/src/engine/actions/action-context.ts @@ -1,5 +1,3 @@ -import type { EasingFunction } from '../util/easing-functions'; -import { EasingFunctions } from '../util/easing-functions'; import { ActionQueue } from './action-queue'; import { Repeat } from './action/repeat'; import { RepeatForever } from './action/repeat-forever'; @@ -16,8 +14,6 @@ import { isScaleToOptions, ScaleTo, ScaleToWithOptions } from './action/scale-to import type { ScaleByOptions } from './action/scale-by'; import { isScaleByOptions, ScaleBy, ScaleByWithOptions } from './action/scale-by'; import { CallMethod } from './action/call-method'; -import { EaseTo } from './action/ease-to'; -import { EaseBy } from './action/ease-by'; import { Blink } from './action/blink'; import { Fade } from './action/fade'; import { Delay } from './action/delay'; @@ -91,87 +87,6 @@ export class ActionContext { return this; } - /** - * This method will move an actor to the specified `x` and `y` position over the - * specified duration using a given {@apilink EasingFunctions} and return back the actor. This - * method is part of the actor 'Action' fluent API allowing action chaining. - * @param pos The x,y vector location to move the actor to - * @param duration The time it should take the actor to move to the new location in milliseconds - * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeTo(pos: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; - /** - * This method will move an actor to the specified `x` and `y` position over the - * specified duration using a given {@apilink EasingFunctions} and return back the actor. This - * method is part of the actor 'Action' fluent API allowing action chaining. - * @param x The x location to move the actor to - * @param y The y location to move the actor to - * @param duration The time it should take the actor to move to the new location in milliseconds - * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeTo(x: number, y: number, duration: number, easingFcn?: EasingFunction): ActionContext; - public easeTo(...args: any[]): ActionContext { - let x = 0; - let y = 0; - let duration = 0; - let easingFcn = EasingFunctions.Linear; - if (args[0] instanceof Vector) { - x = args[0].x; - y = args[0].y; - duration = args[1]; - easingFcn = args[2] ?? easingFcn; - } else { - x = args[0]; - y = args[1]; - duration = args[2]; - easingFcn = args[3] ?? easingFcn; - } - - this._queue.add(new EaseTo(this._entity, x, y, duration, easingFcn)); - return this; - } - - /** - * This method will move an actor by a specified vector offset relative to the current position given - * a duration and a {@apilink EasingFunction}. This method is part of the actor 'Action' fluent API allowing action chaining. - * @param offset Vector offset relative to the current position - * @param duration The duration in milliseconds - * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveBy({offset: Vector, duration: number, easing: EasingFunction}) - */ - public easeBy(offset: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; - /** - * This method will move an actor by a specified x and y offset relative to the current position given - * a duration and a {@apilink EasingFunction}. This method is part of the actor 'Action' fluent API allowing action chaining. - * @param offset Vector offset relative to the current position - * @param duration The duration in milliseconds - * @param easingFcn Use {@apilink EasingFunction} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveBy({offset: Vector, duration: number, easing: EasingFunction}) - */ - public easeBy(offsetX: number, offsetY: number, duration: number, easingFcn?: EasingFunction): ActionContext; - public easeBy(...args: any[]): ActionContext { - let offsetX = 0; - let offsetY = 0; - let duration = 0; - let easingFcn = EasingFunctions.Linear; - if (args[0] instanceof Vector) { - offsetX = args[0].x; - offsetY = args[0].y; - duration = args[1]; - easingFcn = args[2] ?? easingFcn; - } else { - offsetX = args[0]; - offsetY = args[1]; - duration = args[2]; - easingFcn = args[3] ?? easingFcn; - } - - this._queue.add(new EaseBy(this._entity, offsetX, offsetY, duration, easingFcn)); - return this; - } - /** * Moves an actor to a specified {@link Vector} in a given duration in milliseconds. * You may optionally specify an {@link EasingFunction} diff --git a/src/engine/actions/action/ease-by.ts b/src/engine/actions/action/ease-by.ts deleted file mode 100644 index 32971e1205..0000000000 --- a/src/engine/actions/action/ease-by.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { MotionComponent } from '../../entity-component-system/components/motion-component'; -import { TransformComponent } from '../../entity-component-system/components/transform-component'; -import type { Entity } from '../../entity-component-system/entity'; -import { vec, Vector } from '../../math/vector'; -import type { Action } from '../action'; -import { nextActionId } from '../action'; - -/** - * @deprecated use moveBy({offset: Vector, duration: number, easing: EasingFunction}) - */ -export class EaseBy implements Action { - id = nextActionId(); - private _tx: TransformComponent; - private _motion: MotionComponent; - private _currentLerpTime: number = 0; - private _lerpDuration: number = 1 * 1000; // 1 second - private _lerpStart: Vector = new Vector(0, 0); - private _lerpEnd: Vector = new Vector(0, 0); - private _offset: Vector; - private _initialized: boolean = false; - private _stopped: boolean = false; - constructor( - entity: Entity, - offsetX: number, - offsetY: number, - duration: number, - public easingFcn: (currentTime: number, startValue: number, endValue: number, duration: number) => number - ) { - this._tx = entity.get(TransformComponent); - this._motion = entity.get(MotionComponent); - this._lerpDuration = duration; - this._offset = new Vector(offsetX, offsetY); - } - private _initialize() { - this._lerpStart = new Vector(this._tx.pos.x, this._tx.pos.y); - this._currentLerpTime = 0; - this._lerpEnd = this._lerpStart.add(this._offset); - } - - public update(elapsed: number): void { - if (!this._initialized) { - this._initialize(); - this._initialized = true; - } - - // Need to update lerp time first, otherwise the first update will always be zero - this._currentLerpTime += elapsed; - let newX = this._tx.pos.x; - let newY = this._tx.pos.y; - if (this._currentLerpTime < this._lerpDuration) { - if (this._lerpEnd.x < this._lerpStart.x) { - newX = - this._lerpStart.x - - (this.easingFcn(this._currentLerpTime, this._lerpEnd.x, this._lerpStart.x, this._lerpDuration) - this._lerpEnd.x); - } else { - newX = this.easingFcn(this._currentLerpTime, this._lerpStart.x, this._lerpEnd.x, this._lerpDuration); - } - - if (this._lerpEnd.y < this._lerpStart.y) { - newY = - this._lerpStart.y - - (this.easingFcn(this._currentLerpTime, this._lerpEnd.y, this._lerpStart.y, this._lerpDuration) - this._lerpEnd.y); - } else { - newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration); - } - // Given the lerp position figure out the velocity in pixels per second - const seconds = elapsed / 1000; - this._motion.vel = vec(seconds === 0 ? 0 : (newX - this._tx.pos.x) / seconds, seconds === 0 ? 0 : (newY - this._tx.pos.y) / seconds); - } else { - this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y); - this._motion.vel = Vector.Zero; - } - } - public isComplete(): boolean { - return this._stopped || this._currentLerpTime >= this._lerpDuration; - } - - public reset(): void { - this._initialized = false; - this._stopped = false; - this._currentLerpTime = 0; - } - public stop(): void { - this._motion.vel = vec(0, 0); - this._stopped = true; - } -} diff --git a/src/engine/actions/action/ease-to.ts b/src/engine/actions/action/ease-to.ts deleted file mode 100644 index ecf95d74fa..0000000000 --- a/src/engine/actions/action/ease-to.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { Entity } from '../../entity-component-system/entity'; -import { TransformComponent } from '../../entity-component-system/components/transform-component'; -import { MotionComponent } from '../../entity-component-system/components/motion-component'; -import { vec, Vector } from '../../math/vector'; -import type { Action } from '../action'; -import { nextActionId } from '../action'; - -/** - * @deprecated use moveTo({pos: Vector, duration: number, easing: EasingFunction}) - */ -export class EaseTo implements Action { - id = nextActionId(); - private _tx: TransformComponent; - private _motion: MotionComponent; - private _currentLerpTime: number = 0; - private _lerpDuration: number = 1 * 1000; // 1 second - private _lerpStart: Vector = new Vector(0, 0); - private _lerpEnd: Vector = new Vector(0, 0); - private _initialized: boolean = false; - private _stopped: boolean = false; - constructor( - entity: Entity, - x: number, - y: number, - duration: number, - public easingFcn: (currentTime: number, startValue: number, endValue: number, duration: number) => number - ) { - this._tx = entity.get(TransformComponent); - this._motion = entity.get(MotionComponent); - this._lerpDuration = duration; - this._lerpEnd = new Vector(x, y); - } - private _initialize() { - this._lerpStart = new Vector(this._tx.pos.x, this._tx.pos.y); - this._currentLerpTime = 0; - } - - public update(elapsed: number): void { - if (!this._initialized) { - this._initialize(); - this._initialized = true; - } - - // Need to update lerp time first, otherwise the first update will always be zero - this._currentLerpTime += elapsed; - let newX = this._tx.pos.x; - let newY = this._tx.pos.y; - if (this._currentLerpTime < this._lerpDuration) { - if (this._lerpEnd.x < this._lerpStart.x) { - newX = - this._lerpStart.x - - (this.easingFcn(this._currentLerpTime, this._lerpEnd.x, this._lerpStart.x, this._lerpDuration) - this._lerpEnd.x); - } else { - newX = this.easingFcn(this._currentLerpTime, this._lerpStart.x, this._lerpEnd.x, this._lerpDuration); - } - - if (this._lerpEnd.y < this._lerpStart.y) { - newY = - this._lerpStart.y - - (this.easingFcn(this._currentLerpTime, this._lerpEnd.y, this._lerpStart.y, this._lerpDuration) - this._lerpEnd.y); - } else { - newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration); - } - // Given the lerp position figure out the velocity in pixels per second - const seconds = elapsed / 1000; - this._motion.vel = vec(seconds === 0 ? 0 : (newX - this._tx.pos.x) / seconds, seconds === 0 ? 0 : (newY - this._tx.pos.y) / seconds); - } else { - this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y); - this._motion.vel = Vector.Zero; - } - } - public isComplete(): boolean { - return this._stopped || this._currentLerpTime >= this._lerpDuration; - } - - public reset(): void { - this._initialized = false; - this._stopped = false; - this._currentLerpTime = 0; - } - public stop(): void { - this._motion.vel = vec(0, 0); - this._stopped = true; - } -} diff --git a/src/engine/actions/action/move-by.ts b/src/engine/actions/action/move-by.ts index 73ac0b5556..dd6609d425 100644 --- a/src/engine/actions/action/move-by.ts +++ b/src/engine/actions/action/move-by.ts @@ -4,8 +4,6 @@ import type { Entity } from '../../entity-component-system/entity'; import type { Easing } from '../../math'; import { clamp, lerp, linear, remap } from '../../math'; import { Vector, vec } from '../../math/vector'; -import type { EasingFunction } from '../../util/easing-functions'; -import { EasingFunctions, isLegacyEasing } from '../../util/easing-functions'; import { Logger } from '../../util/log'; import type { Action } from '../action'; import { nextActionId } from '../action'; @@ -13,7 +11,7 @@ import { nextActionId } from '../action'; export interface MoveByOptions { offset: Vector; duration: number; - easing?: Easing | EasingFunction; + easing?: Easing; } /** @@ -34,9 +32,7 @@ export class MoveByWithOptions implements Action { private _stopped: boolean = false; private _motion: MotionComponent; private _offset: Vector; - private _legacyEasing: EasingFunction = EasingFunctions.Linear; private _easing: Easing = linear; - private _useLegacyEasing = false; constructor( public entity: Entity, options: MoveByOptions @@ -44,10 +40,6 @@ export class MoveByWithOptions implements Action { this._offset = options.offset; this._easing = options.easing ?? this._easing; - if (isLegacyEasing(options.easing)) { - this._legacyEasing = options.easing; - this._useLegacyEasing = true; - } this._tx = entity.get(TransformComponent); this._motion = entity.get(MotionComponent); if (!this._tx) { @@ -66,15 +58,8 @@ export class MoveByWithOptions implements Action { const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const currentPos = this._tx.pos; - let newPosX = 0; - let newPosY = 0; - if (this._useLegacyEasing) { - newPosX = this._legacyEasing(t, this._start.x, this._end.x, 1); - newPosY = this._legacyEasing(t, this._start.y, this._end.y, 1); - } else { - newPosX = lerp(this._start.x, this._end.x, this._easing(t)); - newPosY = lerp(this._start.y, this._end.y, this._easing(t)); - } + const newPosX = lerp(this._start.x, this._end.x, this._easing(t)); + const newPosY = lerp(this._start.y, this._end.y, this._easing(t)); const seconds = elapsed / 1000; const velX = seconds === 0 ? 0 : (newPosX - currentPos.x) / seconds; @@ -88,7 +73,7 @@ export class MoveByWithOptions implements Action { } } public isComplete(entity: Entity): boolean { - return this._stopped || this._currentMs < 0; + return this._stopped || this._currentMs <= 0; } public stop(): void { diff --git a/src/engine/actions/action/move-to.ts b/src/engine/actions/action/move-to.ts index b56ded98ab..57e43a9b31 100644 --- a/src/engine/actions/action/move-to.ts +++ b/src/engine/actions/action/move-to.ts @@ -4,15 +4,13 @@ import type { Entity } from '../../entity-component-system/entity'; import type { Easing } from '../../math'; import { clamp, lerp, linear, remap } from '../../math'; import { Vector, vec } from '../../math/vector'; -import type { EasingFunction } from '../../util/easing-functions'; -import { EasingFunctions, isLegacyEasing } from '../../util/easing-functions'; import type { Action } from '../action'; import { nextActionId } from '../action'; export interface MoveToOptions { pos: Vector; duration: number; - easing?: Easing | EasingFunction; + easing?: Easing; } /** @@ -33,8 +31,6 @@ export class MoveToWithOptions implements Action { private _stopped: boolean = false; private _motion: MotionComponent; private _easing: Easing = linear; - private _legacyEasing: EasingFunction = EasingFunctions.Linear; - private _useLegacyEasing = false; constructor( public entity: Entity, @@ -42,10 +38,6 @@ export class MoveToWithOptions implements Action { ) { this._end = options.pos; this._easing = options.easing ?? this._easing; - if (isLegacyEasing(options.easing)) { - this._legacyEasing = options.easing; - this._useLegacyEasing = true; - } this._tx = entity.get(TransformComponent); this._motion = entity.get(MotionComponent); if (!this._tx) { @@ -63,15 +55,8 @@ export class MoveToWithOptions implements Action { const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1); const currentPos = this._tx.pos; - let newPosX = 0; - let newPosY = 0; - if (this._useLegacyEasing) { - newPosX = this._legacyEasing(t, this._start.x, this._end.x, 1); - newPosY = this._legacyEasing(t, this._start.y, this._end.y, 1); - } else { - newPosX = lerp(this._start.x, this._end.x, this._easing(t)); - newPosY = lerp(this._start.y, this._end.y, this._easing(t)); - } + const newPosX = lerp(this._start.x, this._end.x, this._easing(t)); + const newPosY = lerp(this._start.y, this._end.y, this._easing(t)); const seconds = elapsed / 1000; const velX = seconds === 0 ? 0 : (newPosX - currentPos.x) / seconds; @@ -85,7 +70,7 @@ export class MoveToWithOptions implements Action { } } public isComplete(entity: Entity): boolean { - return this._stopped || this._currentMs < 0; + return this._stopped || this._currentMs <= 0; } public stop(): void { diff --git a/src/engine/actions/actions-component.ts b/src/engine/actions/actions-component.ts index 1980d57048..733c6d7761 100644 --- a/src/engine/actions/actions-component.ts +++ b/src/engine/actions/actions-component.ts @@ -5,7 +5,6 @@ import type { Actor } from '../actor'; import { MotionComponent } from '../entity-component-system/components/motion-component'; import { TransformComponent } from '../entity-component-system/components/transform-component'; import type { Vector, RotationType } from '../math'; -import type { EasingFunction } from '../util/easing-functions'; import type { ActionQueue } from './action-queue'; import type { Action } from './action'; import type { Color } from '../color'; @@ -90,52 +89,6 @@ export class ActionsComponent extends Component implements ActionContextMethods return this._getCtx().curveTo.apply(this._ctx, [options]); } - /** - * This method will move an actor to the specified `x` and `y` position over the - * specified duration using a given {@apilink EasingFunctions} and return back the actor. This - * method is part of the actor 'Action' fluent API allowing action chaining. - * @param pos The x,y vector location to move the actor to - * @param duration The time it should take the actor to move to the new location in milliseconds - * @param easingFcn Use {@apilink EasingFunctions} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeTo(pos: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; - /** - * This method will move an actor to the specified `x` and `y` position over the - * specified duration using a given {@apilink EasingFunctions} and return back the actor. This - * method is part of the actor 'Action' fluent API allowing action chaining. - * @param x The x location to move the actor to - * @param y The y location to move the actor to - * @param duration The time it should take the actor to move to the new location in milliseconds - * @param easingFcn Use {@apilink EasingFunctions} or a custom function to use to calculate position, Default is {@apilink EasingFunctions.Linear} - * @deprecated use new moveTo({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeTo(x: number, y: number, duration: number, easingFcn?: EasingFunction): ActionContext; - public easeTo(...args: any[]): ActionContext { - return this._getCtx().easeTo.apply(this._ctx, args as any); - } - - /** - * - * @param offset - * @param duration - * @param easingFcn - * @deprecated use new moveBy({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeBy(offset: Vector, duration: number, easingFcn?: EasingFunction): ActionContext; - /** - * - * @param offsetX - * @param offsetY - * @param duration - * @param easingFcn - * @deprecated use new moveBy({pos: Vector, duration: number, easing: EasingFunction}) - */ - public easeBy(offsetX: number, offsetY: number, duration: number, easingFcn?: EasingFunction): ActionContext; - public easeBy(...args: any[]): ActionContext { - return this._getCtx().easeBy.apply(this._ctx, args as any); - } - /** * Moves an actor to a specified {@link Vector} in a given duration in milliseconds. * You may optionally specify an {@link EasingFunction} diff --git a/src/engine/actions/index.ts b/src/engine/actions/index.ts index 021cb7f57a..ce7cc972cf 100644 --- a/src/engine/actions/index.ts +++ b/src/engine/actions/index.ts @@ -9,8 +9,6 @@ export * from './action/repeat'; export * from './action/repeat-forever'; export * from './action/blink'; export * from './action/die'; -export * from './action/ease-to'; -export * from './action/ease-by'; export * from './action/fade'; export * from './action/follow'; export * from './action/meet'; diff --git a/src/engine/actor.ts b/src/engine/actor.ts index 25ac2792b9..df11661f03 100644 --- a/src/engine/actor.ts +++ b/src/engine/actor.ts @@ -865,7 +865,7 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia * Get the center point of an actor (global position) */ public get center(): Vector { - const globalPos = this.getGlobalPos(); + const globalPos = this.globalPos; return new Vector( globalPos.x + this.width / 2 - this.anchor.x * this.width, globalPos.y + this.height / 2 - this.anchor.y * this.height @@ -880,20 +880,11 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia } public get width() { - return this.collider.localBounds.width * this.getGlobalScale().x; + return this.collider.localBounds.width * this.globalScale.x; } public get height() { - return this.collider.localBounds.height * this.getGlobalScale().y; - } - - /** - * Gets this actor's rotation taking into account any parent relationships - * @returns Rotation angle in radians - * @deprecated Use {@apilink globalRotation} instead - */ - public getGlobalRotation(): number { - return this.get(TransformComponent).globalRotation; + return this.collider.localBounds.height * this.globalScale.y; } /** @@ -903,15 +894,6 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia return this.get(TransformComponent).globalRotation; } - /** - * Gets an actor's world position taking into account parent relationships, scaling, rotation, and translation - * @returns Position in world coordinates - * @deprecated Use {@apilink globalPos} instead - */ - public getGlobalPos(): Vector { - return this.get(TransformComponent).globalPos; - } - /** * The actor's world position taking into account parent relationships, scaling, rotation, and translation */ @@ -919,14 +901,6 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia return this.get(TransformComponent).globalPos; } - /** - * Gets the global scale of the Actor - * @deprecated Use {@apilink globalScale} instead - */ - public getGlobalScale(): Vector { - return this.get(TransformComponent).globalScale; - } - /** * The global scale of the Actor */ diff --git a/src/engine/camera.ts b/src/engine/camera.ts index f4abf48e46..2d5974754f 100644 --- a/src/engine/camera.ts +++ b/src/engine/camera.ts @@ -1,7 +1,5 @@ import type { Engine } from './engine'; import type { Screen } from './screen'; -import type { EasingFunction } from './util/easing-functions'; -import { EasingFunctions, isLegacyEasing } from './util/easing-functions'; import { Vector, vec } from './math/vector'; import type { Actor } from './actor'; import { removeItemFromArray } from './util/util'; @@ -386,11 +384,7 @@ export class Camera implements CanUpdate, CanInitialize { private _zoomResolve: (val: boolean) => void; private _zoomPromise: Promise; - private _legacyZoomEasing: EasingFunction = EasingFunctions.EaseInOutCubic; - private _useLegacyZoom = false; private _zoomEasing: Easing = easeInOutCubic; - private _legacyEasing: EasingFunction = EasingFunctions.EaseInOutCubic; - private _useLegacyEasing = false; private _easing: Easing = easeInOutCubic; private _halfWidth: number = 0; @@ -487,7 +481,7 @@ export class Camera implements CanUpdate, CanInitialize { * @returns A {@apilink Promise} that resolves when movement is finished, including if it's interrupted. * The {@apilink Promise} value is the {@apilink Vector} of the target position. It will be rejected if a move cannot be made. */ - public move(pos: Vector, duration: number, easingFn: Easing | EasingFunction = EasingFunctions.EaseInOutCubic): Promise { + public move(pos: Vector, duration: number, easingFn: Easing = easeInOutCubic): Promise { if (typeof easingFn !== 'function') { throw 'Please specify an EasingFunction'; } @@ -510,11 +504,7 @@ export class Camera implements CanUpdate, CanInitialize { this._lerpEnd = pos; this._currentLerpTime = 0; this._cameraMoving = true; - if (isLegacyEasing(easingFn)) { - this._legacyEasing = easingFn; - } else { - this._easing = easingFn; - } + this._easing = easingFn; return this._lerpPromise; } @@ -538,22 +528,14 @@ export class Camera implements CanUpdate, CanInitialize { * @param scale The scale of the zoom * @param duration The duration of the zoom in milliseconds */ - public zoomOverTime( - scale: number, - duration: number = 0, - easingFn: Easing | EasingFunction = EasingFunctions.EaseInOutCubic - ): Promise { + public zoomOverTime(scale: number, duration: number = 0, easingFn: Easing = easeInOutCubic): Promise { this._zoomPromise = new Promise((resolve) => { this._zoomResolve = resolve; }); if (duration) { this._isZooming = true; - if (isLegacyEasing(easingFn)) { - this._legacyZoomEasing = easingFn; - } else { - this._easing = easingFn; - } + this._easing = easingFn; this._currentZoomTime = 0; this._zoomDuration = duration; this._zoomStart = this.zoom; @@ -776,15 +758,7 @@ export class Camera implements CanUpdate, CanInitialize { if (this._isZooming) { if (this._currentZoomTime < this._zoomDuration) { - let newZoom = this.zoom; - if (this._useLegacyZoom) { - const zoomEasing = this._legacyZoomEasing; - newZoom = zoomEasing(this._currentZoomTime, this._zoomStart, this._zoomEnd, this._zoomDuration); - } else { - newZoom = lerp(this._zoomStart, this._zoomEnd, this._zoomEasing(this._currentZoomTime / this._zoomDuration)); - } - - this.zoom = newZoom; + this.zoom = lerp(this._zoomStart, this._zoomEnd, this._zoomEasing(this._currentZoomTime / this._zoomDuration)); this._currentZoomTime += elapsed; } else { this._isZooming = false; @@ -796,14 +770,9 @@ export class Camera implements CanUpdate, CanInitialize { if (this._cameraMoving) { if (this._currentLerpTime < this._lerpDuration) { - let lerpPoint = this.pos; - if (this._useLegacyEasing) { - const moveEasing = EasingFunctions.CreateVectorEasingFunction(this._legacyEasing); - lerpPoint = moveEasing(this._currentLerpTime, this._lerpStart, this._lerpEnd, this._lerpDuration); - } else { - lerpPoint.x = lerp(this._lerpStart.x, this._lerpEnd.x, this._easing(this._currentLerpTime / this._lerpDuration)); - lerpPoint.y = lerp(this._lerpStart.y, this._lerpEnd.y, this._easing(this._currentLerpTime / this._lerpDuration)); - } + const lerpPoint = this.pos; + lerpPoint.x = lerp(this._lerpStart.x, this._lerpEnd.x, this._easing(this._currentLerpTime / this._lerpDuration)); + lerpPoint.y = lerp(this._lerpStart.y, this._lerpEnd.y, this._easing(this._currentLerpTime / this._lerpDuration)); this.pos = lerpPoint; diff --git a/src/engine/collision/body-component.ts b/src/engine/collision/body-component.ts index 6cf73a7410..d4eb7f9fd3 100644 --- a/src/engine/collision/body-component.ts +++ b/src/engine/collision/body-component.ts @@ -157,13 +157,6 @@ export class BodyComponent extends Component implements Clonable public canSleep: boolean = this.collisionType === CollisionType.Active; 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 @@ -172,15 +165,6 @@ export class BodyComponent extends Component implements Clonable return this.canSleep && this._sleeping; } - /** - * Set the sleep state of the body - * @param sleeping - * @deprecated use isSleeping - */ - public setSleeping(sleeping: boolean) { - this.isSleeping = sleeping; - } - public wake() { if (this._sleeping && this.collisionType === CollisionType.Active) { this._sleeping = false; @@ -310,14 +294,6 @@ export class BodyComponent extends Component implements Clonable */ public limitDegreeOfFreedom: DegreeOfFreedom[] = []; - /** - * Returns if the owner is active - * @deprecated use isActive - */ - public get active() { - return !!this.owner?.isActive; - } - /** * Returns if the owner is active */ @@ -325,13 +301,6 @@ export class BodyComponent extends Component implements Clonable return !!this.owner?.isActive; } - /** - * @deprecated Use globalPos - */ - public get center() { - return this.globalPos; - } - public transform: TransformComponent; public motion: MotionComponent; diff --git a/src/engine/collision/bounding-box.ts b/src/engine/collision/bounding-box.ts index f8ac05465e..f3aa9c294a 100644 --- a/src/engine/collision/bounding-box.ts +++ b/src/engine/collision/bounding-box.ts @@ -435,16 +435,6 @@ export class BoundingBox { return BoundingBox.getSideFromIntersection(intersect); } - /** - * Draw a debug bounding box - * @param ex - * @param color - * @deprecated - */ - public draw(ex: ExcaliburGraphicsContext, options: RectGraphicsOptions = { color: Color.Yellow }) { - ex.debug.drawRect(this.left, this.top, this.width, this.height, options); - } - /** * Draw a debug bounding box * @param ex diff --git a/src/engine/director/slide.ts b/src/engine/director/slide.ts index e28582f6c8..d7494327fc 100644 --- a/src/engine/director/slide.ts +++ b/src/engine/director/slide.ts @@ -6,10 +6,11 @@ import type { TransitionOptions } from './transition'; import { Transition } from './transition'; import { Vector } from '../math/vector'; import { vec } from '../math/vector'; -import { EasingFunctions, type EasingFunction } from '../util/easing-functions'; import { CoordPlane } from '../math/coord-plane'; import { lerp } from '../math/lerp'; import type { Camera } from '../camera'; +import type { Easing } from '../math/easings'; +import { linear } from '../math/easings'; export interface SlideOptions { /** @@ -23,7 +24,7 @@ export interface SlideOptions { /** * Optionally select an easing function, by default linear (aka lerp) */ - easingFunction?: EasingFunction; + easingFunction?: Easing; } /** @@ -34,7 +35,7 @@ export interface SlideOptions { export class Slide extends Transition { private _image!: HTMLImageElement; private _screenCover!: Sprite; - private _easing = EasingFunctions.Linear; + private _easing = linear; readonly slideDirection: 'up' | 'down' | 'left' | 'right'; private _start: Vector = Vector.Zero; private _end: Vector = Vector.Zero; @@ -103,7 +104,7 @@ export class Slide extends Transition { } override onStart(progress: number): void { - const time = this._easing(this.distance, 0, 1, 1); + const time = this._easing(this.distance); this.transform.pos.x = lerp(this._start.x, this._end.x, time); this.transform.pos.y = lerp(this._start.y, this._end.y, time); this._camera.pos.x = lerp(this._startCameraPosition.x, this._destinationCameraPosition.x, time); @@ -111,7 +112,7 @@ export class Slide extends Transition { } override onUpdate(progress: number): void { - const time = this._easing(this.distance, 0, 1, 1); + const time = this._easing(this.distance); this.transform.pos.x = lerp(this._start.x, this._end.x, time); this.transform.pos.y = lerp(this._start.y, this._end.y, time); this._camera.pos.x = lerp(this._startCameraPosition.x, this._destinationCameraPosition.x, time); diff --git a/src/engine/director/transition.ts b/src/engine/director/transition.ts index d55b79ec18..442e0e501f 100644 --- a/src/engine/director/transition.ts +++ b/src/engine/director/transition.ts @@ -6,8 +6,6 @@ import { GraphicsComponent } from '../graphics'; import { CoordPlane } from '../math/coord-plane'; import { Vector } from '../math/vector'; import { clamp } from '../math/util'; -import type { EasingFunction } from '../util/easing-functions'; -import { EasingFunctions, isLegacyEasing } from '../util/easing-functions'; import type { CoroutineInstance } from '../util/coroutine'; import { coroutine } from '../util/coroutine'; import { Logger } from '../util/log'; @@ -40,7 +38,7 @@ export interface TransitionOptions { /** * Optionally specify a easing function, by default linear */ - easing?: Easing | EasingFunction; + easing?: Easing; /** * Optionally specify a transition direction, by default 'out' * @@ -61,7 +59,6 @@ export class Transition extends Entity { readonly blockInput: boolean; readonly duration: number; readonly easing: Easing; - readonly legacyEasing: EasingFunction; readonly direction: 'out' | 'in'; private _completeFuture = new Future(); protected _engine?: Engine; @@ -73,7 +70,6 @@ export class Transition extends Entity { private _currentProgress: number = 0; public done = this._completeFuture.promise; - private _useLegacyEasing: boolean = false; /** * Returns a number between [0, 1] indicating what state the transition is in. @@ -101,12 +97,7 @@ export class Transition extends Entity { super(); this.name = `Transition#${this.id}`; this.duration = options.duration; - if (isLegacyEasing(options.easing)) { - this.legacyEasing = options.easing ?? EasingFunctions.Linear; - this._useLegacyEasing = true; - } else { - this.easing = options.easing ?? linear; - } + this.easing = options.easing ?? linear; this.direction = options.direction ?? 'out'; this.hideLoader = options.hideLoader ?? false; @@ -143,17 +134,9 @@ export class Transition extends Entity { } if (this.direction === 'out') { - if (this._useLegacyEasing) { - this._currentProgress = clamp(this.legacyEasing(this._currentDistance, 0, 1, 1), 0, 1); - } else { - this._currentProgress = clamp(lerp(0, 1, this.easing(this._currentDistance)), 0, 1); - } + this._currentProgress = clamp(lerp(0, 1, this.easing(this._currentDistance)), 0, 1); } else { - if (this._useLegacyEasing) { - this._currentProgress = clamp(this.legacyEasing(this._currentDistance, 1, 0, 1), 0, 1); - } else { - this._currentProgress = clamp(lerp(1, 0, this.easing(this._currentDistance)), 0, 1); - } + this._currentProgress = clamp(lerp(1, 0, this.easing(this._currentDistance)), 0, 1); } } diff --git a/src/engine/engine.ts b/src/engine/engine.ts index d6a009ba13..e6e3b5ed63 100644 --- a/src/engine/engine.ts +++ b/src/engine/engine.ts @@ -651,7 +651,7 @@ export class Engine implements CanInitialize, * Indicates whether the engine is set to fullscreen or not */ public get isFullscreen(): boolean { - return this.screen.isFullScreen; + return this.screen.isFullscreen; } /** diff --git a/src/engine/entity-component-system/entity.ts b/src/engine/entity-component-system/entity.ts index cab1e34af1..3efe82e81b 100644 --- a/src/engine/entity-component-system/entity.ts +++ b/src/engine/entity-component-system/entity.ts @@ -148,22 +148,6 @@ export class Entity implements OnIniti */ public scene: Scene | null = null; - /** - * Whether this entity is active, if set to false it will be reclaimed - * @deprecated use isActive - */ - 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 */ diff --git a/src/engine/entity-component-system/index.ts b/src/engine/entity-component-system/index.ts index 3eaef870d5..7ff2156587 100644 --- a/src/engine/entity-component-system/index.ts +++ b/src/engine/entity-component-system/index.ts @@ -2,7 +2,6 @@ export * from './component'; export * from './entity'; export * from './entity-manager'; export * from './query'; -export * from './tag-query'; export * from './query-manager'; export * from './system'; export * from './system-manager'; diff --git a/src/engine/entity-component-system/tag-query.ts b/src/engine/entity-component-system/tag-query.ts deleted file mode 100644 index 36616c3498..0000000000 --- a/src/engine/entity-component-system/tag-query.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Observable } from '../util/observable'; -import type { Entity } from './entity'; - -/** - * @deprecated - */ -export class TagQuery { - public readonly id: string; - public tags = new Set(); - public entities: Entity[] = []; - /** - * This fires right after the component is added - */ - public entityAdded$ = new Observable>(); - /** - * This fires right before the component is actually removed from the entity, it will still be available for cleanup purposes - */ - public entityRemoved$ = new Observable>(); - - constructor(public readonly requiredTags: TKnownTags[]) { - if (requiredTags.length === 0) { - throw new Error('Cannot create tag query without tags'); - } - for (const tag of requiredTags) { - this.tags.add(tag); - } - - this.id = TagQuery.createId(requiredTags); - } - - static createId(requiredComponents: string[]) { - return requiredComponents.slice().sort().join('-'); - } - - checkAndAdd(entity: Entity) { - if (!this.entities.includes(entity) && entity.hasAllTags(Array.from(this.tags))) { - this.entities.push(entity); - this.entityAdded$.notifyAll(entity); - return true; - } - return false; - } - - removeEntity(entity: Entity) { - const index = this.entities.indexOf(entity); - if (index > -1) { - this.entities.splice(index, 1); - this.entityRemoved$.notifyAll(entity); - } - } - - /** - * Returns a list of entities that match the query - * @param sort Optional sorting function to sort entities returned from the query - */ - public getEntities(sort?: (a: Entity, b: Entity) => number): Entity[] { - if (sort) { - this.entities.sort(sort); - } - return this.entities; - } -} diff --git a/src/engine/entity-component-system/world.ts b/src/engine/entity-component-system/world.ts index 4fad113963..b3111f9c66 100644 --- a/src/engine/entity-component-system/world.ts +++ b/src/engine/entity-component-system/world.ts @@ -33,13 +33,6 @@ export class World { return this.queryManager.createQuery(params); } - /** - * @deprecated - */ - queryTags(requiredTags: TKnownTags[]): Query { - return this.queryManager.createQuery({ tags: { all: requiredTags } }) as any; - } - /** * Update systems by type and time elapsed in milliseconds */ diff --git a/src/engine/graphics/animation.ts b/src/engine/graphics/animation.ts index dd58717202..7b92e00c23 100644 --- a/src/engine/graphics/animation.ts +++ b/src/engine/graphics/animation.ts @@ -124,11 +124,7 @@ export interface FromSpriteSheetOptions { * the default duration. */ frameCoordinates: { x: number; y: number; duration?: number; options?: GetSpriteOptions }[]; - /** - * Optionally specify a default duration for frames in milliseconds - * @deprecated use `durationPerFrame` - */ - durationPerFrameMs?: number; + /** * Optionally specify a default duration for frames in milliseconds */ @@ -289,8 +285,8 @@ export class Animation extends Graphic implements HasTick { * @returns Animation */ public static fromSpriteSheetCoordinates(this: T, options: FromSpriteSheetOptions): InstanceType { - const { spriteSheet, frameCoordinates, durationPerFrame, durationPerFrameMs, speed, strategy, reverse, data } = options; - const defaultDuration = durationPerFrame ?? durationPerFrameMs ?? 100; + const { spriteSheet, frameCoordinates, durationPerFrame, speed, strategy, reverse, data } = options; + const defaultDuration = durationPerFrame ?? 100; const frames: Frame[] = []; for (const coord of frameCoordinates) { const { x, y, duration, options } = coord; diff --git a/src/engine/graphics/graphics-component.ts b/src/engine/graphics/graphics-component.ts index d4523a5933..d72886bd75 100644 --- a/src/engine/graphics/graphics-component.ts +++ b/src/engine/graphics/graphics-component.ts @@ -111,22 +111,6 @@ export class GraphicsComponent extends Component { public onPostTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void; private _color?: Color; - /** - * Sets or gets wether any drawing should be visible in this component - * @deprecated use isVisible - */ - 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 */ diff --git a/src/engine/index.ts b/src/engine/index.ts index 3056e12c66..5e373bc571 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -97,7 +97,6 @@ export { util as Util }; export * from './util/browser'; export * from './util/decorators'; export * from './util/detector'; -export * from './util/easing-functions'; export * from './util/observable'; export * from './util/log'; export * from './util/pool'; diff --git a/src/engine/input/gamepad.ts b/src/engine/input/gamepad.ts index 11206bea37..4dac530ed5 100644 --- a/src/engine/input/gamepad.ts +++ b/src/engine/input/gamepad.ts @@ -314,16 +314,6 @@ export class Gamepad { this._buttonsUp = new Array(16); } - /** - * Whether or not the given button is pressed - * @deprecated will be removed in v0.28.0. Use isButtonHeld instead - * @param button The button to query - * @param threshold The threshold over which the button is considered to be pressed - */ - public isButtonPressed(button: Buttons | number, threshold: number = 1) { - return this._buttons[button] >= threshold; - } - /** * Tests if a certain button is held down. This is persisted between frames. * @param button The button to query diff --git a/src/engine/math/vector.ts b/src/engine/math/vector.ts index cb2936c3c5..004ea7383b 100644 --- a/src/engine/math/vector.ts +++ b/src/engine/math/vector.ts @@ -194,24 +194,6 @@ export class Vector implements Clonable { return this; } - /** - * The size (magnitude) of the Vector - * @deprecated Will be removed in v1, use Vector.magnitude - */ - public get size(): number { - return this.distance(); - } - - /** - * Setting the size mutates the current vector - * @warning Can be used to set the size of the vector, **be very careful using this, mutating vectors can cause hard to find bugs** - * @deprecated Will be removed in v1, use Vector.magnitude - */ - public set size(newLength: number) { - const v = this.normalize().scale(newLength); - this.setTo(v.x, v.y); - } - /** * The magnitude (length) of the Vector */ diff --git a/src/engine/screen.ts b/src/engine/screen.ts index 0502d7fbe5..b51f89516d 100644 --- a/src/engine/screen.ts +++ b/src/engine/screen.ts @@ -602,14 +602,6 @@ export class Screen { this.graphicsContext.smoothing = this._antialiasing; } - /** - * Returns true if excalibur is fullscreen using the browser fullscreen api - * @deprecated use isFullscreen() - */ - public get isFullScreen() { - return this._isFullscreen; - } - /** * Returns true if excalibur is fullscreen using the browser fullscreen api */ @@ -617,18 +609,6 @@ export class Screen { return this._isFullscreen; } - /** - * Requests to go 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 - * @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. @@ -661,14 +641,6 @@ export class Screen { return Promise.resolve(); } - /** - * Requests to exit fullscreen using the browser fullscreen api - * @deprecated use exitFullscreen() - */ - public exitFullScreen(): Promise { - return this.exitFullscreen(); - } - public exitFullscreen(): Promise { return document.exitFullscreen(); } diff --git a/src/engine/tile-map/isometric-map.ts b/src/engine/tile-map/isometric-map.ts index fc0d372ca6..50f322b8f8 100644 --- a/src/engine/tile-map/isometric-map.ts +++ b/src/engine/tile-map/isometric-map.ts @@ -291,22 +291,6 @@ export class IsometricMap extends Entity implements HasNestedPointerEvents { */ public readonly tiles: IsometricTile[]; - /** - * Whether tiles should be visible - * @deprecated use isVisible - */ - 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 */ diff --git a/src/engine/timer.ts b/src/engine/timer.ts index b05ab3c47e..955909c825 100644 --- a/src/engine/timer.ts +++ b/src/engine/timer.ts @@ -38,10 +38,6 @@ export interface TimerOptions { * If a number is specified then it will only repeat a number of times */ numberOfRepeats?: number; - /** - * @deprecated use action: () => void, will be removed in v1.0 - */ - fcn?: () => void; /** * Action to perform every time the timer fires */ @@ -102,7 +98,7 @@ export class Timer { public scene: Scene = null; constructor(options: TimerOptions) { - const fcn = options.action ?? options.fcn; + const fcn = options.action; const interval = options.interval; const repeats = options.repeats; const numberOfRepeats = options.numberOfRepeats; diff --git a/src/engine/util/easing-functions.ts b/src/engine/util/easing-functions.ts deleted file mode 100644 index 15c017c37f..0000000000 --- a/src/engine/util/easing-functions.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { Vector } from '../math/vector'; - -/** - * A definition of an EasingFunction. See {@apilink EasingFunctions}. - * @deprecated - */ -// tslint:disable-next-line -export interface EasingFunction { - (currentTime: number, startValue: TValueToEase, endValue: TValueToEase, duration: number): TValueToEase; -} - -export function isLegacyEasing(x?: Function): x is EasingFunction { - return !!x && x.length === 4; -} - -/** - * Standard easing functions for motion in Excalibur, defined on a domain of [0, duration] and a range from [+startValue,+endValue] - * Given a time, the function will return a value from positive startValue to positive endValue. - * - * ```js - * function Linear (t) { - * return t * t; - * } - * - * // accelerating from zero velocity - * function EaseInQuad (t) { - * return t * t; - * } - * - * // decelerating to zero velocity - * function EaseOutQuad (t) { - * return t * (2 - t); - * } - * - * // acceleration until halfway, then deceleration - * function EaseInOutQuad (t) { - * return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t; - * } - * - * // accelerating from zero velocity - * function EaseInCubic (t) { - * return t * t * t; - * } - * - * // decelerating to zero velocity - * function EaseOutCubic (t) { - * return (--t) * t * t + 1; - * } - * - * // acceleration until halfway, then deceleration - * function EaseInOutCubic (t) { - * return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1; - * } - * ``` - * - * @deprecated - */ -export class EasingFunctions { - /** - * @deprecated - */ - public static CreateReversibleEasingFunction(easing: EasingFunction): EasingFunction { - return (time: number, start: number, end: number, duration: number) => { - if (end < start) { - return start - (easing(time, end, start, duration) - end); - } else { - return easing(time, start, end, duration); - } - }; - } - - /** - * @deprecated - */ - public static CreateVectorEasingFunction(easing: EasingFunction): EasingFunction { - return (time: number, start: Vector, end: Vector, duration: number) => { - return new Vector(easing(time, start.x, end.x, duration), easing(time, start.y, end.y, duration)); - }; - } - - /** - * @deprecated use ex.linear - */ - public static Linear: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - return (endValue * currentTime) / duration + startValue; - } - ); - - /** - * @deprecated use ex.easeInQuad - */ - public static EaseInQuad = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration; - - return endValue * currentTime * currentTime + startValue; - } - ); - - /** - * @deprecated ex.easeOutQuad - */ - public static EaseOutQuad: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration; - return -endValue * currentTime * (currentTime - 2) + startValue; - } - ); - - /** - * @deprecated ex.easeInOutQuad - */ - public static EaseInOutQuad: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration / 2; - - if (currentTime < 1) { - return (endValue / 2) * currentTime * currentTime + startValue; - } - currentTime--; - - return (-endValue / 2) * (currentTime * (currentTime - 2) - 1) + startValue; - } - ); - - /** - * @deprecated ex.easeInCubic - */ - public static EaseInCubic: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration; - return endValue * currentTime * currentTime * currentTime + startValue; - } - ); - - /** - * @deprecated ex.easeOutCubic - */ - public static EaseOutCubic: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration; - currentTime--; - return endValue * (currentTime * currentTime * currentTime + 1) + startValue; - } - ); - - /** - * @deprecated use ex.easeInOutCubic - */ - public static EaseInOutCubic: EasingFunction = EasingFunctions.CreateReversibleEasingFunction( - (currentTime: number, startValue: number, endValue: number, duration: number) => { - endValue = endValue - startValue; - currentTime /= duration / 2; - if (currentTime < 1) { - return (endValue / 2) * currentTime * currentTime * currentTime + startValue; - } - currentTime -= 2; - return (endValue / 2) * (currentTime * currentTime * currentTime + 2) + startValue; - } - ); -} diff --git a/src/engine/util/index.ts b/src/engine/util/index.ts index 8a0e2e919c..2b08ad152f 100644 --- a/src/engine/util/index.ts +++ b/src/engine/util/index.ts @@ -4,7 +4,5 @@ export * from './log'; export * from './observable'; -export * from './easing-functions'; - import * as drawUtil from './draw-util'; export { drawUtil as DrawUtil }; diff --git a/src/spec/vitest/action-spec.ts b/src/spec/vitest/action-spec.ts index 2236ce14ce..fd68c76e0e 100644 --- a/src/spec/vitest/action-spec.ts +++ b/src/spec/vitest/action-spec.ts @@ -166,14 +166,14 @@ describe('Action', () => { describe('blink', () => { it('can blink on and off', () => { - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); actor.actions.blink(200, 200); scene.update(engine, 200); - expect(actor.graphics.visible).toBe(false); + expect(actor.graphics.isVisible).toBe(false); scene.update(engine, 250); - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); }); it('can be reset', () => { @@ -187,31 +187,31 @@ describe('Action', () => { }); it('can blink at a frequency forever', () => { - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); actor.actions.repeatForever((ctx) => ctx.blink(200, 200)); scene.update(engine, 200); for (let i = 0; i < 2; i++) { - expect(actor.graphics.visible).toBe(false); + expect(actor.graphics.isVisible).toBe(false); scene.update(engine, 200); - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); scene.update(engine, 200); } }); it('can be stopped', () => { - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); actor.actions.blink(1, 3000); scene.update(engine, 500); - expect(actor.graphics.visible).toBe(false); + expect(actor.graphics.isVisible).toBe(false); actor.actions.clearActions(); scene.update(engine, 500); scene.update(engine, 500); - expect(actor.graphics.visible).toBe(true); + expect(actor.graphics.isVisible).toBe(true); }); }); @@ -239,7 +239,7 @@ describe('Action', () => { expect(scene.actors.length).toBe(1); actor.actions.die(); scene.update(engine, 100); - expect(actor.active).toBe(false); + expect(actor.isActive).toBe(false); expect(scene.actors.length).toBe(0); }); @@ -526,19 +526,27 @@ describe('Action', () => { describe('easeBy', () => { it('can be reset', () => { - const easeTo = new ex.EaseBy(actor, 100, 0, 100, ex.EasingFunctions.EaseInOutCubic); + const easeTo = new ex.MoveByWithOptions(actor, { + offset: ex.vec(100, 0), + duration: 100, + easing: ex.easeInOutCubic + }); easeTo.update(1000); - expect(easeTo.isComplete()).toBe(true); + expect(easeTo.isComplete(actor)).toBe(true); easeTo.reset(); actor.pos = ex.vec(0, 0); - expect(easeTo.isComplete()).toBe(false); + expect(easeTo.isComplete(actor)).toBe(false); }); it('can be eased to a location given an easing function (x,y) overload', () => { actor.pos = ex.vec(100, 100); expect(actor.pos).toBeVector(ex.vec(100, 100)); - actor.actions.easeBy(100, 0, 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveBy({ + offset: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(150, 100)); @@ -557,7 +565,11 @@ describe('Action', () => { actor.pos = ex.vec(100, 100); expect(actor.pos).toBeVector(ex.vec(100, 100)); - actor.actions.easeBy(ex.vec(100, 0), 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveBy({ + offset: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(150, 100)); @@ -576,7 +588,11 @@ describe('Action', () => { actor.pos = ex.vec(100, 100); expect(actor.pos).toBeVector(ex.vec(100, 100)); - actor.actions.easeBy(100, 0, 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveBy({ + offset: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(150, 100)); @@ -593,18 +609,26 @@ describe('Action', () => { describe('easeTo', () => { it('can be reset', () => { - const easeTo = new ex.EaseTo(actor, 100, 0, 100, ex.EasingFunctions.EaseInOutCubic); + const easeTo = new ex.MoveToWithOptions(actor, { + pos: ex.vec(100, 0), + duration: 100, + easing: ex.easeInOutCubic + }); easeTo.update(1000); - expect(easeTo.isComplete()).toBe(true); + expect(easeTo.isComplete(actor)).toBe(true); easeTo.reset(); actor.pos = ex.vec(0, 0); - expect(easeTo.isComplete()).toBe(false); + expect(easeTo.isComplete(actor)).toBe(false); }); it('can be eased to a location given an easing function (x,y) overload', () => { expect(actor.pos).toBeVector(ex.vec(0, 0)); - actor.actions.easeTo(100, 0, 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveTo({ + pos: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(50, 0)); @@ -622,7 +646,11 @@ describe('Action', () => { it('can be eased to a location given an easing function vector overload', () => { expect(actor.pos).toBeVector(ex.vec(0, 0)); - actor.actions.easeTo(ex.vec(100, 0), 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveTo({ + pos: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(50, 0)); @@ -640,13 +668,18 @@ describe('Action', () => { it('can be eased to a location given an easing function vector overload', () => { expect(actor.pos).toBeVector(ex.vec(0, 0)); - actor.actions.easeTo(ex.vec(100, 0), 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveTo({ + pos: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(50, 0)); expect(actor.vel).toBeVector(ex.vec(100, 0)); scene.update(engine, 500); + scene.update(engine, 1); expect(actor.pos).toBeVector(ex.vec(100, 0)); expect(actor.vel).toBeVector(ex.vec(0, 0)); @@ -658,7 +691,11 @@ describe('Action', () => { it('can be stopped', () => { expect(actor.pos).toBeVector(ex.vec(0, 0)); - actor.actions.easeTo(100, 0, 1000, ex.EasingFunctions.EaseInOutCubic); + actor.actions.moveTo({ + pos: ex.vec(100, 0), + duration: 1000, + easing: ex.easeInOutCubic + }); scene.update(engine, 500); expect(actor.pos).toBeVector(ex.vec(50, 0)); diff --git a/src/spec/vitest/actor-spec.ts b/src/spec/vitest/actor-spec.ts index 3434cb876c..36c0a9bc7f 100644 --- a/src/spec/vitest/actor-spec.ts +++ b/src/spec/vitest/actor-spec.ts @@ -538,8 +538,8 @@ describe('A game actor', () => { actor.addChild(child); motionSystem.update(100); - expect(child.getGlobalPos().x).toBeCloseTo(10, 0.001); - expect(child.getGlobalPos().y).toBeCloseTo(20, 0.001); + expect(child.globalPos.x).toBeCloseTo(10, 0.001); + expect(child.globalPos.y).toBeCloseTo(20, 0.001); }); it('is rotated along with its grandparent', () => { @@ -555,9 +555,9 @@ describe('A game actor', () => { child.addChild(grandchild); motionSystem.update(100); - expect(grandchild.getGlobalRotation()).toBe(rotation); - expect(grandchild.getGlobalPos().x).toBeCloseTo(10, 0.001); - expect(grandchild.getGlobalPos().y).toBeCloseTo(30, 0.001); + expect(grandchild.globalRotation).toBe(rotation); + expect(grandchild.globalPos.x).toBeCloseTo(10, 0.001); + expect(grandchild.globalPos.y).toBeCloseTo(30, 0.001); }); it('is scaled along with its parent', () => { @@ -570,8 +570,8 @@ describe('A game actor', () => { actor.addChild(child); motionSystem.update(100); - expect(child.getGlobalPos().x).toBe(30); - expect(child.getGlobalPos().y).toBe(30); + expect(child.globalPos.x).toBe(30); + expect(child.globalPos.y).toBe(30); }); it('is scaled along with its grandparent', () => { @@ -590,8 +590,8 @@ describe('A game actor', () => { // p = (10, 10) // c = (10 * 2 + 10, 10 * 2 + 10) = (30, 30) // gc = (10 * 2 + 30, 10 * 2 + 30) = (50, 50) - expect(grandchild.getGlobalPos().x).toBe(50); - expect(grandchild.getGlobalPos().y).toBe(50); + expect(grandchild.globalPos.x).toBe(50); + expect(grandchild.globalPos.y).toBe(50); }); it('is rotated and scaled along with its parent', () => { @@ -606,8 +606,8 @@ describe('A game actor', () => { actor.addChild(child); motionSystem.update(100); - expect(child.getGlobalPos().x).toBeCloseTo(10, 0.001); - expect(child.getGlobalPos().y).toBeCloseTo(30, 0.001); + expect(child.globalPos.x).toBeCloseTo(10, 0.001); + expect(child.globalPos.y).toBeCloseTo(30, 0.001); }); it('is rotated and scaled along with its grandparent', () => { @@ -624,8 +624,8 @@ describe('A game actor', () => { child.addChild(grandchild); motionSystem.update(100); - expect(grandchild.getGlobalPos().x).toBeCloseTo(10, 0.001); - expect(grandchild.getGlobalPos().y).toBeCloseTo(50, 0.001); + expect(grandchild.globalPos.x).toBeCloseTo(10, 0.001); + expect(grandchild.globalPos.y).toBeCloseTo(50, 0.001); }); it('can find its global coordinates if it has a parent', () => { @@ -645,8 +645,8 @@ describe('A game actor', () => { actionSystem.update(1); motionSystem.update(1); - expect(childActor.getGlobalPos().x).toBe(60); - expect(childActor.getGlobalPos().y).toBe(65); + expect(childActor.globalPos.x).toBe(60); + expect(childActor.globalPos.y).toBe(65); }); it('can find its global coordinates if it has multiple parents', () => { @@ -665,8 +665,8 @@ describe('A game actor', () => { actor.update(engine, 1); scene.update(engine, 1); - expect(grandChildActor.getGlobalPos().x).toBe(70); - expect(grandChildActor.getGlobalPos().y).toBe(75); + expect(grandChildActor.globalPos.x).toBe(70); + expect(grandChildActor.globalPos.y).toBe(75); }); it("can find its global coordinates if it doesn't have a parent", () => { @@ -679,8 +679,8 @@ describe('A game actor', () => { actor.update(engine, 1); scene.update(engine, 1); - expect(actor.getGlobalPos().x).toBe(10); - expect(actor.getGlobalPos().y).toBe(15); + expect(actor.globalPos.x).toBe(10); + expect(actor.globalPos.y).toBe(15); }); it('can be removed from the scene', () => { @@ -1032,7 +1032,7 @@ describe('A game actor', () => { childActor.graphics.onPostDraw = vi.fn(); - childActor.graphics.visible = true; + childActor.graphics.isVisible = true; scene.draw(engine.graphicsContext, 100); expect(childActor.graphics.onPostDraw).toHaveBeenCalled(); }); @@ -1045,7 +1045,7 @@ describe('A game actor', () => { childActor.graphics.onPostDraw = vi.fn(); - childActor.graphics.visible = false; + childActor.graphics.isVisible = false; scene.draw(engine.graphicsContext, 100); expect(childActor.graphics.onPostDraw).not.toHaveBeenCalled(); }); diff --git a/src/spec/vitest/bounding-box-spec.ts b/src/spec/vitest/bounding-box-spec.ts index be45684aff..20b3cde36b 100644 --- a/src/spec/vitest/bounding-box-spec.ts +++ b/src/spec/vitest/bounding-box-spec.ts @@ -318,7 +318,7 @@ function runBoundingBoxTests(creationType: string, createBoundingBox: Function) const ray = new ex.Ray(new ex.Vector(-10, 5), ex.Vector.Right); - expect(bb.rayCast(ray, ray.dir.size)).toBe(false); + expect(bb.rayCast(ray, ray.dir.magnitude)).toBe(false); }); it('ray cast when the origin is on the boundary', () => { diff --git a/src/spec/vitest/camera-spec.ts b/src/spec/vitest/camera-spec.ts index 663f5e5edc..a07967a39d 100644 --- a/src/spec/vitest/camera-spec.ts +++ b/src/spec/vitest/camera-spec.ts @@ -427,8 +427,8 @@ describe('A camera', () => { it('can lerp over time', () => new Promise((done) => { - engine.currentScene.camera.move(new ex.Vector(100, 100), 1000, ex.EasingFunctions.EaseOutCubic).then(() => { - engine.currentScene.camera.move(new ex.Vector(200, 200), 1000, ex.EasingFunctions.Linear).then(() => { + engine.currentScene.camera.move(new ex.Vector(100, 100), 1000, ex.easeOutCubic).then(() => { + engine.currentScene.camera.move(new ex.Vector(200, 200), 1000, ex.linear).then(() => { expect(engine.currentScene.camera.pos.x).toBe(200); expect(engine.currentScene.camera.pos.y).toBe(200); done(); diff --git a/src/spec/vitest/collision-spec.ts b/src/spec/vitest/collision-spec.ts index e737b3b8a1..1064dd3e7b 100644 --- a/src/spec/vitest/collision-spec.ts +++ b/src/spec/vitest/collision-spec.ts @@ -230,7 +230,7 @@ describe('A Collision', () => { const collisionHandler = (ev: ex.PreCollisionEvent) => { const timer = new ex.Timer({ interval: 30, - fcn: () => { + action: () => { expect(activeBlock.vel.x).toBeGreaterThan(0); expect(passiveBlock.vel.x).toBeLessThan(0); done(); diff --git a/src/spec/vitest/easing-function-spec.ts b/src/spec/vitest/easing-function-spec.ts deleted file mode 100644 index 142b978b22..0000000000 --- a/src/spec/vitest/easing-function-spec.ts +++ /dev/null @@ -1,189 +0,0 @@ -import * as ex from '@excalibur'; - -describe('An Easing Function', () => { - it('can interpolate linearly', () => { - const zeroTime = ex.EasingFunctions.Linear(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.Linear(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.Linear(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.Linear(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(12.5); - expect(threeQuarterTime).toBe(17.5); - expect(finalTime).toBe(20); - }); - - it('can be linearly reversible', () => { - const zeroTime = ex.EasingFunctions.Linear(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.Linear(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.Linear(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.Linear(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(17.5); - expect(threeQuarterTime).toBe(12.5); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseInQuad', () => { - const zeroTime = ex.EasingFunctions.EaseInQuad(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseInQuad(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInQuad(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseInQuad(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(10.625); - expect(threeQuarterTime).toBe(15.625); - expect(finalTime).toBe(20); - }); - - it('can be EaseInQuad reversible', () => { - const zeroTime = ex.EasingFunctions.EaseInQuad(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseInQuad(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInQuad(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseInQuad(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(19.375); - expect(threeQuarterTime).toBe(14.375); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseOutQuad', () => { - const zeroTime = ex.EasingFunctions.EaseOutQuad(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseOutQuad(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseOutQuad(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseOutQuad(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(14.375); - expect(threeQuarterTime).toBe(19.375); - expect(finalTime).toBe(20); - }); - - it('can be EaseOutQuad reversible', () => { - const zeroTime = ex.EasingFunctions.EaseOutQuad(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseOutQuad(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseOutQuad(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseOutQuad(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(15.625); - expect(threeQuarterTime).toBe(10.625); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseInOutQuad', () => { - const zeroTime = ex.EasingFunctions.EaseInOutQuad(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseInOutQuad(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInOutQuad(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseInOutQuad(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(11.25); - expect(threeQuarterTime).toBe(18.75); - expect(finalTime).toBe(20); - }); - - it('can be EaseInOutQuad reversible', () => { - const zeroTime = ex.EasingFunctions.EaseInOutQuad(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseInOutQuad(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInOutQuad(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseInOutQuad(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(18.75); - expect(threeQuarterTime).toBe(11.25); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseInCubic', () => { - const zeroTime = ex.EasingFunctions.EaseInCubic(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseInCubic(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInCubic(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseInCubic(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(10.15625); - expect(threeQuarterTime).toBe(14.21875); - expect(finalTime).toBe(20); - }); - - it('can be EaseInCubic reversible', () => { - const zeroTime = ex.EasingFunctions.EaseInCubic(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseInCubic(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInCubic(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseInCubic(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(19.84375); - expect(threeQuarterTime).toBe(15.78125); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseOutCubic', () => { - const zeroTime = ex.EasingFunctions.EaseOutCubic(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseOutCubic(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseOutCubic(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseOutCubic(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(15.78125); - expect(threeQuarterTime).toBe(19.84375); - expect(finalTime).toBe(20); - }); - - it('can be EaseOutCubic reversible', () => { - const zeroTime = ex.EasingFunctions.EaseOutCubic(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseOutCubic(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseOutCubic(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseOutCubic(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(14.21875); - expect(threeQuarterTime).toBe(10.15625); - expect(finalTime).toBe(10); - }); - - it('can interpolate EaseInOutCubic', () => { - const zeroTime = ex.EasingFunctions.EaseInOutCubic(0, 10, 20, 100); - const quarterTime = ex.EasingFunctions.EaseInOutCubic(25, 10, 20, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInOutCubic(75, 10, 20, 100); - const finalTime = ex.EasingFunctions.EaseInOutCubic(100, 10, 20, 100); - - expect(zeroTime).toBe(10); - expect(quarterTime).toBe(10.625); - expect(threeQuarterTime).toBe(19.375); - expect(finalTime).toBe(20); - }); - - it('can be EaseInOutCubic reversible', () => { - const zeroTime = ex.EasingFunctions.EaseInOutCubic(0, 20, 10, 100); - const quarterTime = ex.EasingFunctions.EaseInOutCubic(25, 20, 10, 100); - const threeQuarterTime = ex.EasingFunctions.EaseInOutCubic(75, 20, 10, 100); - const finalTime = ex.EasingFunctions.EaseInOutCubic(100, 20, 10, 100); - - expect(zeroTime).toBe(20); - expect(quarterTime).toBe(19.375); - expect(threeQuarterTime).toBe(10.625); - expect(finalTime).toBe(10); - }); - - it('can be used with vectors', () => { - const vectorEasing = ex.EasingFunctions.CreateVectorEasingFunction(ex.EasingFunctions.Linear); - - const zeroTime = vectorEasing(0, new ex.Vector(10, 10), new ex.Vector(20, 20), 100); - const quarterTime = vectorEasing(25, new ex.Vector(10, 10), new ex.Vector(20, 20), 100); - const threeQuarterTime = vectorEasing(75, new ex.Vector(10, 10), new ex.Vector(20, 20), 100); - const finalTime = vectorEasing(100, new ex.Vector(10, 10), new ex.Vector(20, 20), 100); - - expect(zeroTime.x).toBe(10); - expect(zeroTime.y).toBe(10); - expect(quarterTime.x).toBe(12.5); - expect(quarterTime.y).toBe(12.5); - expect(threeQuarterTime.x).toBe(17.5); - expect(threeQuarterTime.y).toBe(17.5); - expect(finalTime.x).toBe(20); - expect(finalTime.y).toBe(20); - }); -}); diff --git a/src/spec/vitest/graphics-component-spec.ts b/src/spec/vitest/graphics-component-spec.ts index b48d2acec7..f458317f18 100644 --- a/src/spec/vitest/graphics-component-spec.ts +++ b/src/spec/vitest/graphics-component-spec.ts @@ -11,7 +11,7 @@ describe('A Graphics ECS Component', () => { expect(sut.anchor).toBeVector(ex.vec(0.5, 0.5)); expect(sut.offset).toBeVector(ex.vec(0, 0)); expect(sut.opacity).toBe(1); - expect(sut.visible).toBe(true); + expect(sut.isVisible).toBe(true); expect(sut.current).toBeUndefined(); expect(sut.graphics).toEqual({}); }); @@ -32,7 +32,7 @@ describe('A Graphics ECS Component', () => { graphics.anchor = ex.vec(0, 0); graphics.offset = ex.vec(1, 1); graphics.opacity = 0.2; - graphics.visible = false; + graphics.isVisible = false; graphics.copyGraphics = true; graphics.onPreDraw = () => { /* do nothing */ @@ -50,7 +50,7 @@ describe('A Graphics ECS Component', () => { expect(sut.anchor).toBeVector(graphics.anchor); expect(sut.offset).toBeVector(graphics.offset); expect(sut.opacity).toEqual(graphics.opacity); - expect(sut.visible).toEqual(graphics.visible); + expect(sut.isVisible).toEqual(graphics.isVisible); expect(sut.copyGraphics).toEqual(graphics.copyGraphics); expect(sut.onPreDraw).toBe(sut.onPreDraw); expect(sut.onPostDraw).toBe(sut.onPostDraw); @@ -84,7 +84,7 @@ describe('A Graphics ECS Component', () => { expect(sut.anchor).toBeVector(ex.vec(0, 0)); expect(sut.offset).toBeVector(ex.vec(10, 11)); expect(sut.opacity).toBe(0.5); - expect(sut.visible).toBe(false); + expect(sut.isVisible).toBe(false); expect(sut.current).not.toBeNull(); expect(sut.graphics).toEqual({ 'some-gfx': rect diff --git a/src/spec/vitest/query-manager-spec.ts b/src/spec/vitest/query-manager-spec.ts index 80f272cd1f..a8d7bc501e 100644 --- a/src/spec/vitest/query-manager-spec.ts +++ b/src/spec/vitest/query-manager-spec.ts @@ -62,9 +62,9 @@ describe('A QueryManager', () => { world.entityManager.addEntity(entity2); // Query for all entities that have type A components - const queryA = world.queryTags(['A']); + const queryA = world.query({ tags: { all: ['A'] } }); // Query for all entities that have type A & B components - const queryAB = world.queryTags(['A', 'B']); + const queryAB = world.query({ tags: { all: ['A', 'B'] } }); expect(queryA.getEntities(), 'Both entities have component A').toEqual([entity1, entity2]); expect(queryAB.getEntities(), 'Only entity1 has both A+B').toEqual([entity1]); @@ -112,7 +112,7 @@ describe('A QueryManager', () => { entity2.addTag('A'); entity2.addTag('B'); - const queryAB = world.queryTags(['A', 'B']); + const queryAB = world.query({ tags: { all: ['A', 'B'] } }); expect(queryAB.getEntities()).toEqual([]); world.queryManager.addEntity(entity1); @@ -245,7 +245,7 @@ describe('A QueryManager', () => { entity2.addTag('A'); entity2.addTag('B'); - const queryAB = world.queryTags(['A', 'B']); + const queryAB = world.query({ tags: { all: ['A', 'B'] } }); world.queryManager.addEntity(entity1); world.queryManager.addEntity(entity2); expect(queryAB.getEntities()).toEqual([entity1, entity2]); @@ -290,7 +290,7 @@ describe('A QueryManager', () => { entity2.addTag('A'); entity2.addTag('B'); - const queryAB = world.queryTags(['A', 'B']); + const queryAB = world.query({ tags: { all: ['A', 'B'] } }); world.queryManager.addEntity(entity1); world.queryManager.addEntity(entity2); diff --git a/src/spec/vitest/scene-spec.ts b/src/spec/vitest/scene-spec.ts index bb80a0c896..c8a76b906f 100644 --- a/src/spec/vitest/scene-spec.ts +++ b/src/spec/vitest/scene-spec.ts @@ -295,7 +295,7 @@ describe('A scene', () => { it('draws visible Actors', () => { engine.goToScene('root'); - actor.graphics.visible = true; + actor.graphics.isVisible = true; actor.graphics.onPostDraw = vi.fn(); scene.add(actor); @@ -306,7 +306,7 @@ describe('A scene', () => { it('does not draw invisible actors', () => { engine.goToScene('root'); - actor.graphics.visible = false; + actor.graphics.isVisible = false; actor.graphics.onPostDraw = vi.fn(); scene.add(actor); @@ -630,7 +630,7 @@ describe('A scene', () => { const scene1 = new ex.Scene(); const scene2 = new ex.Scene(); const timer = new ex.Timer({ - fcn: () => { + action: () => { /* pass */ }, interval: 100 @@ -692,7 +692,7 @@ describe('A scene', () => { // create Timer const timer = new ex.Timer({ interval: 10, - fcn: () => { + action: () => { scene.add(actor); }, repeats: false @@ -728,7 +728,7 @@ describe('A scene', () => { // create Timer const timer = new ex.Timer({ interval: 10, - fcn: () => { + action: () => { scene.add(actor); }, repeats: false @@ -757,7 +757,7 @@ describe('A scene', () => { it('will not kill the actor if it is already dead', () => { scene.add(actor); - actor.active = false; + actor.isActive = false; vi.spyOn(actor, 'kill'); @@ -789,7 +789,7 @@ describe('A scene', () => { // create Timer const timer = new ex.Timer({ interval: 10, - fcn: () => { + action: () => { scene.add(tilemap); }, repeats: false diff --git a/src/spec/vitest/screen-element-spec.ts b/src/spec/vitest/screen-element-spec.ts index 852bd78525..36d578a919 100644 --- a/src/spec/vitest/screen-element-spec.ts +++ b/src/spec/vitest/screen-element-spec.ts @@ -86,7 +86,7 @@ describe('A ScreenElement', () => { }); it('is drawn when visible', () => { - screenElement.graphics.visible = true; + screenElement.graphics.isVisible = true; screenElement.graphics.onPostDraw = vi.fn(); scene.add(screenElement); @@ -96,7 +96,7 @@ describe('A ScreenElement', () => { }); it('is not drawn when not visible', () => { - screenElement.graphics.visible = false; + screenElement.graphics.isVisible = false; screenElement.graphics.onPostDraw = vi.fn(); scene.add(screenElement); diff --git a/src/spec/vitest/screen-spec.ts b/src/spec/vitest/screen-spec.ts index bd74cd1ec2..85b4117c6c 100644 --- a/src/spec/vitest/screen-spec.ts +++ b/src/spec/vitest/screen-spec.ts @@ -385,7 +385,7 @@ describe('A Screen', () => { viewport: { width: 800, height: 600 } }); - expect(sut.isFullScreen).toBe(false); + expect(sut.isFullscreen).toBe(false); const nonFullScreenPage = sut.screenToPageCoordinates(ex.vec(800, 600)); expect(nonFullScreenPage).toBeVector(ex.vec(800, 600)); @@ -393,7 +393,7 @@ describe('A Screen', () => { expect(nonFullScreenScreen).toBeVector(ex.vec(800, 600)); canvas.dispatchEvent(new Event('fullscreenchange')); - expect(sut.isFullScreen).toBe(true); + expect(sut.isFullscreen).toBe(true); const page = sut.screenToPageCoordinates(ex.vec(800, 600)); expect(page).toBeVector(ex.vec(1000, 775)); @@ -412,14 +412,14 @@ describe('A Screen', () => { viewport: { width: 800, height: 600 } }); - expect(sut.isFullScreen).toBe(false); + expect(sut.isFullscreen).toBe(false); const nonFullScreenPage = sut.screenToPageCoordinates(ex.vec(800, 600)); expect(nonFullScreenPage).toBeVector(ex.vec(800, 600)); const nonFullScreenScreen = sut.pageToScreenCoordinates(nonFullScreenPage); expect(nonFullScreenScreen).toBeVector(ex.vec(800, 600)); canvas.dispatchEvent(new Event('fullscreenchange')); - expect(sut.isFullScreen).toBe(true); + expect(sut.isFullscreen).toBe(true); const page = sut.screenToPageCoordinates(ex.vec(800, 600)); expect(page).toBeVector(ex.vec(1183.33, 800)); diff --git a/src/spec/vitest/slide-spec.ts b/src/spec/vitest/slide-spec.ts index fa82cf85ea..c0f09d8ce0 100644 --- a/src/spec/vitest/slide-spec.ts +++ b/src/spec/vitest/slide-spec.ts @@ -188,7 +188,7 @@ describe('A Slide transition', () => { const sut = new ex.Slide({ duration: 1000, slideDirection: 'up', - easingFunction: ex.EasingFunctions.EaseInOutCubic + easingFunction: ex.easeInOutCubic }); const scene = new ex.Scene(); scene.add( diff --git a/src/spec/vitest/tag-query-spec.ts b/src/spec/vitest/tag-query-spec.ts deleted file mode 100644 index 940fcb635e..0000000000 --- a/src/spec/vitest/tag-query-spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import * as ex from '@excalibur'; - -describe('A tag query', () => { - it('should exist', () => { - expect(ex.TagQuery).toBeDefined(); - }); - - it('can be created', () => { - expect(new ex.TagQuery(['A', 'B'])).not.toBeNull(); - }); - - it('has an id', () => { - const query = new ex.TagQuery(['A', 'B']); - expect(query.id).toEqual('A-B'); - }); - - it('can match with entities', () => { - const queryAB = new ex.TagQuery(['A', 'B']); - const entity1 = new ex.Entity(); - entity1.addTag('A'); - entity1.addTag('B'); - - const entity2 = new ex.Entity(); - entity2.addTag('A'); - - expect(entity1.hasAllTags(queryAB.requiredTags), 'entity1 should match has both components A, B').toBe(true); - expect(entity2.hasAllTags(queryAB.requiredTags), 'entity2 should not match, only has 1 component A').toBe(false); - }); - - it('can only add entities that match', () => { - const queryAB = new ex.TagQuery(['A', 'B']); - const entity1 = new ex.Entity(); - entity1.addTag('A'); - entity1.addTag('B'); - - const entity2 = new ex.Entity(); - entity2.addTag('A'); - - queryAB.checkAndAdd(entity1); - expect(queryAB.getEntities()).toEqual([entity1]); - - queryAB.checkAndAdd(entity2); - expect(queryAB.getEntities()).toEqual([entity1]); - }); - - it('can remove entities', () => { - const queryAB = new ex.TagQuery(['A', 'B']); - const entity1 = new ex.Entity(); - entity1.addTag('A'); - entity1.addTag('B'); - - const entity2 = new ex.Entity(); - entity2.addTag('A'); - - queryAB.checkAndAdd(entity1); - expect(queryAB.getEntities()).toEqual([entity1]); - - queryAB.removeEntity(entity2); - expect(queryAB.getEntities()).toEqual([entity1]); - - queryAB.removeEntity(entity1); - expect(queryAB.getEntities()).toEqual([]); - }); - - it('notifies observers of when something is added to the query', () => - new Promise((done) => { - const queryAB = new ex.TagQuery(['A', 'B']); - const entity1 = new ex.Entity(); - entity1.addTag('A'); - entity1.addTag('B'); - - queryAB.entityAdded$.subscribe((e) => { - expect(e).toBe(entity1); - done(); - }); - - queryAB.checkAndAdd(entity1); - })); - - it('notifies observers of when something is added to the query', () => - new Promise((done) => { - const queryAB = new ex.TagQuery(['A', 'B']); - const entity1 = new ex.Entity(); - entity1.addTag('A'); - entity1.addTag('B'); - queryAB.checkAndAdd(entity1); - - queryAB.entityRemoved$.subscribe((e) => { - expect(e).toBe(entity1); - done(); - }); - - queryAB.removeEntity(entity1); - })); -}); diff --git a/src/spec/vitest/timer-spec.ts b/src/spec/vitest/timer-spec.ts index c1c0c8c219..0a8dedd330 100644 --- a/src/spec/vitest/timer-spec.ts +++ b/src/spec/vitest/timer-spec.ts @@ -13,7 +13,7 @@ describe('A Timer', () => { }); timer = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { /*do nothing*/ } }); @@ -32,7 +32,7 @@ describe('A Timer', () => { it('has a unique id', () => { const newtimer = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { /*do nothing*/ } }); @@ -41,7 +41,7 @@ describe('A Timer', () => { const newtimer2 = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { /*do nothing*/ } }); @@ -52,7 +52,7 @@ describe('A Timer', () => { it('does not start when added to a scene', () => { const sut = new ex.Timer({ interval: 42, - fcn: () => { + action: () => { /* nothing */ } }); @@ -68,7 +68,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); const sut = new ex.Timer({ interval: 42, - fcn: timerSpy + action: timerSpy }); scene.add(sut); @@ -98,7 +98,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); const sut = new ex.Timer({ interval: 42, - fcn: timerSpy + action: timerSpy }); scene.add(sut); @@ -110,7 +110,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); const sut = new ex.Timer({ interval: 42, - fcn: timerSpy + action: timerSpy }); scene.add(sut); @@ -136,7 +136,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); const sut = new ex.Timer({ interval: 500, - fcn: timerSpy + action: timerSpy }); sut.start(); sut.update(501); @@ -149,7 +149,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); timer = new ex.Timer({ interval: 500, - fcn: timerSpy, + action: timerSpy, repeats: true }); @@ -165,7 +165,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); timer = new ex.Timer({ interval: 500, - fcn: timerSpy, + action: timerSpy, repeats: true, numberOfRepeats: 2 }); @@ -191,7 +191,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); timer = new ex.Timer({ interval: 500, - fcn: timerSpy, + action: timerSpy, repeats: true }); scene.addTimer(timer); @@ -228,7 +228,7 @@ describe('A Timer', () => { const timerSpy = vi.fn(); timer = new ex.Timer({ interval: 500, - fcn: timerSpy, + action: timerSpy, repeats: true }); scene.addTimer(timer); @@ -255,7 +255,7 @@ describe('A Timer', () => { // non-repeating timer timer = new ex.Timer({ interval: 500, - fcn: timerSpy, + action: timerSpy, repeats: false }); scene.add(timer); @@ -283,7 +283,7 @@ describe('A Timer', () => { // non-repeating timer timer = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { count++; }, repeats: false @@ -313,7 +313,7 @@ describe('A Timer', () => { // non-repeating timer timer = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { count++; }, repeats: true @@ -338,7 +338,7 @@ describe('A Timer', () => { // non-repeating timer timer = new ex.Timer({ interval: 500, - fcn: function () { + action: function () { const dummy = 0; }, repeats: true, @@ -374,7 +374,7 @@ describe('A Timer', () => { // arrange const timer = new ex.Timer({ interval: 100, - fcn: () => { + action: () => { count++; }, repeats: true @@ -396,7 +396,7 @@ describe('A Timer', () => { // arrange const timer = new ex.Timer({ interval: 100, - fcn: () => { + action: () => { count++; }, repeats: true diff --git a/src/stories/actions.stories.ts b/src/stories/actions.stories.ts index 4e6e17e09d..dad927b7ec 100644 --- a/src/stories/actions.stories.ts +++ b/src/stories/actions.stories.ts @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/html-vite'; -import { Actor, Loader, EasingFunctions, RotationType } from '../engine'; +import { Actor, easeInOutCubic, easeOutCubic, Loader, RotationType, vec } from '../engine'; import { ImageSource } from '../engine/graphics'; import { enumToControlSelectLabels, enumToControlSelectOptions, withEngine } from './utils'; @@ -286,8 +286,8 @@ export const Ease: StoryObj = { const originalPos = heart.pos.clone(); heart.actions.repeatForever((actions) => { actions - .easeTo(originalPos.x + easeX, originalPos.y + easeY, duration, EasingFunctions.EaseOutCubic) - .easeTo(originalPos.x, originalPos.y, duration, EasingFunctions.EaseInOutCubic); + .moveTo({ pos: vec(originalPos.x + easeX, originalPos.y + easeY), duration, easing: easeOutCubic }) + .moveTo({ pos: vec(originalPos.x, originalPos.y), duration, easing: easeInOutCubic }); }); }), parameters: { diff --git a/src/stories/audio.stories.ts b/src/stories/audio.stories.ts index 3f3d79d78e..3de15f9298 100644 --- a/src/stories/audio.stories.ts +++ b/src/stories/audio.stories.ts @@ -4,7 +4,7 @@ import playIcon from '@fortawesome/fontawesome-free/svgs/solid/play.svg'; import pauseIcon from '@fortawesome/fontawesome-free/svgs/solid/pause.svg'; import stopIcon from '@fortawesome/fontawesome-free/svgs/solid/stop.svg'; import type { NativeSoundEvent, NativeSoundProcessedEvent } from '../engine'; -import { Actor, Sound, Loader, Color, EasingFunctions } from '../engine'; +import { Actor, Sound, Loader, Color, linear, vec } from '../engine'; import { ImageSource, Sprite } from '../engine/graphics'; import { withEngine } from './utils'; @@ -71,7 +71,7 @@ export const PlayingASound: StoryObj = { if (guitarLoopSound.duration > 0) { startTime = Date.now(); elapsedTime = 0; - playHead.actions.easeTo(playheadEndPos, playHead.pos.y, guitarLoopSound.duration * 1000, EasingFunctions.Linear); + playHead.actions.moveTo({ pos: vec(playheadEndPos, playHead.pos.y), duration: guitarLoopSound.duration * 1000, easing: linear }); } startOrPauseBtn.graphics.use('pause'); action('playbackstart')(e); @@ -87,7 +87,11 @@ export const PlayingASound: StoryObj = { guitarLoopSound.on('resume', (e: NativeSoundEvent) => { startTime = Date.now(); if (guitarLoopSound.duration > 0) { - playHead.actions.easeTo(playheadEndPos, playHead.pos.y, guitarLoopSound.duration * 1000 - elapsedTime, EasingFunctions.Linear); + playHead.actions.moveTo({ + pos: vec(playheadEndPos, playHead.pos.y), + duration: guitarLoopSound.duration * 1000 - elapsedTime, + easing: linear + }); } startOrPauseBtn.graphics.use('pause'); action('resume')(e);