<commit_before>#include "PackAnimation.h"
#include "PackNodeFactory.h"
#include "PackAnchor.h"
#include "PackClipbox.h"
#include "Utility.h"
#include "typedef.h"

#include "AnimToLuaString.h"
#include "AnimFromLua.h"

#include "AnimToBin.h"
#include "AnimFromBin.h"

#include <ee/Sprite.h>
#include <ee/SymbolFile.h>
#include <ee/ImageSprite.h>
#include <ee/SymbolFile.h>

#include <sprite2/SymType.h>
#include <sprite2/RenderColor.h>
#include <sprite2/RenderShader.h>
#include <sprite2/RenderCamera.h>
#include <sprite2/RenderFilter.h>
#include <gum/trans_color.h>

namespace erespacker
{

PackAnimation::PackAnimation(int id)
	: IPackNode(id)
{
}

void PackAnimation::PackToLuaString(ebuilder::CodeGenerator& gen, 
									const ee::TexturePacker& tp,
									float scale) const
{
	AnimToLuaString::Pack(this, gen);
}

void PackAnimation::UnpackFromLua(lua_State* L, const std::vector<ee::Image*>& images)
{
	AnimFromLua::Unpack(L, this);
}

int PackAnimation::SizeOfPackToBin() const
{
	return AnimToBin::Size(this);
}

void PackAnimation::PackToBin(uint8_t** ptr, 
							  const ee::TexturePacker& tp,
							  float scale) const
{
	AnimToBin::Pack(this, ptr);
}

int PackAnimation::SizeOfUnpackFromBin() const
{
	return AnimFromBin::Size(this);
}

void PackAnimation::UnpackFromBin(uint8_t** ptr, const std::vector<ee::Image*>& images)
{
	AnimFromBin::Unpack(ptr, this);
}

bool PackAnimation::CreateFramePart(const ee::Sprite* spr, Frame& frame)
{	
	const IPackNode* node = PackNodeFactory::Instance()->Create(spr);

	PackAnimation::Part part;
	std::string name = "";
	if (Utility::IsNameValid(spr->GetName())) {
		name = spr->GetName();
	}

	bool force_mat = false;
	bool new_comp = AddComponent(node, name, part.comp_idx, force_mat);
	PackAnimation::LoadSprTrans(spr, part.t, force_mat);

	frame.parts.push_back(part);

	return new_comp;
}

void PackAnimation::CreateClipboxFramePart(const PackClipbox* cb, Frame& frame)
{
	PackAnimation::Part part;

	bool force_mat;
	AddComponent(cb, "", part.comp_idx, force_mat);

	part.t.mat[0] = part.t.mat[3] = 1024;
	part.t.mat[1] = part.t.mat[2] = 0;
	part.t.mat[4] = static_cast<int>(cb->x * SCALE);
	part.t.mat[5] =-static_cast<int>(cb->y * SCALE);

	frame.parts.push_back(part);
}

void PackAnimation::Clear()
{
	export_name.clear();
	components.clear();
	actions.clear();
	frames.clear();
}

bool PackAnimation::AddComponent(const IPackNode* node, const std::string& name, int& comp_idx, bool& force_mat)
{
	bool new_comp = false;
	bool is_anchor = false;
	if (const PackAnchor* anchor = dynamic_cast<const PackAnchor*>(node)) {
		is_anchor = true;
		for (int i = 0, n = components.size(); i < n; ++i) {
			if (dynamic_cast<const PackAnchor*>(components[i].node) && components[i].name == name) {
				comp_idx = i;
				force_mat = true;
				return new_comp;
			}
		}
	} else {
		for (int i = 0, n = components.size(); i < n; ++i) {
			if (components[i].node == node && components[i].name == name) {
				comp_idx = i;
				force_mat = true;
				return new_comp;
			}
		}

		for (int i = 0, n = components.size(); i < n; ++i) {
			if (components[i].node->GetFilepath() == node->GetFilepath() 
				&& components[i].name == name
				&& !name.empty()) 
			{
				int type = ee::SymbolFile::Instance()->Type(node->GetFilepath());
				switch (type)
				{
				case s2::SYM_IMAGE:
					comp_idx = i;
					force_mat = false;
					return new_comp;
				case s2::SYM_COMPLEX: case s2::SYM_ANIMATION: case s2::SYM_TEXTBOX:
					comp_idx = i;
					force_mat = true;
					return new_comp;
				}
			}
		}
	}

	Component comp;
	comp.node = node;
	comp.name = name;
	components.push_back(comp);
	comp_idx = components.size() - 1;

	new_comp = true;

	if (is_anchor) {
		force_mat = true;
	} else if (ee::SymbolFile::Instance()->Type(node->GetFilepath()) == s2::SYM_IMAGE) {
		force_mat = false;
	} else {
		force_mat = !name.empty();
	}

	return new_comp;
}

void PackAnimation::LoadSprTrans(const ee::Sprite* spr, SpriteTrans& trans, bool force_mat)
{
	LoadSprMat(spr, trans, force_mat);<commit_msg>[FIXED] pack animation<commit_after>#include "PackAnimation.h"
#include "PackNodeFactory.h"
#include "PackAnchor.h"
#include "PackClipbox.h"
#include "Utility.h"
#include "typedef.h"

#include "AnimToLuaString.h"
#include "AnimFromLua.h"

#include "AnimToBin.h"
#include "AnimFromBin.h"

#include <ee/Sprite.h>
#include <ee/SymbolFile.h>
#include <ee/ImageSprite.h>
#include <ee/SymbolFile.h>

#include <sprite2/SymType.h>
#include <sprite2/RenderColor.h>
#include <sprite2/RenderShader.h>
#include <sprite2/RenderCamera.h>
#include <sprite2/RenderFilter.h>
#include <gum/trans_color.h>

namespace erespacker
{

PackAnimation::PackAnimation(int id)
	: IPackNode(id)
{
}

void PackAnimation::PackToLuaString(ebuilder::CodeGenerator& gen, 
									const ee::TexturePacker& tp,
									float scale) const
{
	AnimToLuaString::Pack(this, gen);
}

void PackAnimation::UnpackFromLua(lua_State* L, const std::vector<ee::Image*>& images)
{
	AnimFromLua::Unpack(L, this);
}

int PackAnimation::SizeOfPackToBin() const
{
	return AnimToBin::Size(this);
}

void PackAnimation::PackToBin(uint8_t** ptr, 
							  const ee::TexturePacker& tp,
							  float scale) const
{
	AnimToBin::Pack(this, ptr);
}

int PackAnimation::SizeOfUnpackFromBin() const
{
	return AnimFromBin::Size(this);
}

void PackAnimation::UnpackFromBin(uint8_t** ptr, const std::vector<ee::Image*>& images)
{
	AnimFromBin::Unpack(ptr, this);
}

bool PackAnimation::CreateFramePart(const ee::Sprite* spr, Frame& frame)
{	
	const IPackNode* node = PackNodeFactory::Instance()->Create(spr);

	PackAnimation::Part part;
	std::string name = "";
	if (Utility::IsNameValid(spr->GetName())) {
		name = spr->GetName();
	}

	bool force_mat = false;
	bool new_comp = AddComponent(node, name, part.comp_idx, force_mat);
	PackAnimation::LoadSprTrans(spr, part.t, force_mat);

	frame.parts.push_back(part);

	return new_comp;
}

void PackAnimation::CreateClipboxFramePart(const PackClipbox* cb, Frame& frame)
{
	PackAnimation::Part part;

	bool force_mat;
	AddComponent(cb, "", part.comp_idx, force_mat);

	part.t.mat[0] = part.t.mat[3] = 1024;
	part.t.mat[1] = part.t.mat[2] = 0;
	part.t.mat[4] = static_cast<int>(cb->x * SCALE);
	part.t.mat[5] =-static_cast<int>(cb->y * SCALE);

	frame.parts.push_back(part);
}

void PackAnimation::Clear()
{
	export_name.clear();
	components.clear();
	actions.clear();
	frames.clear();
}

bool PackAnimation::AddComponent(const IPackNode* node, const std::string& name, int& comp_idx, bool& force_mat)
{
	bool new_comp = false;
	bool is_anchor = false;
	if (const PackAnchor* anchor = dynamic_cast<const PackAnchor*>(node)) {
		is_anchor = true;
		for (int i = 0, n = components.size(); i < n; ++i) {
			if (dynamic_cast<const PackAnchor*>(components[i].node) && components[i].name == name) {
				comp_idx = i;
				force_mat = true;
				return new_comp;
			}
		}
	} else {
		for (int i = 0, n = components.size(); i < n; ++i) {
			if (components[i].node == node && components[i].name == name) {
				comp_idx = i;
				force_mat = true;
				return new_comp;
			}
		}

		for (int i = 0, n = components.size(); i < n; ++i) {
			if (components[i].node->GetFilepath() == node->GetFilepath() 
				&& components[i].name == name
				&& !name.empty()) 
			{
				int type = ee::SymbolFile::Instance()->Type(node->GetFilepath());
				switch (type)
				{
				case s2::SYM_IMAGE:
					comp_idx = i;
					force_mat = false;
					return new_comp;
				case s2::SYM_COMPLEX: case s2::SYM_ANIMATION: case s2::SYM_TEXTBOX: case s2::SYM_MASK: case s2::SYM_PARTICLE3D:
					comp_idx = i;
					force_mat = true;
					return new_comp;
				}
			}
		}
	}

	Component comp;
	comp.node = node;
	comp.name = name;
	components.push_back(comp);
	comp_idx = components.size() - 1;

	new_comp = true;

	if (is_anchor) {
		force_mat = true;
	} else if (ee::SymbolFile::Instance()->Type(node->GetFilepath()) == s2::SYM_IMAGE) {
		force_mat = false;
	} else {
		force_mat = !name.empty();
	}

	return new_comp;
}

void PackAnimation::LoadSprTrans(const ee::Sprite* spr, SpriteTrans& trans, bool force_mat)
{
	LoadSprMat(spr, trans, force_mat);
{'fraction_non_alphanumeric': 0.16102425212359966, 'fraction_numerical': 0.007017111904468792, 'mean_word_length': 4.522773623385452, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6338225', 'n_tokens_mistral': 3342, 'n_tokens_neox': 3066, 'n_words': 609}