From 5e81eeec452925339d658e1249de570416dfa4a5 Mon Sep 17 00:00:00 2001 From: jedeen Date: Sun, 23 Dec 2018 08:01:59 -0600 Subject: [PATCH] [chore] Remove deprecated PauseAfterLoader (#1073) --- sandbox/tests/loader/pauseafter/index.html | 37 ----- sandbox/tests/loader/pauseafter/ios.html | 37 ----- sandbox/tests/loader/pauseafter/ios.ts | 33 ----- sandbox/tests/loader/pauseafter/pauseafter.ts | 21 --- src/engine/Loader.ts | 129 ------------------ 5 files changed, 257 deletions(-) delete mode 100644 sandbox/tests/loader/pauseafter/index.html delete mode 100644 sandbox/tests/loader/pauseafter/ios.html delete mode 100644 sandbox/tests/loader/pauseafter/ios.ts delete mode 100644 sandbox/tests/loader/pauseafter/pauseafter.ts diff --git a/sandbox/tests/loader/pauseafter/index.html b/sandbox/tests/loader/pauseafter/index.html deleted file mode 100644 index bb8fb9923..000000000 --- a/sandbox/tests/loader/pauseafter/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - PauseAfterLoader Test - - - -
- - Tap to Play -
- - -

You should see a loader, then a button to press to play, then a sound

- - \ No newline at end of file diff --git a/sandbox/tests/loader/pauseafter/ios.html b/sandbox/tests/loader/pauseafter/ios.html deleted file mode 100644 index c039c5ee8..000000000 --- a/sandbox/tests/loader/pauseafter/ios.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - PauseAfterLoader Test - iOS - - - -
- - Tap to Play -
- - -

On iOS, you should see the paused loader. On all other platforms, you shouldn't. On iOS you should also hear a sound every 2 seconds after starting the game.

- - \ No newline at end of file diff --git a/sandbox/tests/loader/pauseafter/ios.ts b/sandbox/tests/loader/pauseafter/ios.ts deleted file mode 100644 index 288319fdf..000000000 --- a/sandbox/tests/loader/pauseafter/ios.ts +++ /dev/null @@ -1,33 +0,0 @@ -/// - -var game = new ex.Engine({ - canvasElementId: 'game', - displayMode: ex.DisplayMode.FullScreen -}); - -var jump = new ex.Sound('../../../sounds/jump.mp3', '../../../sounds/jump.wav'); - -// if iOS, use PauseAfterLoader -var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window).MSStream; -var loader: ex.Loader = iOS ? new ex.PauseAfterLoader('tap-to-play') : new ex.Loader(); - -loader.addResource(jump); - -var lbl = new ex.Label('Game started, you should hear a sound every 2 seconds', 20, 100, 'sans-serif'); -lbl.fontSize = 10; -lbl.color = ex.Color.White; -var tmr = new ex.Timer( - () => { - jump.play(); - }, - 2000, - true -); - -game.add(lbl); -game.add(tmr); - -game.start(loader).then(() => { - // should play immediately - jump.play(); -}); diff --git a/sandbox/tests/loader/pauseafter/pauseafter.ts b/sandbox/tests/loader/pauseafter/pauseafter.ts deleted file mode 100644 index c1382987d..000000000 --- a/sandbox/tests/loader/pauseafter/pauseafter.ts +++ /dev/null @@ -1,21 +0,0 @@ -/// - -var game = new ex.Engine({ - canvasElementId: 'game', - width: 500, - height: 500 -}); - -var jump = new ex.Sound('../../../sounds/jump.mp3', '../../../sounds/jump.wav'); -var loader: ex.Loader = new ex.PauseAfterLoader('tap-to-play', [jump]); - -var lbl = new ex.Label('Game started, you should hear a sound', 20, 100, 'sans-serif'); -lbl.fontSize = 10; -lbl.color = ex.Color.White; - -game.add(lbl); - -game.start(loader).then(() => { - // should play immediately - jump.play(); -}); diff --git a/src/engine/Loader.ts b/src/engine/Loader.ts index ec1b4911c..55ef17ad7 100644 --- a/src/engine/Loader.ts +++ b/src/engine/Loader.ts @@ -7,7 +7,6 @@ import { ILoadable } from './Interfaces/ILoadable'; import { ILoader } from './Interfaces/ILoader'; import { Class } from './Class'; import * as DrawUtil from './Util/DrawUtil'; -import { obsolete } from './Util/Decorators'; import logoImg from './Loader.logo.png'; import loaderCss from './Loader.css'; @@ -371,131 +370,3 @@ export class Loader extends Class implements ILoader { return; }; } - -/** - * @obsolete Use [[Loader]] instead, this functionality has been made default - * - * A [[Loader]] that pauses after loading to allow user - * to proceed to play the game. Typically you will - * want to use this loader for iOS to allow sounds - * to play after loading (Apple Safari requires user - * interaction to allow sounds, even for games) - * - * **Note:** Because Loader is not part of a Scene, you must - * call `update` and `draw` manually on "child" objects. - * - * ## Implementing a Trigger - * - * The `PauseAfterLoader` requires an element to act as the trigger button - * to start the game. - * - * For example, let's create an `` tag to be our trigger and call it `tap-to-play`. - * - * ```html - * - * ``` - * - * We've put it inside a wrapper to position it properly over the game canvas. - * - * Now let's add some CSS to style it (insert into ``): - * - * ```html - * - * ``` - * - * Now we can create a `PauseAfterLoader` with a reference to our trigger button: - * - * ```ts - * var loader = new ex.PauseAfterLoader('tap-to-play', [...]); - * ``` - * - * ## Use PauseAfterLoader for iOS - * - * The primary use case for pausing before starting the game is to - * pass Apple's requirement of user interaction. The Web Audio context - * in Safari is disabled by default until user interaction. - * - * Therefore, you can use this snippet to only use PauseAfterLoader when - * iOS is detected (see [this thread](http://stackoverflow.com/questions/9038625/detect-if-device-is-ios) - * for more techniques). - * - * ```ts - * var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window).MSStream; - * var loader: ex.Loader = iOS ? new ex.PauseAfterLoader('tap-to-play') : new ex.Loader(); - * - * loader.addResource(...); - * ``` - */ -export class PauseAfterLoader extends Loader { - private _loadedValue: any; - private _waitPromise: Promise; - private _playTrigger: HTMLElement; - - constructor(triggerElementId: string, loadables?: ILoadable[]) { - super(loadables); - - this._playTrigger = document.getElementById(triggerElementId); - this._playTrigger.addEventListener('click', this._handleOnTrigger); - } - - @obsolete({ message: 'Deprecated in v0.20.0', alternateMethod: 'Use ex.Loader instead' }) - public load(): Promise { - this._waitPromise = new Promise(); - - // wait until user indicates to proceed before finishing load - super.load().then( - (value?) => { - this._loadedValue = value; - - // show element - this._playTrigger.style.display = 'block'; - }, - (value?) => { - this._waitPromise.reject(value); - } - ); - - return this._waitPromise; - } - - private _handleOnTrigger = () => { - if (this._waitPromise.state() !== PromiseState.Pending) { - return false; - } - - // unlock Safari WebAudio context - WebAudio.unlock(); - - // continue to play game - this._waitPromise.resolve(this._loadedValue); - - // hide DOM element - this._playTrigger.style.display = 'none'; - - return false; - }; -}