Skip to content

Commit

Permalink
Provide easier access to the active SceneController instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigabyte5671 committed Sep 4, 2023
1 parent 473deda commit 1833ff9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/modules/avatar/controller/inputController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { IInputHandler } from "./inputs/inputHandler";
import { KeyboardInput } from "./inputs/keyboardInput";
import { VirtualJoystickInput } from "./inputs/virtualJoystickInput";
import { applicationStore, userStore } from "@Stores/index";
import type { SceneController } from "@Modules/scene/controllers";
import { Renderer } from "@Base/modules/scene";
import { MouseSettingsController } from "@Base/modules/avatar/controller/inputs/mouseSettings";

// Custom camera controls.
Expand Down Expand Up @@ -496,9 +496,7 @@ export class InputController extends ScriptComponent {
return;
}
this._avatarState.state = State.Idle;
const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject;
const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined;
sceneController?.applyGravity();
Renderer.getScene().sceneController?.applyGravity();
}
}

Expand Down Expand Up @@ -550,15 +548,13 @@ export class InputController extends ScriptComponent {
return;
}

// Reset the avatar's rotation (so that it is standing up).
// Reset the avatar's rotation (so that it is standing upright).
if (this._gameObject && this._gameObject.rotationQuaternion) {
this._gameObject.rotationQuaternion.x = 0;
this._gameObject.rotationQuaternion.z = 0;
}

const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject;
const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined;
sceneController?.applyGravity();
Renderer.getScene().sceneController?.applyGravity();

this._avatarState.duration += delta;

Expand Down
9 changes: 2 additions & 7 deletions src/modules/avatar/controller/inputs/keyboardInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import { InputState, CameraMode, InputMode } from "../inputState";
import { applicationStore, userStore } from "@Stores/index";
import { AudioManager as AudioMgr } from "@Modules/scene/audio";
import { Renderer } from "@Modules/scene";
import type { GameObject } from "@Modules/object";
import type { SceneController } from "@Modules/scene/controllers";


export class KeyboardInput implements IInputHandler {
Expand Down Expand Up @@ -162,8 +160,7 @@ export class KeyboardInput implements IInputHandler {

// Fly.
if (sourceEvent.code === userStore.controls.keyboard.movement.fly?.keycode) {
const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject;
const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined;
const sceneController = Renderer.getScene().sceneController;

if (this._state.state === State.Fly) {
this._state.action = Action.Jump;
Expand Down Expand Up @@ -233,9 +230,7 @@ export class KeyboardInput implements IInputHandler {
this._state.action = animation;

// Remove gravity.
const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject;
const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined;
sceneController?.removeGravity();
Renderer.getScene().sceneController?.removeGravity();

// Snap to the sittable object.
avatarMesh.setAbsolutePosition(selectedSitObject[0].getAbsolutePosition());
Expand Down
4 changes: 4 additions & 0 deletions src/modules/scene/vscene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export class VScene {
return this._css3DRenderer;
}

public get sceneController(): Nullable<SceneController> {
return this._sceneController;
}

public render(): void {
this._scene.render();

Expand Down

0 comments on commit 1833ff9

Please sign in to comment.