-- Compiled with roblox-ts v3.0.0-dev-834585a local TS = _G[script] local clientWorldsMap = TS.import(script, script.Parent, "clientWorldsMap").clientWorldsMap local componentNameCtorMap = TS.import(script, script.Parent, "componentNameCtorMap").componentNameCtorMap --[[ * * Hydrates the client with the latest state of the world on the server. * * This function will throw an error if the `payload` is corrupted. * * @client ]] local function hydrateClient(world, payload) local _world = world local entityIdMap = clientWorldsMap[_world] if not entityIdMap then entityIdMap = {} local _world_1 = world local _entityIdMap = entityIdMap clientWorldsMap[_world_1] = _entityIdMap end for serverEntityId, components in payload do local clientEntityId = entityIdMap[serverEntityId] local componentsToInsert = {} for componentName, data in components do local component = componentNameCtorMap[componentName] if component then local _arg0 = component(data) table.insert(componentsToInsert, _arg0) end end local _arg0 = not (#componentsToInsert == 0) assert(_arg0, "server sent corrupt hydrate data") if clientEntityId == nil then clientEntityId = world:spawn(unpack(componentsToInsert)) local _entityIdMap = entityIdMap local _clientEntityId = clientEntityId _entityIdMap[serverEntityId] = _clientEntityId else world:replace(clientEntityId, unpack(componentsToInsert)) end end for entityId in world do local doesExistOnServer = false for serverEntityId, clientEntityId in entityIdMap do if clientEntityId == entityId then doesExistOnServer = true entityIdMap[serverEntityId] = nil break end end if not doesExistOnServer then world:despawn(entityId) end end end return { hydrateClient = hydrateClient, }