refactor to not expose tinyxml2 symbols
This commit is contained in:
		
							
								
								
									
										156
									
								
								src/anm2.cpp
									
									
									
									
									
								
							
							
						
						
									
										156
									
								
								src/anm2.cpp
									
									
									
									
									
								
							@@ -1,5 +1,7 @@
 | 
			
		||||
#include "anm2.h"
 | 
			
		||||
 | 
			
		||||
using namespace tinyxml2;
 | 
			
		||||
 | 
			
		||||
static void _anm2_created_on_set(Anm2* self)
 | 
			
		||||
{
 | 
			
		||||
	auto now = std::chrono::system_clock::now();
 | 
			
		||||
@@ -11,13 +13,12 @@ static void _anm2_created_on_set(Anm2* self)
 | 
			
		||||
	self->createdOn = timeString.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void anm2_frame_serialize(Anm2Frame* frame, Anm2Type type, tinyxml2::XMLDocument* document = nullptr, tinyxml2::XMLElement* addElement = nullptr, std::string* string = nullptr)
 | 
			
		||||
static void _anm2_frame_serialize(Anm2Frame* frame, Anm2Type type, XMLDocument* document = nullptr, XMLElement* addElement = nullptr, std::string* string = nullptr)
 | 
			
		||||
{
 | 
			
		||||
	tinyxml2::XMLDocument localDocument;
 | 
			
		||||
	tinyxml2::XMLDocument* useDocument = document ? document : &localDocument;
 | 
			
		||||
	XMLDocument localDocument;
 | 
			
		||||
	XMLDocument* useDocument = document ? document : &localDocument;
 | 
			
		||||
 | 
			
		||||
	tinyxml2::XMLElement* element = type == ANM2_TRIGGERS ? useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGERS]) : 
 | 
			
		||||
												  useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_FRAME]);
 | 
			
		||||
	XMLElement* element = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_FRAME]);
 | 
			
		||||
	
 | 
			
		||||
	if (type == ANM2_TRIGGERS)
 | 
			
		||||
	{
 | 
			
		||||
@@ -65,38 +66,38 @@ void anm2_frame_serialize(Anm2Frame* frame, Anm2Type type, tinyxml2::XMLDocument
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void anm2_animation_serialize(Anm2Animation* animation, tinyxml2::XMLDocument* document = nullptr, tinyxml2::XMLElement* addElement = nullptr, std::string* string = nullptr)
 | 
			
		||||
static void _anm2_animation_serialize(Anm2Animation* animation, XMLDocument* document = nullptr, XMLElement* addElement = nullptr, std::string* string = nullptr)
 | 
			
		||||
{
 | 
			
		||||
	tinyxml2::XMLDocument localDocument;
 | 
			
		||||
	tinyxml2::XMLDocument* useDocument = document ? document : &localDocument;
 | 
			
		||||
	XMLDocument localDocument;
 | 
			
		||||
	XMLDocument* useDocument = document ? document : &localDocument;
 | 
			
		||||
 | 
			
		||||
	// Animation
 | 
			
		||||
	tinyxml2::XMLElement* element = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION]);
 | 
			
		||||
	XMLElement* element = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION]);
 | 
			
		||||
	element->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_NAME], animation->name.c_str()); // Name
 | 
			
		||||
	element->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_FRAME_NUM], animation->frameNum); // FrameNum
 | 
			
		||||
	element->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_LOOP], animation->isLoop); // Loop
 | 
			
		||||
 | 
			
		||||
	// RootAnimation
 | 
			
		||||
	tinyxml2::XMLElement* rootElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ROOT_ANIMATION]);
 | 
			
		||||
	XMLElement* rootElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ROOT_ANIMATION]);
 | 
			
		||||
 | 
			
		||||
	for (auto& frame : animation->rootAnimation.frames)
 | 
			
		||||
		anm2_frame_serialize(&frame, ANM2_ROOT, useDocument, rootElement);
 | 
			
		||||
		_anm2_frame_serialize(&frame, ANM2_ROOT, useDocument, rootElement);
 | 
			
		||||
 | 
			
		||||
	element->InsertEndChild(rootElement);
 | 
			
		||||
 | 
			
		||||
	// LayerAnimations
 | 
			
		||||
	tinyxml2::XMLElement* layersElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATIONS]);
 | 
			
		||||
	XMLElement* layersElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATIONS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& id : animation->layerOrder)
 | 
			
		||||
	{
 | 
			
		||||
		// LayerAnimation
 | 
			
		||||
		Anm2Item& layerAnimation = animation->layerAnimations[id];
 | 
			
		||||
		tinyxml2::XMLElement* layerElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATION]);
 | 
			
		||||
		XMLElement* layerElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATION]);
 | 
			
		||||
		layerElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_LAYER_ID], id); // LayerId
 | 
			
		||||
		layerElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_VISIBLE], layerAnimation.isVisible); // Visible 
 | 
			
		||||
 | 
			
		||||
		for (auto& frame : layerAnimation.frames)
 | 
			
		||||
			anm2_frame_serialize(&frame, ANM2_LAYER, useDocument, layerElement);
 | 
			
		||||
			_anm2_frame_serialize(&frame, ANM2_LAYER, useDocument, layerElement);
 | 
			
		||||
 | 
			
		||||
		layersElement->InsertEndChild(layerElement);
 | 
			
		||||
	}
 | 
			
		||||
