1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-17 07:57:45 +00:00
sapphire/src/world/Action/ActionLutData.cpp

51 lines
1,006 B
C++
Raw Normal View History

#include "ActionLut.h"
2023-01-27 05:23:13 +01:00
#include "ActionLutData.h"
#include <fstream>
#include <filesystem>
#include <iostream>
using namespace Sapphire::World::Action;
2023-01-27 05:23:13 +01:00
namespace fs = std::filesystem;
2023-01-27 05:23:13 +01:00
ActionLut::Lut ActionLut::m_actionLut;
bool ActionLutData::cacheActions()
{
std::fstream f;
for( auto& p : fs::recursive_directory_iterator( "data/actions/" ) )
{
if( p.path().extension() == ".json" )
{
f.open( p.path() );
if( !f.is_open() )
return false;
auto actionJSON = nlohmann::json::parse( f );
for( auto& i : actionJSON.items() )
{
auto id = std::stoi( i.key() );
auto action = i.value().get< ActionEntry >();
ActionLut::m_actionLut.try_emplace( id, action );
}
f.close();
f.clear();
}
}
if( ActionLut::m_actionLut.empty() )
return false;
return true;
}
bool ActionLutData::reloadActions()
{
2023-01-27 05:23:13 +01:00
if( !ActionLut::m_actionLut.empty() )
ActionLut::m_actionLut.clear();
2022-01-02 22:32:17 +01:00
2023-01-27 05:23:13 +01:00
return cacheActions();
}