Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
fix: initial parcelObservable notification not being called (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
pravusjif authored Oct 19, 2022
1 parent 5e7504c commit 29238aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/shared/world/SceneWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export class SceneWorker {
private subscribeToSceneChangeEvents() {
this.sceneChangeObserver = sceneObservable.add((report) => {
const userId = getCurrentUserId(store.getState())

if (userId) {
const sceneId = this.loadableScene.id
if (report.newScene?.id === sceneId) {
Expand Down
7 changes: 5 additions & 2 deletions packages/shared/world/positionThings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ positionObservable.add((event) => {
lastPlayerPositionReport = event
})

// Listen to position changes, and notify if the parcel changed
let calledInitialParcelNotification = false
let lastPlayerParcel: Vector2
// Listen to position changes, and notify if the parcel changed
positionObservable.add(({ position, immediate }) => {
const parcel = Vector2.Zero()
worldToGrid(position, parcel)
if (!lastPlayerParcel || parcel.x !== lastPlayerParcel.x || parcel.y !== lastPlayerParcel.y) {

if (!calledInitialParcelNotification || parcel.x !== lastPlayerParcel.x || parcel.y !== lastPlayerParcel.y) {
calledInitialParcelNotification = true
parcelObservable.notifyObservers({ previousParcel: lastPlayerParcel, newParcel: parcel, immediate })
setLastPlayerParcel(parcel)
}
Expand Down

0 comments on commit 29238aa

Please sign in to comment.