Exemplo n.º 1
0
void SaveEntityAsAction::Redo()
{
	if(!sc2Path.IsEmpty() && sc2Path.IsEqualToExtension(".sc2") &&
		NULL != entities && entities->Size() > 0)
	{
		DAVA::Scene *scene = new DAVA::Scene();
        Vector3 oldZero = entities->GetCommonZeroPos();
		for(size_t i = 0; i < entities->Size(); ++i)
		{
			DAVA::Entity *entity = entities->GetEntity(i);
			DAVA::Entity *clone = entity->Clone();

            Vector3 offset = clone->GetLocalTransform().GetTranslationVector() - oldZero;
            Matrix4 newLocalTransform = clone->GetLocalTransform();
            newLocalTransform.SetTranslationVector(offset);
            clone->SetLocalTransform(newLocalTransform);

            DAVA::KeyedArchive *props = GetCustomPropertiesArchieve(clone);
            if(props)
            {
                props->DeleteKey(ResourceEditor::EDITOR_REFERENCE_TO_OWNER);
            }
            
			scene->AddNode(clone);
		}

        scene->Save(sc2Path);

		scene->Release();
	}
}