@@ -104,17 +105,17 @@ void anm2_animation_serialize(Anm2Animation* animation, tinyxml2::XMLDocument* d
 | 
			
		||||
	element->InsertEndChild(layersElement);
 | 
			
		||||
 | 
			
		||||
	// Nulls
 | 
			
		||||
	tinyxml2::XMLElement* nullsElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATIONS]);
 | 
			
		||||
	XMLElement* nullsElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATIONS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& [id, null] : animation->nullAnimations)
 | 
			
		||||
	{
 | 
			
		||||
		// NullAnimation
 | 
			
		||||
		tinyxml2::XMLElement* nullElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATION]);
 | 
			
		||||
		XMLElement* nullElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATION]);
 | 
			
		||||
		nullElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_NULL_ID], id); // NullId
 | 
			
		||||
		nullElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_VISIBLE], null.isVisible); // Visible 
 | 
			
		||||
		
 | 
			
		||||
		for (auto& frame : null.frames)
 | 
			
		||||
			anm2_frame_serialize(&frame, ANM2_NULL, useDocument, nullElement);
 | 
			
		||||
			_anm2_frame_serialize(&frame, ANM2_NULL, useDocument, nullElement);
 | 
			
		||||
 | 
			
		||||
		nullsElement->InsertEndChild(nullElement);
 | 
			
		||||
	}
 | 
			
		||||
@@ -122,10 +123,10 @@ void anm2_animation_serialize(Anm2Animation* animation, tinyxml2::XMLDocument* d
 | 
			
		||||
	element->InsertEndChild(nullsElement);
 | 
			
		||||
 | 
			
		||||
	// Triggers 
 | 
			
		||||
	tinyxml2::XMLElement* triggersElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGERS]);
 | 
			
		||||
	XMLElement* triggersElement = useDocument->NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGERS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& frame : animation->triggers.frames)
 | 
			
		||||
		anm2_frame_serialize(&frame, ANM2_TRIGGERS, useDocument, triggersElement);
 | 
			
		||||
		_anm2_frame_serialize(&frame, ANM2_TRIGGERS, useDocument, triggersElement);
 | 
			
		||||
 | 
			
		||||
	element->InsertEndChild(triggersElement);
 | 
			
		||||
	
 | 
			
		||||
