void ResourcesManager::UnserializeFrom(const SerializerElement & element) { const SerializerElement & resourcesElement = element.GetChild("resources", 0, "Resources"); resourcesElement.ConsiderAsArrayOf("resource", "Resource"); for(std::size_t i = 0;i<resourcesElement.GetChildrenCount();++i) { const SerializerElement & resourceElement = resourcesElement.GetChild(i); gd::String kind = resourceElement.GetStringAttribute("kind"); gd::String name = resourceElement.GetStringAttribute("name"); std::shared_ptr<Resource> resource = CreateResource(kind); resource->SetName(name); resource->UnserializeFrom(resourceElement); resources.push_back(resource); } #if defined(GD_IDE_ONLY) const SerializerElement & resourcesFoldersElement = element.GetChild("resourceFolders", 0, "ResourceFolders"); resourcesFoldersElement.ConsiderAsArrayOf("folder", "Folder"); for(std::size_t i = 0;i<resourcesFoldersElement.GetChildrenCount();++i) { ResourceFolder folder; folder.UnserializeFrom(resourcesFoldersElement.GetChild(i), *this); folders.push_back(folder); } #endif }
/** * \brief Unserialize the layer. */ void Layer::UnserializeFrom(const SerializerElement & element) { SetName(element.GetStringAttribute("name", "", "Name")); SetVisibility(element.GetBoolAttribute("visibility", true, "Visibility")); //Compatibility with GD <= 3.3 if (element.HasChild("Camera")) { for (std::size_t i = 0; i < element.GetChildrenCount("Camera"); ++i) { const SerializerElement & cameraElement = element.GetChild("Camera", i); SetCameraCount(GetCameraCount()+1); Camera & camera = GetCamera(GetCameraCount()-1); camera.SetUseDefaultSize(cameraElement.GetBoolAttribute("DefaultSize", true)); camera.SetSize(cameraElement.GetDoubleAttribute("Width"), cameraElement.GetDoubleAttribute("Height")); camera.SetUseDefaultViewport(cameraElement.GetBoolAttribute("DefaultViewport", true)); camera.SetViewport(cameraElement.GetDoubleAttribute("ViewportLeft"), cameraElement.GetDoubleAttribute("ViewportTop"), cameraElement.GetDoubleAttribute("ViewportRight"), cameraElement.GetDoubleAttribute("ViewportBottom") ); // (sf::Rect used Right and Bottom instead of Width and Height before) } } //End of compatibility code else { SerializerElement & camerasElement = element.GetChild("cameras"); camerasElement.ConsiderAsArrayOf("camera"); for (std::size_t i = 0; i < camerasElement.GetChildrenCount(); ++i) { const SerializerElement & cameraElement = camerasElement.GetChild(i); SetCameraCount(GetCameraCount()+1); Camera & camera = GetCamera(GetCameraCount()-1); camera.SetUseDefaultSize(cameraElement.GetBoolAttribute("defaultSize", true)); camera.SetSize(cameraElement.GetDoubleAttribute("width"), cameraElement.GetDoubleAttribute("height")); camera.SetUseDefaultViewport(cameraElement.GetBoolAttribute("defaultViewport", true)); camera.SetViewport(cameraElement.GetDoubleAttribute("viewportLeft"), cameraElement.GetDoubleAttribute("viewportTop"), cameraElement.GetDoubleAttribute("viewportRight"), cameraElement.GetDoubleAttribute("viewportBottom")); // (sf::Rect used Right and Bottom instead of Width and Height before) } } effects.clear(); SerializerElement & effectsElement = element.GetChild("effects"); effectsElement.ConsiderAsArrayOf("effect"); for (std::size_t i = 0; i < effectsElement.GetChildrenCount(); ++i) { const SerializerElement & effectElement = effectsElement.GetChild(i); auto effect = std::shared_ptr<gd::Effect>(new Effect); effect->UnserializeFrom(effectElement); effects.push_back(effect); } }
void LinkEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { SerializerElement & includeElement = element.GetChild("include", 0, "Limites"); SetTarget(element.GetChild("target", 0, "Scene").GetValue().GetString()); if(includeElement.HasAttribute("includeAll")) { //Compatibility with GDevelop <= 4.0.92 if(includeElement.GetBoolAttribute("includeAll", true)) { SetIncludeAllEvents(); } else { SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"), includeElement.GetIntAttribute("end")); } } else { //GDevelop > 4.0.92 IncludeConfig config = static_cast<IncludeConfig>(includeElement.GetIntAttribute("includeConfig", 0)); if(config == INCLUDE_ALL) SetIncludeAllEvents(); else if(config == INCLUDE_EVENTS_GROUP) SetIncludeEventsGroup(includeElement.GetStringAttribute("eventsGroup")); else if(config == INCLUDE_BY_INDEX) SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"), includeElement.GetIntAttribute("end")); } }
void ForEachEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { objectsToPick = gd::Expression(element.GetChild("object", 0, "Object").GetValue().GetString()); gd::EventsListSerialization::OpenConditions(project, conditions, element.GetChild("conditions", 0, "Conditions")); gd::EventsListSerialization::OpenActions(project, actions, element.GetChild("actions", 0, "Actions")); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events")); }
void RepeatEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { repeatNumberExpression = gd::Expression(element.GetChild("repeatExpression", 0, "RepeatExpression").GetValue().GetString()); gd::EventsListSerialization::OpenConditions(project, conditions, element.GetChild("conditions", 0, "Conditions")); gd::EventsListSerialization::OpenActions(project, actions, element.GetChild("actions", 0, "Actions")); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events")); }
void LinkEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { SerializerElement & includeElement = element.GetChild("include", 0, "Limites"); SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"), includeElement.GetIntAttribute("end")); SetIncludeAllEvents(includeElement.GetBoolAttribute("includeAll", true)); SetTarget(element.GetChild("target", 0, "Scene").GetValue().GetString()); }
void ExternalLayout::UnserializeFrom(const SerializerElement & element) { name = element.GetStringAttribute("name", "", "Name"); instances.UnserializeFrom(element.GetChild("instances", 0, "Instances")); #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) editionSettings.UnserializeFrom(element.GetChild("editionSettings")); associatedLayout = element.GetStringAttribute("associatedLayout"); #endif }
void WhileEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { justCreatedByTheUser = false; infiniteLoopWarning = element.GetBoolAttribute("infiniteLoopWarning"); gd::EventsListSerialization::OpenConditions(project, whileConditions, element.GetChild("whileConditions", 0, "WhileConditions")); gd::EventsListSerialization::OpenConditions(project, conditions, element.GetChild("conditions", 0, "Conditions")); gd::EventsListSerialization::OpenActions(project, actions, element.GetChild("actions", 0, "Actions")); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events")); }
void Object::UnserializeFrom(gd::Project & project, const SerializerElement & element) { //Name and type are already loaded. objectVariables.UnserializeFrom(element.GetChild("variables", 0, "Variables")); //Compatibility with GD <= 3.3 if (element.HasChild("Automatism")) { for (std::size_t i = 0; i < element.GetChildrenCount("Automatism"); ++i) { SerializerElement & behaviorElement = element.GetChild("Automatism", i); gd::String autoType = behaviorElement.GetStringAttribute("type", "", "Type") .FindAndReplace("Automatism", "Behavior"); gd::String autoName = behaviorElement.GetStringAttribute("name", "", "Name"); Behavior* behavior = project.CreateBehavior(autoType); if ( behavior != NULL ) { behavior->SetName(autoName); behavior->UnserializeFrom(behaviorElement); behaviors[behavior->GetName()] = behavior; } else std::cout << "WARNING: Unknown behavior " << autoType << std::endl; } } //End of compatibility code else { SerializerElement & behaviorsElement = element.GetChild("behaviors", 0, "automatisms"); behaviorsElement.ConsiderAsArrayOf("behavior", "automatism"); for (std::size_t i = 0; i < behaviorsElement.GetChildrenCount(); ++i) { SerializerElement & behaviorElement = behaviorsElement.GetChild(i); gd::String autoType = behaviorElement.GetStringAttribute("type") .FindAndReplace("Automatism", "Behavior"); //Compatibility with GD <= 4 gd::String autoName = behaviorElement.GetStringAttribute("name"); Behavior* behavior = project.CreateBehavior(autoType); if ( behavior != NULL ) { behavior->SetName(autoName); behavior->UnserializeFrom(behaviorElement); behaviors[behavior->GetName()] = behavior; } else std::cout << "WARNING: Unknown behavior " << autoType << std::endl; } } DoUnserializeFrom(project, element); }
void CommentEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { const SerializerElement & colorElement = element.GetChild("color", 0, "Couleur"); r = colorElement.GetIntAttribute("r"); v = colorElement.GetIntAttribute("g", 0, "v"); b = colorElement.GetIntAttribute("b"); textR = colorElement.GetIntAttribute("textR"); textG = colorElement.GetIntAttribute("textG"); textB = colorElement.GetIntAttribute("textB"); com1 = element.GetChild("comment", 0, "Com1").GetValue().GetString(); com2 = element.GetChild("comment2", 0, "Com2").GetValue().GetString(); }
void ExternalEvents::UnserializeFrom(gd::Project & project, const SerializerElement & element) { name = element.GetStringAttribute("name", "", "Name"); associatedScene = element.GetStringAttribute("associatedLayout", "", "AssociatedScene"); lastChangeTimeStamp = element.GetIntAttribute("lastChangeTimeStamp", 0, "LastChangeTimeStamp"); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events")); }
void GroupEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { name = element.GetStringAttribute("name"); source = element.GetStringAttribute("source"); creationTime = element.GetIntAttribute("creationTime"); colorR = element.GetIntAttribute("colorR"); colorG = element.GetIntAttribute("colorG"); colorB = element.GetIntAttribute("colorB"); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events")); parameters.clear(); gd::SerializerElement & parametersElement = element.GetChild("parameters"); parametersElement.ConsiderAsArrayOf("parameters"); for ( std::size_t i = 0;i < parametersElement.GetChildrenCount();++i) parameters.push_back(parametersElement.GetChild(i).GetValue().GetString()); }
void ObjectGroup::UnserializeFrom(std::vector < gd::ObjectGroup > & list, const SerializerElement & element) { element.ConsiderAsArrayOf("group", "Groupe"); for (unsigned int i = 0; i < element.GetChildrenCount(); ++i) { SerializerElement & groupElement = element.GetChild(i); gd::ObjectGroup objectGroup; objectGroup.SetName(groupElement.GetStringAttribute("name", "", "nom")); //Compatibility with GD <= 3.3 if ( groupElement.HasChild("Objet") ) { for (unsigned int j = 0; j < groupElement.GetChildrenCount("Objet"); ++j) objectGroup.AddObject(groupElement.GetChild("Objet", j).GetStringAttribute("nom")); } //End of compatibility code else { SerializerElement & objectsElement = groupElement.GetChild("objects"); objectsElement.ConsiderAsArrayOf("object"); for (unsigned int j = 0; j < objectsElement.GetChildrenCount(); ++j) objectGroup.AddObject(objectsElement.GetChild(j).GetStringAttribute("name")); } list.push_back( objectGroup ); } }
void ResourceFolder::UnserializeFrom(const SerializerElement & element, gd::ResourcesManager & parentManager) { name = element.GetStringAttribute("name"); SerializerElement & resourcesElement = element.GetChild("resources", 0, "Resources"); resourcesElement.ConsiderAsArrayOf("resource", "Resource"); for(std::size_t i = 0;i<resourcesElement.GetChildrenCount();++i) AddResource(resourcesElement.GetChild(i).GetStringAttribute("name"), parentManager); }
void gd::EventsListSerialization::OpenConditions(gd::Project & project, gd::InstructionsList & conditions, const SerializerElement & elem) { elem.ConsiderAsArrayOf("condition", "Condition"); for(std::size_t i = 0; i<elem.GetChildrenCount(); ++i) { gd::Instruction instruction; const SerializerElement & conditionElem = elem.GetChild(i); instruction.SetType(conditionElem.GetChild("type", 0, "Type").GetStringAttribute("value") .FindAndReplace("Automatism", "Behavior")); //Compatibility with GD <= 4 instruction.SetInverted(conditionElem.GetChild("type", 0, "Type").GetBoolAttribute("inverted", false, "Contraire")); //Read parameters vector < gd::Expression > parameters; //Compatibility with GD <= 3.3 if (conditionElem.HasChild("Parametre")) { for (std::size_t j = 0;j<conditionElem.GetChildrenCount("Parametre");++j) parameters.push_back(gd::Expression(conditionElem.GetChild("Parametre", j).GetValue().GetString())); } //end of compatibility code else { const SerializerElement & parametersElem = conditionElem.GetChild("parameters"); parametersElem.ConsiderAsArrayOf("parameter"); for (std::size_t j = 0;j<parametersElem.GetChildrenCount();++j) parameters.push_back(gd::Expression(parametersElem.GetChild(j).GetValue().GetString())); } instruction.SetParameters( parameters ); //Read sub conditions if ( conditionElem.HasChild("subConditions", "SubConditions") ) OpenConditions(project, instruction.GetSubInstructions(), conditionElem.GetChild("subConditions", 0, "SubConditions" )); conditions.Insert( instruction ); } if ( project.GetLastSaveGDMajorVersion() < 3 || (project.GetLastSaveGDMajorVersion() == 3 && project.GetLastSaveGDMinorVersion() <= 1 ) ) UpdateInstructionsFromGD31x(project, conditions, false); if ( project.GetLastSaveGDMajorVersion() < 3 ) UpdateInstructionsFromGD2x(project, conditions, false); }
void gd::EventsListSerialization::OpenActions(gd::Project & project, vector < gd::Instruction > & actions, const SerializerElement & elem) { elem.ConsiderAsArrayOf("action", "Action"); for(unsigned int i = 0; i<elem.GetChildrenCount(); ++i) { gd::Instruction instruction; const SerializerElement & actionElem = elem.GetChild(i); instruction.SetType( actionElem.GetChild("type", 0, "Type").GetStringAttribute("value") ); //Read parameters vector < gd::Expression > parameters; //Compatibility with GD <= 3.3 if (actionElem.HasChild("Parametre")) { for (unsigned int j = 0;j<actionElem.GetChildrenCount("Parametre");++j) parameters.push_back(gd::Expression(actionElem.GetChild("Parametre", j).GetValue().GetString())); } //end of compatibility code else { const SerializerElement & parametersElem = actionElem.GetChild("parameters"); parametersElem.ConsiderAsArrayOf("parameter"); for (unsigned int j = 0;j<parametersElem.GetChildrenCount();++j) parameters.push_back(gd::Expression(parametersElem.GetChild(j).GetValue().GetString())); } instruction.SetParameters( parameters ); //Read sub actions if ( actionElem.HasChild("subActions", "SubActions") ) OpenActions(project, instruction.GetSubInstructions(), actionElem.GetChild("subActions", 0, "SubActions" )); actions.push_back( instruction ); } if ( project.GetLastSaveGDMajorVersion() < 3 || (project.GetLastSaveGDMajorVersion() == 3 && project.GetLastSaveGDMinorVersion() <= 1 ) ) UpdateInstructionsFromGD31x(project, actions, true); if ( project.GetLastSaveGDMajorVersion() < 3 ) UpdateInstructionsFromGD2x(project, actions, true); }
void EventsFunctionsExtension::UnserializeFrom( gd::Project& project, const SerializerElement& element) { version = element.GetStringAttribute("version"); extensionNamespace = element.GetStringAttribute("extensionNamespace"); description = element.GetStringAttribute("description"); name = element.GetStringAttribute("name"); fullName = element.GetStringAttribute("fullName"); const gd::SerializerElement& eventsFunctionsElement = element.GetChild("eventsFunctions"); eventsFunctions.clear(); eventsFunctionsElement.ConsiderAsArrayOf("eventsFunction"); for (std::size_t i = 0; i < eventsFunctionsElement.GetChildrenCount(); ++i) { gd::EventsFunction& newEventsFunction = InsertNewEventsFunction("", GetEventsFunctionsCount()); newEventsFunction.UnserializeFrom(project, eventsFunctionsElement.GetChild(i)); } }
void ClassWithObjects::UnserializeObjectsFrom(gd::Project & project, const SerializerElement & element) { initialObjects.clear(); element.ConsiderAsArrayOf("object", "Objet"); for (std::size_t i = 0; i < element.GetChildrenCount(); ++i) { const SerializerElement & objectElement = element.GetChild(i); gd::String type = objectElement.GetStringAttribute("type"); std::shared_ptr<gd::Object> newObject = project.CreateObject(type, objectElement.GetStringAttribute("name", "", "nom")); if ( newObject != std::shared_ptr<gd::Object>() ) { newObject->UnserializeFrom(project, objectElement); initialObjects.push_back( newObject ); } else std::cout << "WARNING: Unknown object type \"" << type << "\"" << std::endl; } }
void Variable::UnserializeFrom(const SerializerElement & element) { isStructure = element.HasChild("children", "Children"); if (isStructure) { const SerializerElement & childrenElement = element.GetChild("children", 0, "Children"); childrenElement.ConsiderAsArrayOf("variable", "Variable"); for (int i = 0; i < childrenElement.GetChildrenCount(); ++i) { const SerializerElement & childElement = childrenElement.GetChild(i); std::string name = childElement.GetStringAttribute("name", "", "Name"); gd::Variable childVariable; childVariable.UnserializeFrom(childElement); children[name] = childVariable; } } else SetString(element.GetStringAttribute("value", "", "Value")); }
void EventsListSerialization::UnserializeEventsFrom(gd::Project & project, EventsList & list, const SerializerElement & events) { events.ConsiderAsArrayOf("event", "Event"); for(unsigned int i = 0; i<events.GetChildrenCount(); ++i) { SerializerElement & eventElem = events.GetChild(i); std::string type = eventElem.GetChild("type", 0, "Type").GetValue().GetString(); gd::BaseEventSPtr event = project.CreateEvent(type); if ( event != std::shared_ptr<gd::BaseEvent>()) event->UnserializeFrom(project, eventElem); else { std::cout << "WARNING: Unknown event of type " << type << std::endl; event = std::shared_ptr<gd::BaseEvent>(new EmptyEvent); } event->SetDisabled(eventElem.GetBoolAttribute("disabled")); event->folded = eventElem.GetBoolAttribute("folded"); list.InsertEvent(event, list.GetEventsCount()); } }
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; } } }
void StandardEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element) { gd::EventsListSerialization::OpenConditions(project, conditions, element.GetChild("conditions", 0, "Conditions")); gd::EventsListSerialization::OpenActions(project, actions, element.GetChild("actions", 0, "Actions")); gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events")); }