diff --git a/CHANGELOG.md b/CHANGELOG.md index 7182b13ac..184f428d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Remove confusing Graphics Layering from `ex.GraphicsComponent`, recommend we use the `ex.GraphicsGroup` to manage this behavior * Update `ex.GraphicsGroup` to be consistent and use `offset` instead of `pos` for graphics relative positioning +- Prevent people from inadvertently overriding `update()` in `ex.Scene` and `ex.Actor`. This method can still be overridden with the `//@ts-ignore` pragma ### Deprecated diff --git a/sandbox/src/game.ts b/sandbox/src/game.ts index 26be9c515..0cb7d8fc2 100644 --- a/sandbox/src/game.ts +++ b/sandbox/src/game.ts @@ -954,4 +954,12 @@ game.currentScene.camera.y = 200; // Run the mainloop game.start(boot).then(() => { logger.info('All Resources have finished loading'); -}); \ No newline at end of file +}); + + +class MySceneCustomUpdate extends ex.Scene { + //@ts-ignore + update() { + console.log('my update') + } +} \ No newline at end of file diff --git a/sandbox/tests/collisionvelocity/vel.ts b/sandbox/tests/collisionvelocity/vel.ts index f4ab30a24..1cacc4bff 100644 --- a/sandbox/tests/collisionvelocity/vel.ts +++ b/sandbox/tests/collisionvelocity/vel.ts @@ -29,6 +29,7 @@ var player = new ex.Actor({ collisionType: ex.CollisionType.Active }); +//@ts-ignore player.update = (e, ms) => { if (engine.input.keyboard.isHeld(ex.Keys.Space)) { player.vel.x = 0; diff --git a/sandbox/tests/coordinates/coordinates.ts b/sandbox/tests/coordinates/coordinates.ts index ef47c18ce..855930ffa 100644 --- a/sandbox/tests/coordinates/coordinates.ts +++ b/sandbox/tests/coordinates/coordinates.ts @@ -53,6 +53,7 @@ class PointLabel extends ex.Actor { this.addChild(this._actualLabel); } + //@ts-ignore update(engine: ex.Engine, delta: number) { super.update(engine, delta); diff --git a/src/engine/Actor.ts b/src/engine/Actor.ts index 0abc09a79..0ca4a7951 100644 --- a/src/engine/Actor.ts +++ b/src/engine/Actor.ts @@ -47,6 +47,10 @@ import { Text } from './Graphics/Text'; import { CoordPlane } from './Math/coord-plane'; import { EventEmitter, EventKey, Handler, Subscription } from './EventEmitter'; +declare const _: unique symbol; +type Forbidden = { [_]: typeof _; } +type NoOverride = T & Forbidden; + /** * Type guard for checking if something is an Actor * @param x @@ -852,12 +856,16 @@ export class Actor extends Entity implements Eventable, PointerEvents, CanInitia // #region Update /** + * It is not recommended that internal excalibur methods be overridden, do so at your own risk. + * + * Use **[[onPreUpdate]]** or **[[onPostUpdate]]**, or be sure to call the **`super.update()`** + * * Called by the Engine, updates the state of the actor * @internal * @param engine The reference to the current game engine * @param delta The time elapsed since the last update in milliseconds */ - public update(engine: Engine, delta: number) { + public update(engine: Engine, delta: number): NoOverride { this._initialize(engine); this._preupdate(engine, delta); this._postupdate(engine, delta); diff --git a/src/engine/Particles.ts b/src/engine/Particles.ts index 6fb3825b9..611f188c4 100644 --- a/src/engine/Particles.ts +++ b/src/engine/Particles.ts @@ -151,6 +151,7 @@ export class ParticleImpl extends Entity { this.emitter.removeParticle(this); } + //@ts-ignore public update(engine: Engine, delta: number) { this.life = this.life - delta; this.elapsedMultiplier = this.elapsedMultiplier + delta; @@ -596,6 +597,7 @@ export class ParticleEmitter extends Actor { return p; } + //@ts-ignore public update(engine: Engine, delta: number) { super.update(engine, delta); diff --git a/src/engine/Scene.ts b/src/engine/Scene.ts index bde393746..a7105619f 100644 --- a/src/engine/Scene.ts +++ b/src/engine/Scene.ts @@ -37,6 +37,10 @@ import { Color } from './Color'; import { DefaultLoader } from './Director/DefaultLoader'; import { Transition } from './Director'; +declare const _: unique symbol; +type Forbidden = { [_]: typeof _; } +type NoOverride = T & Forbidden; + export class PreLoadEvent { loader: DefaultLoader; } @@ -395,11 +399,16 @@ implements CanInitialize, CanActivate, CanDeactivate, CanUpdate } /** + * It is not recommended that internal excalibur methods be overridden, do so at your own risk. + * + * Use **[[onPreUpdate]]** or **[[onPostUpdate]]**, or be sure to call the **`super.update()`** + * * Updates all the actors and timers in the scene. Called by the [[Engine]]. + * @internal * @param engine Reference to the current Engine * @param delta The number of milliseconds since the last update */ - public update(engine: Engine, delta: number) { + public update(engine: Engine, delta: number): NoOverride { if (!this.isInitialized) { throw new Error('Scene update called before it was initialized!'); } @@ -431,11 +440,16 @@ implements CanInitialize, CanActivate, CanDeactivate, CanUpdate } /** + * It is not recommended that internal excalibur methods be overridden, do so at your own risk. + * + * Use **[[onPreDraw]]** or **[[onPostDraw]]**, or be sure to call the **`super.update()`** + * * Draws all the actors in the Scene. Called by the [[Engine]]. + * @internal * @param ctx The current rendering context * @param delta The number of milliseconds since the last draw */ - public draw(ctx: ExcaliburGraphicsContext, delta: number) { + public draw(ctx: ExcaliburGraphicsContext, delta: number): NoOverride { this._predraw(ctx, delta); this.world.update(SystemType.Draw, delta);