@@ -142,7 +143,7 @@ void anm2_animation_serialize(Anm2Animation* animation, tinyxml2::XMLDocument* d
 | 
			
		||||
 | 
			
		||||
bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
{
 | 
			
		||||
	tinyxml2::XMLDocument document;
 | 
			
		||||
	XMLDocument document;
 | 
			
		||||
 | 
			
		||||
	if (!self || path.empty()) return false;
 | 
			
		||||
 | 
			
		||||
@@ -152,11 +153,11 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	self->version++;
 | 
			
		||||
 | 
			
		||||
	// AnimatedActor
 | 
			
		||||
	tinyxml2::XMLElement* animatedActorElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATED_ACTOR]);
 | 
			
		||||
	XMLElement* animatedActorElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATED_ACTOR]);
 | 
			
		||||
	document.InsertFirstChild(animatedActorElement);
 | 
			
		||||
 | 
			
		||||
	// Info 
 | 
			
		||||
	tinyxml2::XMLElement* infoElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_INFO]);
 | 
			
		||||
	XMLElement* infoElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_INFO]);
 | 
			
		||||
	infoElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_CREATED_BY], self->createdBy.c_str()); // CreatedBy 
 | 
			
		||||
	infoElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_CREATED_ON], self->createdOn.c_str()); // CreatedOn 
 | 
			
		||||
	infoElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_VERSION], self->version); // Version
 | 
			
		||||
@@ -164,15 +165,15 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	animatedActorElement->InsertEndChild(infoElement);
 | 
			
		||||
 | 
			
		||||
	// Content 
 | 
			
		||||
	tinyxml2::XMLElement* contentElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_CONTENT]);
 | 
			
		||||
	XMLElement* contentElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_CONTENT]);
 | 
			
		||||
	
 | 
			
		||||
	// Spritesheets 
 | 
			
		||||
	tinyxml2::XMLElement* spritesheetsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEETS]);
 | 
			
		||||
	XMLElement* spritesheetsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEETS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& [id, spritesheet] : self->spritesheets)
 | 
			
		||||
	{
 | 
			
		||||
		// Spritesheet 
 | 
			
		||||
		tinyxml2::XMLElement* spritesheetElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEET]);
 | 
			
		||||
		XMLElement* spritesheetElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEET]);
 | 
			
		||||
		spritesheetElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_PATH], spritesheet.path.c_str()); // Path 
 | 
			
		||||
		spritesheetElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_ID], id); // ID 
 | 
			
		||||
		spritesheetsElement->InsertEndChild(spritesheetElement);
 | 
			
		||||
@@ -181,12 +182,12 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	contentElement->InsertEndChild(spritesheetsElement);
 | 
			
		||||
	
 | 
			
		||||
	// Layers 
 | 
			
		||||
	tinyxml2::XMLElement* layersElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYERS]);
 | 
			
		||||
	XMLElement* layersElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYERS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& [id, layer] : self->layers)
 | 
			
		||||
	{
 | 
			
		||||
		// Layer 
 | 
			
		||||
		tinyxml2::XMLElement* layerElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER]);
 | 
			
		||||
		XMLElement* layerElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER]);
 | 
			
		||||
		layerElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_NAME], layer.name.c_str()); // Path 
 | 
			
		||||
		layerElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_ID], id); // ID 
 | 
			
		||||
		layerElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_SPRITESHEET_ID], layer.spritesheetID); // SpritesheetId 
 | 
			
		||||
@@ -196,12 +197,12 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	contentElement->InsertEndChild(layersElement);
 | 
			
		||||
	
 | 
			
		||||
	// Nulls 
 | 
			
		||||
	tinyxml2::XMLElement* nullsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULLS]);
 | 
			
		||||
	XMLElement* nullsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULLS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& [id, null] : self->nulls)
 | 
			
		||||
	{
 | 
			
		||||
		// Null 
 | 
			
		||||
		tinyxml2::XMLElement* nullElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL]);
 | 
			
		||||
		XMLElement* nullElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL]);
 | 
			
		||||
		nullElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_NAME], null.name.c_str()); // Name 
 | 
			
		||||
		nullElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_ID], id); // ID 
 | 
			
		||||
		if (null.isShowRect) nullElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_SHOW_RECT], null.isShowRect); // ShowRect 
 | 
			
		||||
