void Layout::UpdateBehaviorsSharedData(gd::Project & project) { std::vector < gd::String > allBehaviorsTypes; std::vector < gd::String > allBehaviorsNames; //Search in objects for the type and the name of every behaviors. for (std::size_t i = 0;i<initialObjects.size();++i) { std::vector < gd::String > objectBehaviors = initialObjects[i]->GetAllBehaviorNames(); for (unsigned int j = 0;j<objectBehaviors.size();++j) { gd::Behavior & behavior = initialObjects[i]->GetBehavior(objectBehaviors[j]); allBehaviorsTypes.push_back(behavior.GetTypeName()); allBehaviorsNames.push_back(behavior.GetName()); } } for (std::size_t i = 0;i<project.GetObjectsCount();++i) { std::vector < gd::String > objectBehaviors = project.GetObject(i).GetAllBehaviorNames(); for (std::size_t j = 0;j<objectBehaviors.size();++j) { gd::Behavior & behavior = project.GetObject(i).GetBehavior(objectBehaviors[j]); allBehaviorsTypes.push_back(behavior.GetTypeName()); allBehaviorsNames.push_back(behavior.GetName()); } } //Create non existing shared data for (std::size_t i = 0;i<allBehaviorsTypes.size() && i < allBehaviorsNames.size();++i) { if ( behaviorsInitialSharedDatas.find(allBehaviorsNames[i]) == behaviorsInitialSharedDatas.end() ) { std::shared_ptr<gd::BehaviorsSharedData> behaviorsSharedDatas = project.CreateBehaviorSharedDatas(allBehaviorsTypes[i]); if ( behaviorsSharedDatas ) { behaviorsSharedDatas->SetName(allBehaviorsNames[i]); behaviorsInitialSharedDatas[behaviorsSharedDatas->GetName()] = behaviorsSharedDatas; } } } //Remove useless shared data: //First construct the list of existing shared data. std::vector < gd::String > allSharedData; for (std::map < gd::String, std::shared_ptr<gd::BehaviorsSharedData> >::const_iterator it = behaviorsInitialSharedDatas.begin(); it != behaviorsInitialSharedDatas.end();++it) { allSharedData.push_back(it->first); } //Then delete shared data not linked to a behavior for (std::size_t i = 0;i<allSharedData.size();++i) { if ( std::find(allBehaviorsNames.begin(), allBehaviorsNames.end(), allSharedData[i]) == allBehaviorsNames.end() ) behaviorsInitialSharedDatas.erase(allSharedData[i]); } }
void Layout::UnserializeFrom(gd::Project & project, const SerializerElement & element) { SetBackgroundColor(element.GetIntAttribute( "r" ), element.GetIntAttribute( "v" ), element.GetIntAttribute( "b" )); SetWindowDefaultTitle( element.GetStringAttribute("title", "(No title)", "titre") ); oglFOV = element.GetDoubleAttribute("oglFOV"); oglZNear = element.GetDoubleAttribute("oglZNear"); oglZFar = element.GetDoubleAttribute("oglZFar"); standardSortMethod = element.GetBoolAttribute( "standardSortMethod" ); stopSoundsOnStartup = element.GetBoolAttribute( "stopSoundsOnStartup" ); disableInputWhenNotFocused = element.GetBoolAttribute( "disableInputWhenNotFocused" ); #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) associatedSettings.UnserializeFrom(element.GetChild("uiSettings", 0, "UISettings")); #endif #if defined(GD_IDE_ONLY) gd::ObjectGroup::UnserializeFrom(objectGroups, element.GetChild( "objectsGroups", 0, "GroupesObjets" )); gd::EventsListSerialization::UnserializeEventsFrom(project, GetEvents(), element.GetChild("events", 0, "Events")); #endif UnserializeObjectsFrom(project, element.GetChild("objects", 0, "Objets")); initialInstances.UnserializeFrom(element.GetChild("instances", 0, "Positions")); variables.UnserializeFrom(element.GetChild("variables", 0, "Variables")); initialLayers.clear(); SerializerElement & layersElement = element.GetChild("layers", 0, "Layers"); layersElement.ConsiderAsArrayOf("layer", "Layer"); for (std::size_t i = 0; i < layersElement.GetChildrenCount(); ++i) { gd::Layer layer; layer.UnserializeFrom(layersElement.GetChild(i)); initialLayers.push_back(layer); } //Compatibility with GD <= 4 gd::String deprecatedTag1 = "automatismsSharedData"; gd::String deprecatedTag2 = "automatismSharedData"; if (!element.HasChild(deprecatedTag1)) { deprecatedTag1 = "AutomatismsSharedDatas"; deprecatedTag2 = "AutomatismSharedDatas"; } //end of compatibility code SerializerElement & behaviorsDataElement = element.GetChild("behaviorsSharedData", 0, deprecatedTag1); behaviorsDataElement.ConsiderAsArrayOf("behaviorSharedData", deprecatedTag2); for (unsigned int i = 0; i < behaviorsDataElement.GetChildrenCount(); ++i) { SerializerElement & behaviorDataElement = behaviorsDataElement.GetChild(i); gd::String type = behaviorDataElement.GetStringAttribute("type", "", "Type") .FindAndReplace("Automatism", "Behavior"); //Compatibility with GD <= 4 std::shared_ptr<gd::BehaviorsSharedData> sharedData = project.CreateBehaviorSharedDatas(type); if ( sharedData != std::shared_ptr<gd::BehaviorsSharedData>() ) { sharedData->SetName( behaviorDataElement.GetStringAttribute("name", "", "Name") ); sharedData->UnserializeFrom(behaviorDataElement); behaviorsInitialSharedDatas[sharedData->GetName()] = sharedData; } } }