* Trigger this event. Override in subclasses to customize behavior. * @protected
()
| 151 | * @protected |
| 152 | */ |
| 153 | triggerEvent() { |
| 154 | const triggerSettings = this.getTriggerSettings(); |
| 155 | const world = this.ancestor.getRootAncestor(); |
| 156 | const app = world.app; |
| 157 | const viewport = app.viewport; |
| 158 | |
| 159 | if (triggerSettings.event === "level") { |
| 160 | this.gotolevel = triggerSettings.to; |
| 161 | if (this.color && this.duration) { |
| 162 | if (!this.fading) { |
| 163 | this.fading = true; |
| 164 | const gotolevel = this.gotolevel; |
| 165 | const settings = this.getTriggerSettings(); |
| 166 | const color = this.color; |
| 167 | const duration = this.duration; |
| 168 | const useMask = this.transition === "mask" && this.transitionShape; |
| 169 | const shape = this.transitionShape; |
| 170 | |
| 171 | // wrap the user's onLoaded to add the reveal effect |
| 172 | const userOnLoaded = settings.onLoaded; |
| 173 | settings.onLoaded = function (levelId) { |
| 174 | // re-read viewport after game.reset reassigns it |
| 175 | const vp = app.viewport; |
| 176 | // reveal effect (same type as hide) |
| 177 | if (useMask) { |
| 178 | vp.addCameraEffect( |
| 179 | new MaskEffect(vp, { |
| 180 | shape, |
| 181 | color, |
| 182 | duration, |
| 183 | direction: "reveal", |
| 184 | }), |
| 185 | ); |
| 186 | } else { |
| 187 | vp.addCameraEffect( |
| 188 | new FadeEffect(vp, { |
| 189 | color, |
| 190 | duration, |
| 191 | direction: "out", |
| 192 | }), |
| 193 | ); |
| 194 | } |
| 195 | // call the user's onLoaded if any |
| 196 | if (typeof userOnLoaded === "function") { |
| 197 | userOnLoaded.call(this, levelId); |
| 198 | } |
| 199 | }; |
| 200 | const onComplete = () => { |
| 201 | level.load(gotolevel, settings); |
| 202 | }; |
| 203 | |
| 204 | // hide effect, then load level + reveal |
| 205 | if (useMask) { |
| 206 | viewport.addCameraEffect( |
| 207 | new MaskEffect(viewport, { |
| 208 | shape, |
| 209 | color, |
| 210 | duration, |
no test coverage detected