@@ -211,12 +212,12 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	contentElement->InsertEndChild(nullsElement);
 | 
			
		||||
 | 
			
		||||
	// Events 
 | 
			
		||||
	tinyxml2::XMLElement* eventsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENTS]);
 | 
			
		||||
	XMLElement* eventsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENTS]);
 | 
			
		||||
 | 
			
		||||
	for (auto& [id, event] : self->events)
 | 
			
		||||
	{
 | 
			
		||||
		// Event 
 | 
			
		||||
		tinyxml2::XMLElement* eventElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENT]);
 | 
			
		||||
		XMLElement* eventElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENT]);
 | 
			
		||||
		eventElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_NAME], event.name.c_str()); // Name 
 | 
			
		||||
		eventElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_ID], id); // ID 
 | 
			
		||||
		eventsElement->InsertEndChild(eventElement);
 | 
			
		||||
@@ -227,12 +228,12 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	animatedActorElement->InsertEndChild(contentElement);
 | 
			
		||||
 | 
			
		||||
	// Animations
 | 
			
		||||
	tinyxml2::XMLElement* animationsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATIONS]);
 | 
			
		||||
	XMLElement* animationsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATIONS]);
 | 
			
		||||
	if (self->defaultAnimationID != ID_NONE)  
 | 
			
		||||
		animationsElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_DEFAULT_ANIMATION], self->animations[self->defaultAnimationID].name.c_str()); // DefaultAnimation
 | 
			
		||||
	
 | 
			
		||||
	for (auto& [id, animation] : self->animations)
 | 
			
		||||
		anm2_animation_serialize(&animation, &document, animationsElement);
 | 
			
		||||
		_anm2_animation_serialize(&animation, &document, animationsElement);
 | 
			
		||||
 | 
			
		||||
	animatedActorElement->InsertEndChild(animationsElement);
 | 
			
		||||
 | 
			
		||||
@@ -249,9 +250,9 @@ bool anm2_serialize(Anm2* self, const std::string& path)
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _anm2_frame_deserialize(Anm2Frame* frame, const tinyxml2::XMLElement* element)
 | 
			
		||||
