Skip to content

Commit e35269e

Browse files
authored
fix: goto & position param in worlds (#6115)
1 parent d4c3f53 commit e35269e

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

browser-interface/packages/shared/scene-loader/sagas.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,13 @@ function* teleportHandler(action: TeleportToAction) {
135135
try {
136136
// look for the target scene
137137
const pointer = encodeParcelPosition(worldToGrid(action.payload.position))
138-
const command: SetDesiredScenesCommand = yield apply(sceneLoader, sceneLoader.fetchScenesByLocation, [[pointer]])
139-
138+
const command: SetDesiredScenesCommand = yield call(sceneLoader.fetchScenesByLocation, [pointer])
140139
// is a target scene, then it will be used to settle the position
141140
if (command && command.scenes && command.scenes.length) {
142141
// pick always the first scene to unsettle the position once loaded
143142
const settlerScene = command.scenes[0].id
144143

145144
const scene: SceneWorker | undefined = yield call(getSceneWorkerBySceneID, settlerScene)
146-
147145
const spawnPoint =
148146
pickWorldSpawnpoint(
149147
scene?.metadata || command.scenes[0].entity.metadata,

browser-interface/packages/shared/scene-loader/world-loader-impl/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,32 @@ export async function createWorldLoader(options: { urns: string[] }): Promise<IS
3131
const emptyParcelController = new EmptyParcelController({ rootUrl: getResourcesURL('.') })
3232

3333
return {
34-
async fetchScenesByLocation(_parcels) {
35-
return { scenes }
34+
async fetchScenesByLocation(parcels) {
35+
// If the world has only one scene, return always that scene.
36+
if (scenes.length === 1) {
37+
return { scenes }
38+
}
39+
40+
// Worlds with more than one scene deployed.
41+
const newScenes = new Set<LoadableScene>()
42+
// First add the scenes based on the location (parcels)
43+
// If there is no scene, add an empty scene.
44+
for (const parcel of parcels) {
45+
const scene = mappingScene.get(parcel)
46+
if (scene) {
47+
newScenes.add(scene)
48+
} else {
49+
const scene = await emptyParcelController.createFakeEntity(parcel)
50+
51+
mappingScene.set(parcel, scene)
52+
newScenes.add(scene)
53+
}
54+
}
55+
// Add the rest of the scenes.
56+
for (const [_, scene] of mappingScene) {
57+
newScenes.add(scene)
58+
}
59+
return { scenes: [...newScenes] }
3660
},
3761
async reportPosition(positionReport) {
3862
const newScenes: Set<LoadableScene> = new Set()

browser-interface/packages/shared/world/TeleportController.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import defaultLogger from 'lib/logger'
66
import { gridToWorld } from 'lib/decentraland/parcels/gridToWorld'
77

88
import { store } from 'shared/store/isolatedStore'
9-
import { getRealmAdapter } from 'shared/realm/selectors'
9+
import { getRealmAdapter, isWorldLoaderActive } from 'shared/realm/selectors'
1010
import { Parcel } from 'shared/dao/types'
1111
import { urlWithProtocol } from 'shared/realm/resolver'
1212
import { trackTeleportTriggered } from 'shared/loading/types'
@@ -17,6 +17,7 @@ import { lastPlayerPosition } from 'shared/world/positionThings'
1717
import { homePointKey } from 'shared/atlas/utils'
1818
import { getFromPersistentStorage } from 'lib/browser/persistentStorage'
1919
import { changeToMostPopulatedRealm } from '../dao'
20+
import { ensureRealmAdapter } from '../realm/ensureRealmAdapter'
2021

2122
const descriptiveValidWorldRanges = getWorld()
2223
.validWorldRanges.map((range) => `(X from ${range.xMin} to ${range.xMax}, and Y from ${range.yMin} to ${range.yMax})`)
@@ -94,9 +95,12 @@ export class TeleportController {
9495
teleportMessage?: string
9596
): Promise<{ message: string; success: boolean }> {
9697
const tpMessage: string = teleportMessage ? teleportMessage : `Teleporting to ${x}, ${y}...`
98+
const realmAdapter = await ensureRealmAdapter()
99+
const isWorld = isWorldLoaderActive(realmAdapter)
100+
97101
if (isInsideWorldLimits(x, y)) {
98102
try {
99-
if (goToMostPopulatedRealm) await changeToMostPopulatedRealm()
103+
if (goToMostPopulatedRealm && !isWorld) await changeToMostPopulatedRealm()
100104

101105
store.dispatch(trackTeleportTriggered(tpMessage))
102106
store.dispatch(teleportToAction({ position: gridToWorld(x, y) }))

0 commit comments

Comments
 (0)