2019-06-02 00:34:07 +10:00
|
|
|
#include "ActionLut.h"
|
2023-01-27 05:23:13 +01:00
|
|
|
#include "ActionLutData.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
2019-06-02 00:34:07 +10:00
|
|
|
|
|
|
|
using namespace Sapphire::World::Action;
|
2023-01-27 05:23:13 +01:00
|
|
|
namespace fs = std::filesystem;
|
2019-06-02 00:34:07 +10:00
|
|
|
|
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()
|
2022-01-20 20:14:34 -03:00
|
|
|
{
|
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();
|
|
|
|
}
|