Skip to content
Closed
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
20 changes: 11 additions & 9 deletions src/game/m_world_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ export const world_store_lists_merge = config => {
world_local.label +
locale_warn_world_remote_missing_2
);
debugger;
/*defer();
defer();
actions.world_prop(world_local.id, {
mod_r: WORLD_STORED_NOT,
});*/
});
}

world_list.push({
Expand Down Expand Up @@ -222,6 +221,10 @@ export const world_store_sync_check = async () => {
)
) {
await world_store_sync(world_syncable);
// Mark as synced in the current list to prevent re-syncing
// before state updates propagate
const synced_time = Math_max(world_syncable.local, world_syncable.remote);
world_syncable.local = world_syncable.remote = synced_time;
actions.state_patch({
world_syncing: null,
});
Expand Down Expand Up @@ -284,7 +287,6 @@ const world_store_sync = async world => {
const data_promise = chunks_get(id);
let id_new = id;

let rename_promise = null;
// world must be registered first?
if (world.remote === WORLD_STORED_SHOULD) {
const response_register = await fetch_(API + 'world', {
Expand All @@ -295,10 +297,11 @@ const world_store_sync = async world => {
}),
});
const result_register = await response_parse(response_register);
rename_promise = chunks_rename(
world_renamed_id_old = id,
world_renamed_id_new = id_new = result_register.id
);
id_new = result_register.id;
// Await rename before upload to avoid inconsistent state if upload fails
world_renamed_id_old = id;
world_renamed_id_new = id_new;
await chunks_rename(id, id_new);
}

const response_upload = await fetch_(API + 'world', {
Expand All @@ -317,7 +320,6 @@ const world_store_sync = async world => {
mod_l: result_upload.modified,
mod_r: result_upload.modified,
});
await rename_promise;
}
else {
actions.world_prop(id, {
Expand Down