static void _anm2_frame_deserialize(Anm2Frame* frame, const XMLElement* element)
 | 
			
		||||
{
 | 
			
		||||
	for (const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
	for (const XMLAttribute* attribute = element->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
	{
 | 
			
		||||
		switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
		{
 | 
			
		||||
@@ -283,14 +284,14 @@ static void _anm2_frame_deserialize(Anm2Frame* frame, const tinyxml2::XMLElement
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _anm2_animation_deserialize(Anm2Animation* animation, const tinyxml2::XMLElement* element)
 | 
			
		||||
static void _anm2_animation_deserialize(Anm2Animation* animation, const XMLElement* element)
 | 
			
		||||
{
 | 
			
		||||
	auto frames_deserialize = [&](const tinyxml2::XMLElement* itemElement, Anm2Item* item)
 | 
			
		||||
	auto frames_deserialize = [&](const XMLElement* itemElement, Anm2Item* item)
 | 
			
		||||
	{
 | 
			
		||||
		// Frame
 | 
			
		||||
		for 
 | 
			
		||||
		(
 | 
			
		||||
			const tinyxml2::XMLElement* frame = itemElement->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_FRAME]); 
 | 
			
		||||
			const XMLElement* frame = itemElement->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_FRAME]); 
 | 
			
		||||
			frame; frame = frame->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_FRAME])
 | 
			
		||||
		)
 | 
			
		||||
			_anm2_frame_deserialize(&item->frames.emplace_back(Anm2Frame()), frame);
 | 
			
		||||
@@ -298,7 +299,7 @@ static void _anm2_animation_deserialize(Anm2Animation* animation, const tinyxml2
 | 
			
		||||
 | 
			
		||||
	s32 id{};
 | 
			
		||||
 | 
			
		||||
	for (const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
	for (const XMLAttribute* attribute = element->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
	{
 | 
			
		||||
		switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
		{
 | 
			
		||||
@@ -310,22 +311,22 @@ static void _anm2_animation_deserialize(Anm2Animation* animation, const tinyxml2
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// RootAnimation
 | 
			
		||||
    if (const tinyxml2::XMLElement* rootAnimation = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ROOT_ANIMATION])) 
 | 
			
		||||
    if (const XMLElement* rootAnimation = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ROOT_ANIMATION])) 
 | 
			
		||||
		frames_deserialize(rootAnimation, &animation->rootAnimation);
 | 
			
		||||
 | 
			
		||||
	// LayerAnimations
 | 
			
		||||
	if (const tinyxml2::XMLElement* layerAnimations = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATIONS])) 
 | 
			
		||||
	if (const XMLElement* layerAnimations = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATIONS])) 
 | 
			
		||||
	{
 | 
			
		||||
		// LayerAnimation
 | 
			
		||||
		for 
 | 
			
		||||
		(
 | 
			
		||||
			const tinyxml2::XMLElement* layerAnimation = layerAnimations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATION]);
 | 
			
		||||
			const XMLElement* layerAnimation = layerAnimations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATION]);
 | 
			
		||||
			layerAnimation; layerAnimation = layerAnimation->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER_ANIMATION])
 | 
			
		||||
		)
 | 
			
		||||
		{ 
 | 
			
		||||
			Anm2Item layerAnimationItem;
 | 
			
		||||
			
 | 
			
		||||
			for (const tinyxml2::XMLAttribute* attribute = layerAnimation->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
			for (const XMLAttribute* attribute = layerAnimation->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
			{	
 | 
			
		||||
				switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
				{
 | 
			
		||||
@@ -342,18 +343,18 @@ static void _anm2_animation_deserialize(Anm2Animation* animation, const tinyxml2
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// NullAnimations
 | 
			
		||||
	if (const tinyxml2::XMLElement* nullAnimations = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATIONS])) 
 | 
			
		||||
	if (const XMLElement* nullAnimations = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATIONS])) 
 | 
			
		||||
	{
 | 
			
		||||
		// NullAnimation
 | 
			
		||||
		for 
 | 
			
		||||
		(
 | 
			
		||||
			const tinyxml2::XMLElement* nullAnimation = nullAnimations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATION]);
 | 
			
		||||
			const XMLElement* nullAnimation = nullAnimations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATION]);
 | 
			
		||||
			nullAnimation; nullAnimation = nullAnimation->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL_ANIMATION])
 | 
			
		||||
		)
 | 
			
		||||
		{ 
 | 
			
		||||
			Anm2Item nullAnimationItem;
 | 
			
		||||
			
 | 
			
		||||
			for (const tinyxml2::XMLAttribute* attribute = nullAnimation->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
			for (const XMLAttribute* attribute = nullAnimation->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
			{	
 | 
			
		||||
				switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
				{
 | 
			
		||||
@@ -369,12 +370,12 @@ static void _anm2_animation_deserialize(Anm2Animation* animation, const tinyxml2
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Triggers
 | 
			
		||||
	if (const tinyxml2::XMLElement* triggers = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGERS])) 
 | 
			
		||||
	if (const XMLElement* triggers = element->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGERS])) 
 | 
			
		||||
	{
 | 
			
		||||
		// Trigger
 | 
			
		||||
		for 
 | 
			
		||||
		(
 | 
			
		||||
			const tinyxml2::XMLElement* trigger = triggers->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGER]); 
 | 
			
		||||
			const XMLElement* trigger = triggers->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGER]); 
 | 
			
		||||
			trigger; trigger = trigger->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_TRIGGER])
 | 
			
		||||
		)
 | 
			
		||||
			_anm2_frame_deserialize(&animation->triggers.frames.emplace_back(Anm2Frame()), trigger);
 | 
			
		||||
