* Every event listener should be binded in this function.
(selector: string)
| 2121 | * Every event listener should be binded in this function. |
| 2122 | */ |
| 2123 | static bind (selector: string): Promise<void> { |
| 2124 | |
| 2125 | |
| 2126 | // Add the orientation checker in case that a specific orientation was |
| 2127 | // defined. |
| 2128 | const isMobile = typeof Platform.mobile === 'function' ? Platform.mobile() : Platform.mobile; |
| 2129 | if (this.setting ('Orientation') !== 'any' && isMobile) { |
| 2130 | |
| 2131 | // Set the event listener for device orientation so we can display a message |
| 2132 | window.addEventListener ('orientationchange', () => { |
| 2133 | |
| 2134 | // Display or remove the device orientation notice depending on the |
| 2135 | // current device orientation |
| 2136 | if (Platform.orientation !== this.setting ('Orientation')) { |
| 2137 | this.alert ('orientation-warning', { |
| 2138 | message: 'OrientationWarning' |
| 2139 | }); |
| 2140 | } else { |
| 2141 | this.dismissAlert ('orientation-warning'); |
| 2142 | } |
| 2143 | }, false); |
| 2144 | } |
| 2145 | |
| 2146 | // Add event listener for back buttons. If the player is playing, the back |
| 2147 | // button will return to the game, if its not playing, then it'll return |
| 2148 | // to the main menu. |
| 2149 | this.on ('click', '[data-screen]:not([data-screen="game"]) [data-action="back"]', (event) => { |
| 2150 | this.goBack (event, selector); |
| 2151 | }); |
| 2152 | |
| 2153 | const self = this; |
| 2154 | |
| 2155 | // Add listeners for the data-action properties |
| 2156 | this.on ('click', '[data-action]', function (this: HTMLElement, event) { |
| 2157 | const element = $_(this); |
| 2158 | |
| 2159 | const action = element.data ('action'); |
| 2160 | |
| 2161 | if (action) { |
| 2162 | // Prevent action clicks from bubbling to the game-screen's proceed handler |
| 2163 | event.stopPropagation (); |
| 2164 | self.runListener (action, event, element); |
| 2165 | } |
| 2166 | |
| 2167 | return action === 'set-volume'; |
| 2168 | }); |
| 2169 | |
| 2170 | this.keyboardShortcut (['right', 'space'], () => { |
| 2171 | this.proceed ({ userInitiated: true, skip: false, autoPlay: false }).then (() => { |
| 2172 | // Nothing to do here |
| 2173 | }).catch ((e) => { |
| 2174 | this.debug.log (`Proceed Prevented\nReason: ${e}`); |
| 2175 | // An action waiting for user interaction or something else |
| 2176 | // is blocking the game. |
| 2177 | }); |
| 2178 | }); |
| 2179 | |
| 2180 | this.keyboardShortcut ('esc', () => { |
no test coverage detected