Skip to content

Commit 4d9b8b3

Browse files
committed
Add prettier and format multiscene example
1 parent 48e4da1 commit 4d9b8b3

6 files changed

Lines changed: 93 additions & 55 deletions

File tree

multiscene/index-scene2.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import {SwitchScene} from './js/switch.js';
1313

1414
export default function registerSceneComponents(engine) {
1515
/* wle:auto-register:start */
16-
engine.registerComponent(Cursor);
17-
engine.registerComponent(HandTracking);
18-
engine.registerComponent(HowlerAudioListener);
19-
engine.registerComponent(MouseLookComponent);
20-
engine.registerComponent(PlayerHeight);
21-
engine.registerComponent(TeleportComponent);
22-
engine.registerComponent(VrModeActiveSwitch);
23-
engine.registerComponent(WasdControlsComponent);
24-
engine.registerComponent(Portal);
25-
engine.registerComponent(SwitchScene);
26-
/* wle:auto-register:end */
16+
engine.registerComponent(Cursor);
17+
engine.registerComponent(HandTracking);
18+
engine.registerComponent(HowlerAudioListener);
19+
engine.registerComponent(MouseLookComponent);
20+
engine.registerComponent(PlayerHeight);
21+
engine.registerComponent(TeleportComponent);
22+
engine.registerComponent(VrModeActiveSwitch);
23+
engine.registerComponent(WasdControlsComponent);
24+
engine.registerComponent(Portal);
25+
engine.registerComponent(SwitchScene);
26+
/* wle:auto-register:end */
2727
}

multiscene/js/portal.js

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
import {Component, Property} from "@wonderlandengine/api";
2-
import { SwitchScene } from './switch';
3-
import { vec3 } from 'gl-matrix';
1+
import {Component, Property} from '@wonderlandengine/api';
2+
import {SwitchScene} from './switch';
3+
import {vec3} from 'gl-matrix';
44

55
/**
66
* switch-scene
77
*/
88
export class Portal extends Component {
9-
static TypeName = "portal";
10-
/* Properties that are configurable in the editor */
11-
static Properties = {
12-
target: Property.object(),
13-
translationDuration: Property.float(0.5),
14-
initialTranslate: Property.float(15),
15-
portalRotateSpeed: Property.float(1.0),
16-
};
9+
static TypeName = 'portal';
10+
/* Properties that are configurable in the editor */
11+
static Properties = {
12+
target: Property.object(),
13+
translationDuration: Property.float(0.5),
14+
initialTranslate: Property.float(15),
15+
portalRotateSpeed: Property.float(1.0),
16+
};
1717

18-
onActivate() {
19-
this.target.translateObject([0, 0, this.initialTranslate]);
20-
}
18+
onActivate() {
19+
this.target.translateObject([0, 0, this.initialTranslate]);
20+
}
2121

22-
update(dt) {
23-
this.object.rotateAxisAngleDegObject(
24-
[0, 0, 1],
25-
dt * 10000 * this.portalRotateSpeed,
26-
);
27-
const playerPosition = this.target.getPositionWorld([]);
28-
const portalPosition = this.object.getPositionWorld([]);
29-
const sqDist= vec3.squaredDistance(playerPosition, portalPosition)
30-
if (sqDist > 0.1) {
31-
const distanceRemaining = Math.abs(
32-
portalPosition[0] - playerPosition[0],
33-
);
34-
const alpha =
35-
1 -
36-
Math.exp(-dt / (this.translationDuration * distanceRemaining));
37-
const newPosition= new Float32Array(3)
38-
vec3.lerp(newPosition,playerPosition,portalPosition,alpha,)
39-
this.target.setPositionWorld(newPosition);
40-
}
41-
else{
42-
this.object.getComponent(SwitchScene).switch();
43-
}
44-
}
22+
update(dt) {
23+
this.object.rotateAxisAngleDegObject(
24+
[0, 0, 1],
25+
dt * 10000 * this.portalRotateSpeed
26+
);
27+
const playerPosition = this.target.getPositionWorld([]);
28+
const portalPosition = this.object.getPositionWorld([]);
29+
const sqDist = vec3.squaredDistance(playerPosition, portalPosition);
30+
if (sqDist > 0.1) {
31+
const distanceRemaining = Math.abs(portalPosition[0] - playerPosition[0]);
32+
const alpha =
33+
1 - Math.exp(-dt / (this.translationDuration * distanceRemaining));
34+
const newPosition = new Float32Array(3);
35+
vec3.lerp(newPosition, playerPosition, portalPosition, alpha);
36+
this.target.setPositionWorld(newPosition);
37+
} else {
38+
this.object.getComponent(SwitchScene).switch();
39+
}
40+
}
4541
}

multiscene/js/scenes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export const Scenes = {
33
/** Main scene, loaded first. */
44
main: null,
55
/** Magical scene, reached via the portal */
6-
second: null
6+
second: null,
77
};

multiscene/js/switch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {Scenes} from './scenes.js';
33

44
/** Component to switch between the main and second scene. */
55
export class SwitchScene extends Component {
6-
static TypeName = 'switch-scene';
6+
static TypeName = 'switch-scene';
77

8-
switch() {
9-
const nextScene = this.scene === Scenes.main ? Scenes.second : Scenes.main;
10-
this.engine.switchTo(nextScene);
11-
}
8+
switch() {
9+
const nextScene = this.scene === Scenes.main ? Scenes.second : Scenes.main;
10+
this.engine.switchTo(nextScene);
11+
}
1212
}

multiscene/package-lock.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

multiscene/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"type": "module",
77
"module": "js/index.js",
88
"scripts": {
9-
"build": "echo \"The 'build' script is run by the editor and should produce your application bundle\""
9+
"build": "echo \"The 'build' script is run by the editor and should produce your application bundle\"",
10+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\""
1011
},
1112
"keywords": [
1213
"wonderland-engine"
@@ -16,5 +17,9 @@
1617
"@wonderlandengine/components": "^1.1.4",
1718
"@wonderlandengine/spatial-audio": "^1.1.2",
1819
"gl-matrix": "^3.4.3"
20+
},
21+
"devDependencies": {
22+
"@wonderlandengine/prettier-config": "^1.0.0",
23+
"prettier": "^3.2.5"
1924
}
2025
}

0 commit comments

Comments
 (0)