This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving start/stop playmode into its own functions file, try exiting p…
…lay mode on scene loading
- Loading branch information
1 parent
1bf2882
commit db8de10
Showing
3 changed files
with
64 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/spatial/src/common/functions/PlayModeFunctions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { AuthState } from '@etherealengine/client-core/src/user/services/AuthService' | ||
import { Engine, UUIDComponent, getComponent, removeComponent, removeEntity } from '@etherealengine/ecs' | ||
import { TransformGizmoControlledComponent } from '@etherealengine/editor/src/classes/TransformGizmoControlledComponent' | ||
import { EditorState } from '@etherealengine/editor/src/services/EditorServices' | ||
import { transformGizmoControlledQuery } from '@etherealengine/editor/src/systems/GizmoSystem' | ||
import { VisualScriptActions, visualScriptQuery } from '@etherealengine/engine' | ||
import { AvatarComponent } from '@etherealengine/engine/src/avatar/components/AvatarComponent' | ||
import { getRandomSpawnPoint } from '@etherealengine/engine/src/avatar/functions/getSpawnPoint' | ||
import { spawnLocalAvatarInWorld } from '@etherealengine/engine/src/avatar/functions/receiveJoinWorld' | ||
import { dispatchAction, getMutableState, getState } from '@etherealengine/hyperflux' | ||
import { WorldNetworkAction } from '@etherealengine/network' | ||
import { EngineState } from '../../EngineState' | ||
import { FollowCameraComponent } from '../../camera/components/FollowCameraComponent' | ||
import { TargetCameraRotationComponent } from '../../camera/components/TargetCameraRotationComponent' | ||
import { ComputedTransformComponent } from '../../transform/components/ComputedTransformComponent' | ||
|
||
/** | ||
* Returns true if we stopped play mode, false if we were not in play mode | ||
*/ | ||
export const tryStopPlayMode = (): boolean => { | ||
const entity = AvatarComponent.getSelfAvatarEntity() | ||
if (entity) { | ||
dispatchAction(WorldNetworkAction.destroyEntity({ entityUUID: getComponent(entity, UUIDComponent) })) | ||
removeEntity(entity) | ||
const viewerEntity = getState(EngineState).viewerEntity | ||
removeComponent(viewerEntity, ComputedTransformComponent) | ||
removeComponent(viewerEntity, FollowCameraComponent) | ||
removeComponent(viewerEntity, TargetCameraRotationComponent) | ||
getMutableState(EngineState).isEditing.set(true) | ||
visualScriptQuery().forEach((entity) => dispatchAction(VisualScriptActions.stop({ entity }))) | ||
// stop all visual script logic | ||
} | ||
return !!entity | ||
} | ||
|
||
export const startPlayMode = () => { | ||
const authState = getState(AuthState) | ||
// const authState = useHookstate(getMutableState(AuthState)) | ||
const avatarDetails = authState.user.avatar //.value | ||
|
||
const avatarSpawnPose = getRandomSpawnPoint(Engine.instance.userID) | ||
const currentScene = getComponent(getState(EditorState).rootEntity, UUIDComponent) | ||
|
||
if (avatarDetails) | ||
spawnLocalAvatarInWorld({ | ||
parentUUID: currentScene, | ||
avatarSpawnPose, | ||
avatarID: avatarDetails.id!, | ||
name: authState.user.name //.value | ||
}) | ||
|
||
// todo | ||
getMutableState(EngineState).isEditing.set(false) | ||
// run all visual script logic | ||
visualScriptQuery().forEach((entity) => dispatchAction(VisualScriptActions.execute({ entity }))) | ||
transformGizmoControlledQuery().forEach((entity) => removeComponent(entity, TransformGizmoControlledComponent)) | ||
//just remove all gizmo in the scene | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters