Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/editor/scene-settings/scene-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ editor.once('load', () => {
let entitiesLoaded = false;
let projectUserSettingsLoaded = false;
let migrateEntityHandle = null;
let reloading = false;
const migrateCameraSettings = () => {
if (!entitiesLoaded || !projectUserSettingsLoaded) {
return;
Expand Down Expand Up @@ -97,10 +98,16 @@ editor.once('load', () => {
migrateEntityHandle = editor.on('entities:add', migrateEntity);

editor.call('status:clear');
if (editor.call('permissions:write')) {
if (editor.call('permissions:write') && !reloading) {
reloading = true;

// reloading before the server has the changes loses them, and the next load migrates again
setTimeout(() => {
editor.call('settings:project').set('engineV2', true);
window.location.reload();
const projectSettings = editor.call('settings:project');
projectSettings.set('engineV2', true);
projectSettings.whenNothingPending(() => {
editor.api.globals.realtime.scenes.current.whenNothingPending(() => window.location.reload());
});
});
}
};
Expand Down
10 changes: 10 additions & 0 deletions src/editor/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SettingsObserver = Observer & {
id: string;
reload: (...args: unknown[]) => void;
disconnect: () => void;
whenNothingPending: (callback: () => void) => void;
};

editor.once('load', () => {
Expand Down Expand Up @@ -158,6 +159,15 @@ editor.once('load', () => {
}
});

// calls back once the server has every local change
settings.whenNothingPending = (callback) => {
if (doc) {
doc.whenNothingPending(callback);
} else {
callback();
}
};

settings.disconnect = function () {
if (doc) {
doc.destroy();
Expand Down
Loading