@@ -391,7 +392,7 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tinyxml2::XMLDocument document;
 | 
			
		||||
	XMLDocument document;
 | 
			
		||||
	if (document.LoadFile(path.c_str()) != XML_SUCCESS)
 | 
			
		||||
	{
 | 
			
		||||
		log_error(std::format(ANM2_PARSE_ERROR, path, document.ErrorStr()));
 | 
			
		||||
@@ -408,12 +409,12 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
    std::filesystem::path workingPath = std::filesystem::current_path();
 | 
			
		||||
	working_directory_from_file_set(path);
 | 
			
		||||
	
 | 
			
		||||
	const tinyxml2::XMLElement* root = document.RootElement();
 | 
			
		||||
	const XMLElement* root = document.RootElement();
 | 
			
		||||
	
 | 
			
		||||
	// Info
 | 
			
		||||
	if (const tinyxml2::XMLElement* info = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_INFO])) 
 | 
			
		||||
	if (const XMLElement* info = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_INFO])) 
 | 
			
		||||
	{
 | 
			
		||||
		for (const tinyxml2::XMLAttribute* attribute = info->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
		for (const XMLAttribute* attribute = info->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
		{
 | 
			
		||||
			switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
			{
 | 
			
		||||
@@ -427,20 +428,20 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// Content
 | 
			
		||||
	if (const tinyxml2::XMLElement* content = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_CONTENT])) 
 | 
			
		||||
	if (const XMLElement* content = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_CONTENT])) 
 | 
			
		||||
	{
 | 
			
		||||
		// Spritesheets
 | 
			
		||||
		if (const tinyxml2::XMLElement* spritesheets = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEETS]))
 | 
			
		||||
		if (const XMLElement* spritesheets = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEETS]))
 | 
			
		||||
		{
 | 
			
		||||
			for 
 | 
			
		||||
			(
 | 
			
		||||
				const tinyxml2::XMLElement* spritesheet = spritesheets->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEET]);
 | 
			
		||||
				const XMLElement* spritesheet = spritesheets->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEET]);
 | 
			
		||||
				spritesheet; spritesheet = spritesheet->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_SPRITESHEET])
 | 
			
		||||
			)
 | 
			
		||||
			{
 | 
			
		||||
				Anm2Spritesheet addSpritesheet;
 | 
			
		||||
				
 | 
			
		||||
				for (const tinyxml2::XMLAttribute* attribute = spritesheet->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				for (const XMLAttribute* attribute = spritesheet->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				{	
 | 
			
		||||
					switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
					{
 | 
			
		||||
@@ -464,17 +465,17 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Layers
 | 
			
		||||
		if (const tinyxml2::XMLElement* layers = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYERS]))
 | 
			
		||||
		if (const XMLElement* layers = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYERS]))
 | 
			
		||||
		{
 | 
			
		||||
			for 
 | 
			
		||||
			(
 | 
			
		||||
				const tinyxml2::XMLElement* layer = layers->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER]);
 | 
			
		||||
				const XMLElement* layer = layers->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER]);
 | 
			
		||||
				layer; layer = layer->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_LAYER])
 | 
			
		||||
			)
 | 
			
		||||
			{
 | 
			
		||||
				Anm2Layer addLayer;
 | 
			
		||||
 | 
			
		||||
				for (const tinyxml2::XMLAttribute* attribute = layer->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				for (const XMLAttribute* attribute = layer->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				{	
 | 
			
		||||
					switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
					{
 | 
			
		||||
@@ -490,17 +491,17 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		// Nulls
 | 
			
		||||
		if (const tinyxml2::XMLElement* nulls = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULLS]))
 | 
			
		||||
		if (const XMLElement* nulls = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULLS]))
 | 
			
		||||
		{
 | 
			
		||||
			for 
 | 
			
		||||
			(
 | 
			
		||||
				const tinyxml2::XMLElement* null = nulls->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL]);
 | 
			
		||||
				const XMLElement* null = nulls->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL]);
 | 
			
		||||
				null; null = null->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_NULL])
 | 
			
		||||
			)
 | 
			
		||||
			{
 | 
			
		||||
				Anm2Null addNull;
 | 
			
		||||
 | 
			
		||||
				for (const tinyxml2::XMLAttribute* attribute = null->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				for (const XMLAttribute* attribute = null->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				{	
 | 
			
		||||
					switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
					{
 | 
			
		||||
@@ -515,18 +516,18 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Events
 | 
			
		||||
		if (const tinyxml2::XMLElement* events = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENTS]))
 | 
			
		||||
		if (const XMLElement* events = content->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENTS]))
 | 
			
		||||
		{
 | 
			
		||||
			// Event
 | 
			
		||||
			for 
 | 
			
		||||
			(
 | 
			
		||||
				const tinyxml2::XMLElement* event = events->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENT]);
 | 
			
		||||
				const XMLElement* event = events->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENT]);
 | 
			
		||||
				event; event = event->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_EVENT])
 | 
			
		||||
			)
 | 
			
		||||
			{
 | 
			
		||||
				Anm2Event addEvent;
 | 
			
		||||
 | 
			
		||||
				for (const tinyxml2::XMLAttribute* attribute = event->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				for (const XMLAttribute* attribute = event->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
				{	
 | 
			
		||||
					switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
					{
 | 
			
		||||
@@ -542,9 +543,9 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Animations
 | 
			
		||||
	if (const tinyxml2::XMLElement* animations = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATIONS]))
 | 
			
		||||
	if (const XMLElement* animations = root->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATIONS]))
 | 
			
		||||
	{
 | 
			
		||||
		for (const tinyxml2::XMLAttribute* attribute = animations->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
		for (const XMLAttribute* attribute = animations->FirstAttribute(); attribute; attribute = attribute->Next())
 | 
			
		||||
		{	
 | 
			
		||||
			switch (ANM2_ATTRIBUTE_STRING_TO_ENUM(attribute->Name()))
 | 
			
		||||
			{
 | 
			
		||||
@@ -556,7 +557,7 @@ bool anm2_deserialize(Anm2* self, const std::string& path, bool isTextures)
 | 
			
		||||
		// Animation
 | 
			
		||||
		for 
 | 
			
		||||
		(
 | 
			
		||||
			const tinyxml2::XMLElement* animation = animations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION]);
 | 
			
		||||
			const XMLElement* animation = animations->FirstChildElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION]);
 | 
			
		||||
			animation; animation = animation->NextSiblingElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION])
 | 
			
		||||
		)
 | 
			
		||||
			_anm2_animation_deserialize(&self->animations[map_next_id_get(self->animations)], animation);
 | 
			
		||||
