Files
GDevelop/Extensions/PathBehavior/ScenePathDatas.cpp
T
Florian Rival a8559bfbbc Add clang-format to format (C++) source files automatically (#491)
* Update all CMakeLists of extensions to use clang-format
* Run clang-format on all Extensions
* Update GDCore CMakeLists.txt to add clang-format
* Run clang-format on GDCore files
* Update GDJS and GDCpp CMakeLists.txt to add clang-format
* Run clang-format on GDCpp and GDJS files
2018-05-09 15:57:38 -07:00

46 lines
1.5 KiB
C++

/**
GDevelop - Path Behavior Extension
Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/
#include "ScenePathDatas.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "PathBehavior.h"
#if defined(GD_IDE_ONLY)
void ScenePathDatas::SerializeTo(gd::SerializerElement& element) const {
gd::SerializerElement& pathsElement = element.AddChild("paths");
pathsElement.ConsiderAsArrayOf("path");
for (std::map<gd::String, std::vector<sf::Vector2f> >::const_iterator it =
globalPaths.begin();
it != globalPaths.end();
it++) {
gd::SerializerElement& pathElement = pathsElement.AddChild("path");
pathElement.SetAttribute("name", it->first);
pathElement.SetAttribute(
"coords",
PathBehavior::GetStringFromCoordsVector(it->second, '/', ';'));
}
}
#endif
void ScenePathDatas::UnserializeFrom(const gd::SerializerElement& element) {
globalPaths.clear();
if (!element.HasChild("paths", "Paths")) return;
const gd::SerializerElement& pathsElement =
element.GetChild("paths", 0, "Paths");
pathsElement.ConsiderAsArrayOf("path", "Path");
for (int i = 0; i < pathsElement.GetChildrenCount(); ++i) {
const gd::SerializerElement& pathElement = pathsElement.GetChild(i);
globalPaths[pathElement.GetStringAttribute("name")] =
PathBehavior::GetCoordsVectorFromString(
pathElement.GetStringAttribute("coords"), '/', ';');
}
}