// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "SceneObject.h"
///
/// Helper class for scene objects creation and deserialization utilities.
///
class SceneObjectsFactory
{
public:
typedef Dictionary ActorToRemovedObjectsDataLookup;
public:
///
/// Creates the scene object from the specified data value. Does not perform deserialization.
///
/// The serialized data stream.
/// The serialization modifier. Cannot be null.
static SceneObject* Spawn(ISerializable::DeserializeStream& stream, ISerializeModifier* modifier);
///
/// Deserializes the scene object from the specified data value.
///
/// The instance to deserialize.
/// The serialized data stream.
/// The serialization modifier. Cannot be null.
static void Deserialize(SceneObject* obj, ISerializable::DeserializeStream& stream, ISerializeModifier* modifier);
///
/// Synchronizes the prefab instances. Prefabs may have new objects added or some removed so deserialized instances need to synchronize with it. Handles also changing prefab object parent in the instance.
///
///
/// Should be called after scene objects deserialization and PostLoad event when scene objects hierarchy is ready (parent-child relation exists). But call it before Init and BeginPlay events.
///
/// The loaded scene objects. Collection will be modified after usage.
/// Maps the loaded actor object to the json data with the RemovedObjects array (used to skip restoring objects removed per prefab instance).
/// The objects deserialization modifier. Collection will be modified after usage.
static void SynchronizePrefabInstances(Array& sceneObjects, const ActorToRemovedObjectsDataLookup& actorToRemovedObjectsData, ISerializeModifier* modifier);
///
/// Handles the object deserialization error.
///
/// The value.
static void HandleObjectDeserializationError(const ISerializable::DeserializeStream& value);
///
/// Creates a new actor object of the given type identifier.
/// [Deprecated: 18.07.2019 expires 18.07.2020]
///
/// The type identifier.
/// The actor identifier.
/// The created actor, or null if failed.
static Actor* CreateActor(int32 typeId, const Guid& id);
private:
static void SynchronizeNewPrefabInstance(Prefab* prefab, Actor* actor, const Guid& prefabObjectId, Array& sceneObjects, ISerializeModifier* modifier);
};