<commit_before>#include "Application.h"
#include "ComponentMaterial.h"
#include "GameObject.h"
#include "imgui\imgui.h"
#include "Data.h"
#include "ResourceFileTexture.h"
#include "Assets.h"
#include "ResourceFileMaterial.h"
#include "ResourceFileRenderTexture.h"

ComponentMaterial::ComponentMaterial(ComponentType type, GameObject* game_object) : Component(type, game_object)
{}

ComponentMaterial::~ComponentMaterial()
{
	CleanUp();
}

void ComponentMaterial::OnInspector()
{
	if (ImGui::CollapsingHeader("Material", &alive, ImGuiTreeNodeFlags_DefaultOpen))
	{
		if (material_path.size() == 0)
		{
			ImGui::Text("Material: Default material");

			for (map<string, uint>::iterator it = texture_ids.begin(); it != texture_ids.end(); it++)
			{
				ImGui::Text("%s", (*it).first.data());
				ImGui::Image((ImTextureID)(*it).second, ImVec2(50, 50));
			}
		}
		else
		{
			ImGui::Text("Material: %s", material_name.data());
			PrintMaterialProperties();
		}


		if (ImGui::Button("Change material"))
		{
			change_material_enabled = true;
		}

		if (change_material_enabled)
		{
			if (ImGui::BeginMenu("Select a material"))
			{
				vector<string> materials;
				App->editor->assets->GetAllFilesByType(FileType::MATERIAL, materials);

				for (vector<string>::iterator it = materials.begin(); it != materials.end(); ++it)
				{
					if (ImGui::MenuItem((*it).data()))
					{
						CleanUp();

						change_material_enabled = false;
						material_name = (*it).data();
						if (rc_material)
						{
							rc_material->Unload();
						}
						material_path = App->resource_manager->FindFile(material_name);
						rc_material = (ResourceFileMaterial*)App->resource_manager->LoadResource(material_path, ResourceFileType::RES_MATERIAL);
						for (vector<Uniform*>::iterator uni = rc_material->material.uniforms.begin(); uni != rc_material->material.uniforms.end(); ++uni)
						{
							if ((*uni)->type == UniformType::U_SAMPLER2D)
							{
								string texture_path;
								int name_size = *reinterpret_cast<int*>((*uni)->value);
								texture_path.resize(name_size);
								memcpy(texture_path._Myptr(), (*uni)->value + sizeof(int), name_size);

								ResourceFileType type = App->resource_manager->GetResourceType(texture_path.data());

								if (type == ResourceFileType::RES_TEXTURE)
								{
									ResourceFileTexture* rc_tmp = (ResourceFileTexture*)App->resource_manager->LoadResource(texture_path, ResourceFileType::RES_TEXTURE);
									tex_resources.push_back(rc_tmp);
									texture_ids.insert(pair<string, uint>((*uni)->name.data(), rc_tmp->GetTexture()));
								}
								else
								{
									ResourceFileRenderTexture* rc_rndtx = (ResourceFileRenderTexture*)App->resource_manager->LoadResource(texture_path, ResourceFileType::RES_RENDER_TEX);
									tex_resources.push_back(rc_rndtx);
									texture_ids.insert(pair<string, uint>((*uni)->name.data(), rc_rndtx->GetTexture()));
								}
							}
						}
					}
				}
				ImGui::EndMenu();
			}
		}
	}
	else
		Remove();
}

void ComponentMaterial::Update()
{

	
}

