<commit_before>///
/// World.cpp
/// starlight
///
/// Created by reworks on 09/07/2016.
/// MIT License.
/// Refer to LICENSE.txt for more details.
///

#include <map>

#include "sol2/sol.hpp"
#include "sl/fs/VFS.hpp"
#include "loguru/loguru.hpp"

#include "World.hpp"

namespace sl
{
	void World::createEntity(const std::string& script)
	{
		sol::state lua;
		lua.script(VFS::inst()->openAsString(script));
		
		entt::Entity entity = m_registry.create();
		sol::table components = lua.get<sol::table>("entity");

		std::map<entt::HashedString::hash_type, sol::table> kvp;
		components.for_each([&](std::pair<sol::object, sol::object> pair)
		{
			kvp.insert({ pair.first.as<entt::HashedString>(), pair.second.as<sol::table>() });
		});

		if (components.get<bool>("hasTags"))
		{
			sol::table tags = components.get<sol::table>("tags");

			std::map<int, entt::HashedString::hash_type> tagsKVP;
			tags.for_each([&](std::pair<sol::object, sol::object> pair)
			{
				tagsKVP.insert({ pair.first.as<int>(), pair.second.as<entt::HashedString>() });
			});

			for (auto& it : tagsKVP)
			{
				m_tagAssign[it.second](entity);
			}

			kvp.erase(entt::HashedString{ "hasTags" });
		}

		kvp.erase(entt::HashedString{ "hasTags" });

		for (auto& it : kvp)
		{
			m_componentAssign[it.first](entity, it.second);
		}
	}

	void World::createEntities(const std::string& batchScript)
	{	
		sol::state lua;
		lua.script(VFS::inst()->openAsString(batchScript));

		sol::table world = lua.get<sol::table>("world");
		sol::table entityList = world.get<sol::table>("entitys");
		entityList.for_each([&](std::pair<sol::object, sol::object> pair)
		{
			createEntity(pair.second.as<std::string>());
		});
	}

	void World::event(ALLEGRO_EVENT* event)
	{
		for (auto& system : m_systems)
		{
			system.second->event(event);
		}
	}

	void World::update(const double dt)
	{
		m_currentLevel->update(dt);

		for (auto& system : m_systems)
		{
			system.second->update(dt, m_registry);
		}
	}
}<commit_msg>woops<commit_after>///
/// World.cpp
/// starlight
///
/// Created by reworks on 09/07/2016.
/// MIT License.
/// Refer to LICENSE.txt for more details.
///

#include <map>

#include "sol2/sol.hpp"
#include "sl/fs/VFS.hpp"
#include "loguru/loguru.hpp"

#include "World.hpp"

namespace sl
{
	void World::createEntity(const std::string& script)
	{
		sol::state lua;
		lua.script(VFS::inst()->openAsString(script));
		
		entt::Entity entity = m_registry.create();
		sol::table components = lua.get<sol::table>("entity");

		std::map<entt::HashedString::hash_type, sol::table> kvp;
		components.for_each([&](std::pair<sol::object, sol::object> pair)
		{
			kvp.insert({ pair.first.as<entt::HashedString>(), pair.second.as<sol::table>() });
		});

		if (components.get<bool>("hasTags"))
		{
			sol::table tags = components.get<sol::table>("tags");

			std::map<int, entt::HashedString::hash_type> tagsKVP;
			tags.for_each([&](std::pair<sol::object, sol::object> pair)
			{
				tagsKVP.insert({ pair.first.as<int>(), pair.second.as<entt::HashedString>() });
			});

			for (auto& it : tagsKVP)
			{
				m_tagAssign[it.second](entity);
			}

			kvp.erase(entt::HashedString{ "hasTags" });
		}

		kvp.erase(entt::HashedString{ "hasTags" });

		for (auto& it : kvp)
		{
			m_componentAssign[it.first](entity, it.second);
		}
	}

	void World::createEntities(const std::string& batchScript)
	{	
		sol::state lua;
		lua.script(VFS::inst()->openAsString(batchScript));

		sol::table world = lua.get<sol::table>("world");
		sol::table entityList = world.get<sol::table>("entitys");
		entityList.for_each([&](std::pair<sol::object, sol::object> pair)
		{
			createEntity(pair.second.as<std::string>());
		});
	}

	void World::event(ALLEGRO_EVENT* event)
	{
		for (auto& system : m_systems)
		{
			system.second->event(event, m_registry);
		}
	}

	void World::update(const double dt)
	{
		m_currentLevel->update(dt);

		for (auto& system : m_systems)
		{
			system.second->update(dt, m_registry);
		}
	}
}
{'fraction_non_alphanumeric': 0.2029678068410463, 'fraction_numerical': 0.004527162977867203, 'mean_word_length': 4.302666666666667, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, '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': '7229902', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1498, 'n_words': 231}