@@ -1173,9 +1174,19 @@ vec4 anm2_animation_rect_get(Anm2* self, Anm2Reference* reference, bool isRootTr
 | 
			
		||||
    return {minX, minY, maxX - minX, maxY - minY};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void anm2_animation_serialize_to_string(Anm2Animation* animation, std::string* string)
 | 
			
		||||
{
 | 
			
		||||
	_anm2_animation_serialize(animation, nullptr, nullptr, string);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void anm2_frame_serialize_to_string(Anm2Frame* frame, Anm2Type type, std::string* string)
 | 
			
		||||
{
 | 
			
		||||
	_anm2_frame_serialize(frame, type, nullptr, nullptr, string);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool anm2_animation_deserialize_from_xml(Anm2Animation* animation, const std::string& xml)
 | 
			
		||||
{
 | 
			
		||||
	tinyxml2::XMLDocument document;
 | 
			
		||||
	XMLDocument document;
 | 
			
		||||
	
 | 
			
		||||
	auto animation_deserialize_error = [&]()
 | 
			
		||||
	{
 | 
			
		||||
@@ -1185,7 +1196,7 @@ bool anm2_animation_deserialize_from_xml(Anm2Animation* animation, const std::st
 | 
			
		||||
 | 
			
		||||
	if (document.Parse(xml.c_str()) != XML_SUCCESS) return animation_deserialize_error();
 | 
			
		||||
	
 | 
			
		||||
	const tinyxml2::XMLElement* element = document.RootElement();
 | 
			
		||||
	const XMLElement* element = document.RootElement();
 | 
			
		||||
	if (!element) return animation_deserialize_error();
 | 
			
		||||
	if (std::string(element->Name()) != std::string(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATION]))
 | 
			
		||||
		return animation_deserialize_error();
 | 
			
		||||
@@ -1196,7 +1207,7 @@ bool anm2_animation_deserialize_from_xml(Anm2Animation* animation, const std::st
 | 
			
		||||
 | 
			
		||||
bool anm2_frame_deserialize_from_xml(Anm2Frame* frame, const std::string& xml)
 | 
			
		||||
{
 | 
			
		||||
	tinyxml2::XMLDocument document;
 | 
			
		||||
	XMLDocument document;
 | 
			
		||||
	
 | 
			
		||||
	auto frame_deserialize_error = [&]()
 | 
			
		||||
	{
 | 
			
		||||
@@ -1206,7 +1217,7 @@ bool anm2_frame_deserialize_from_xml(Anm2Frame* frame, const std::string& xml)
 | 
			
		||||
 | 
			
		||||
	if (document.Parse(xml.c_str()) != XML_SUCCESS) return frame_deserialize_error();
 | 
			
		||||
 | 
			
		||||
	const tinyxml2::XMLElement* element = document.RootElement();
 | 
			
		||||
	const XMLElement* element = document.RootElement();
 | 
			
		||||
	if (!element) return frame_deserialize_error();
 | 
			
		||||
 | 
			
		||||
	if 
 | 
			
		||||
@@ -1217,5 +1228,6 @@ bool anm2_frame_deserialize_from_xml(Anm2Frame* frame, const std::string& xml)
 | 
			
		||||
		return frame_deserialize_error();
 | 
			
		||||
 | 
			
		||||
	_anm2_frame_deserialize(frame, element);
 | 
			
		||||
	
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
@@ -273,12 +273,12 @@ void anm2_animation_merge(Anm2* self, s32 animationID, const std::vector<s32>& m
 | 
			
		||||
void anm2_animation_null_animation_add(Anm2Animation* animation, s32 id);
 | 
			
		||||
void anm2_animation_null_animation_remove(Anm2Animation* animation, s32 id);
 | 
			
		||||
void anm2_animation_remove(Anm2* self, s32 id);
 | 
			
		||||
void anm2_animation_serialize(Anm2Animation* animation, tinyxml2::XMLDocument* document, tinyxml2::XMLElement* addElement, std::string* string);
 | 
			
		||||
void anm2_animation_serialize_to_string(Anm2Animation* animation, std::string* string);
 | 
			
		||||
void anm2_created_on_set(Anm2* self);
 | 
			
		||||
void anm2_frame_bake(Anm2* self, Anm2Reference* reference, s32 interval, bool isRoundScale, bool isRoundRotation);
 | 
			
		||||
void anm2_frame_from_time(Anm2* self, Anm2Frame* frame, Anm2Reference reference, f32 time);
 | 
			
		||||
void anm2_frame_remove(Anm2* self, Anm2Reference* reference);
 | 
			
		||||
void anm2_frame_serialize(Anm2Frame* frame, Anm2Type type, tinyxml2::XMLDocument* document, tinyxml2::XMLElement* addElement, std::string* string);
 | 
			
		||||
void anm2_frame_serialize_to_string(Anm2Frame* frame, Anm2Type type, std::string* string);
 | 
			
		||||
void anm2_free(Anm2* self);
 | 
			
		||||
void anm2_generate_from_grid(Anm2* self, Anm2Reference* reference, vec2 startPosition, vec2 size, vec2 pivot, s32 columns, s32 count, s32 delay);
 | 
			
		||||
void anm2_item_frame_set(Anm2* self, Anm2Reference* reference, const Anm2FrameChange& change, Anm2ChangeType type, s32 start, s32 count);
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ void clipboard_copy(Clipboard* self)
 | 
			
		||||
            if (!reference) break;
 | 
			
		||||
            Anm2Frame* frame = anm2_frame_from_reference(self->anm2, reference);
 | 
			
		||||
            if (!frame) break;
 | 
			
		||||
            anm2_frame_serialize(frame, reference->itemType, nullptr, nullptr, &clipboardText);
 | 
			
		||||
            anm2_frame_serialize_to_string(frame, reference->itemType, &clipboardText);
 | 
			
		||||
            clipboard_text_set();
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
@@ -28,7 +28,7 @@ void clipboard_copy(Clipboard* self)
 | 
			
		||||
            if (!id) break;
 | 
			
		||||
            Anm2Animation* animation = map_find(self->anm2->animations, *id);
 | 
			
		||||
            if (!animation) break;
 | 
			
		||||
            anm2_animation_serialize(animation, nullptr, nullptr, &clipboardText);
 | 
			
		||||
            anm2_animation_serialize_to_string(animation, &clipboardText);
 | 
			
		||||
            clipboard_text_set();
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user