void ComponentMaterial::Save(Data & file)const
{
	Data data;
	data.AppendInt("type", type);
	data.AppendUInt("UUID", uuid);
	data.AppendBool("active", active);
	data.AppendString("path", material_path.data());

	if (material_path.size() == 0)
	{
		data.AppendArray("textures");
		for (vector<string>::const_iterator it = list_textures_paths.begin(); it != list_textures_paths.end(); it++)
		{
			Data texture;
			texture.AppendString("path", (*it).data());
			data.AppendArrayValue(texture);
		}
	}

	file.AppendArrayValue(data);<commit_msg>Removed button OnChange Material<commit_after>#include "Application.h"
#include "ComponentMaterial.h"
#include "GameObject.h"
#include "imgui\imgui.h"
#include "Data.h"
#include "ResourceFileTexture.h"
#include "Assets.h"
#include "ResourceFileMaterial.h"
#include "ResourceFileRenderTexture.h"

ComponentMaterial::ComponentMaterial(ComponentType type, GameObject* game_object) : Component(type, game_object)
{}

ComponentMaterial::~ComponentMaterial()
{
	CleanUp();
}

void ComponentMaterial::OnInspector()
{
	if (ImGui::CollapsingHeader("Material", &alive, ImGuiTreeNodeFlags_DefaultOpen))
	{
		if (material_path.size() == 0)
		{
			ImGui::Text("Material: Default material");

			for (map<string, uint>::iterator it = texture_ids.begin(); it != texture_ids.end(); it++)
			{
				ImGui::Text("%s", (*it).first.data());
				ImGui::Image((ImTextureID)(*it).second, ImVec2(50, 50));
			}
		}
		else
		{
			ImGui::Text("Material: %s", material_name.data());
			PrintMaterialProperties();
		}

		if (ImGui::BeginMenu("Select a material"))
		{
			vector<string> materials;
			App->editor->assets->GetAllFilesByType(FileType::MATERIAL, materials);

			for (vector<string>::iterator it = materials.begin(); it != materials.end(); ++it)
			{
				if (ImGui::MenuItem((*it).data()))
				{
					CleanUp();

					change_material_enabled = false;
					material_name = (*it).data();
					if (rc_material)
					{
						rc_material->Unload();
					}
					material_path = App->resource_manager->FindFile(material_name);
					rc_material = (ResourceFileMaterial*)App->resource_manager->LoadResource(material_path, ResourceFileType::RES_MATERIAL);
					for (vector<Uniform*>::iterator uni = rc_material->material.uniforms.begin(); uni != rc_material->material.uniforms.end(); ++uni)
					{
						if ((*uni)->type == UniformType::U_SAMPLER2D)
						{
							string texture_path;
							int name_size = *reinterpret_cast<int*>((*uni)->value);
							texture_path.resize(name_size);
							memcpy(texture_path._Myptr(), (*uni)->value + sizeof(int), name_size);

							ResourceFileType type = App->resource_manager->GetResourceType(texture_path.data());

							if (type == ResourceFileType::RES_TEXTURE)
							{
								ResourceFileTexture* rc_tmp = (ResourceFileTexture*)App->resource_manager->LoadResource(texture_path, ResourceFileType::RES_TEXTURE);
								tex_resources.push_back(rc_tmp);
								texture_ids.insert(pair<string, uint>((*uni)->name.data(), rc_tmp->GetTexture()));
							}
							else
							{
								ResourceFileRenderTexture* rc_rndtx = (ResourceFileRenderTexture*)App->resource_manager->LoadResource(texture_path, ResourceFileType::RES_RENDER_TEX);
								tex_resources.push_back(rc_rndtx);
								texture_ids.insert(pair<string, uint>((*uni)->name.data(), rc_rndtx->GetTexture()));
							}
						}
					}
				}
			}
			ImGui::EndMenu();
		}

	}
	else
		Remove();
}

void ComponentMaterial::Update()
{

	
}

void ComponentMaterial::Save(Data & file)const
{
	Data data;
	data.AppendInt("type", type);
	data.AppendUInt("UUID", uuid);
	data.AppendBool("active", active);
	data.AppendString("path", material_path.data());

	if (material_path.size() == 0)
	{
		data.AppendArray("textures");
		for (vector<string>::const_iterator it = list_textures_paths.begin(); it != list_textures_paths.end(); it++)
		{
			Data texture;
			texture.AppendString("path", (*it).data());
			data.AppendArrayValue(texture);
		}
	}

	file.AppendArrayValue(data);
{'fraction_non_alphanumeric': 0.16164772727272728, 'fraction_numerical': 0.0022727272727272726, 'mean_word_length': 4.350303951367781, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 65, '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': '4186975', 'n_tokens_mistral': 2791, 'n_tokens_neox': 2227, 'n_words': 337}