#include <StorageDB.hpp>
◆ StorageDatabase()
StorageDatabase::StorageDatabase |
( |
| ) |
|
◆ ~StorageDatabase()
StorageDatabase::~StorageDatabase |
( |
| ) |
|
◆ get_instance()
56 {
58 return &instance;
59 }
StorageDatabase()
Definition: StorageDB.cpp:35
◆ get_storage_by_id()
std::shared_ptr< const storage_config_data > Horizon::Zone::StorageDatabase::get_storage_by_id |
( |
int32_t |
id | ) |
|
|
inline |
LockedLookupTable< uint32_t, std::shared_ptr< const storage_config_data > > _storage_db
Definition: StorageDB.hpp:74
References _storage_db.
◆ get_storage_db()
std::map< uint32_t, std::shared_ptr< const storage_config_data > > const Horizon::Zone::StorageDatabase::get_storage_db |
( |
| ) |
const |
|
inline |
◆ get_storage_db_size()
int32_t Horizon::Zone::StorageDatabase::get_storage_db_size |
( |
| ) |
|
|
inline |
◆ load()
bool StorageDatabase::load |
( |
| ) |
|
44{
45 sol::state lua;
46
47 int total_entries = 0;
48 std::string tmp_string;
49 std::string file_path =
sZone->config().get_static_db_path().string() +
"storage_db.lua";
50
51
52 try {
53 lua.script_file(file_path);
54 sol::table storage_tbl = lua.get<sol::table>("storage_db");
56 HLog(info) <<
"Loaded " << total_entries <<
" entries from '" << file_path <<
"'";
57 } catch(const std::exception &e) {
58 HLog(error) <<
"StorageDB::load: " << e.what();
59 return false;
60 }
61
62 return true;
63}
#define HLog(type)
Definition: Logger.hpp:122
#define sZone
Definition: Zone.hpp:247
bool load_storage(sol::table const &storage_tbl)
Definition: StorageDB.cpp:65
References HLog, load_storage(), and sZone.
◆ load_internal()
bool StorageDatabase::load_internal |
( |
sol::object const & |
key, |
|
|
sol::object const & |
value |
|
) |
| |
|
protected |
77{
79
80 if (key.is<int>()) {
82 } else {
83 HLog(error) <<
"StorageDB::load_internal: Invalid storage id '" << key.as<std::string>() <<
"', key must be numeric.";
84 return false;
85 }
86
87 if (!value.is<sol::table>()) {
88 HLog(error) <<
"StorageDB::load_internal: Invalid value type for storage id '" << config.
storage_id <<
"', value must be a table.";
89 return false;
90 }
91
92 sol::table storage_tbl = value.as<sol::table>();
93 config.
name = storage_tbl.get_or<std::string>(
"Name",
"Storage");
94 config.
capacity = storage_tbl.get_or(
"Capacity", 600);
95
97
98 return true;
99}
Definition: StorageDB.hpp:44
std::string name
Definition: StorageDB.hpp:46
int32_t storage_id
Definition: StorageDB.hpp:45
int32_t capacity
Definition: StorageDB.hpp:47
References _storage_db, Horizon::Zone::storage_config_data::capacity, HLog, Horizon::Zone::storage_config_data::name, and Horizon::Zone::storage_config_data::storage_id.
Referenced by load_storage().
◆ load_storage()
bool StorageDatabase::load_storage |
( |
sol::table const & |
storage_tbl | ) |
|
|
protected |
66{
67 int total_entries = 0;
68 for (auto &kv : storage_tbl) {
70 total_entries++;
71 }
72 }
73 return total_entries > 0;
74}
bool load_internal(sol::object const &key, sol::object const &value)
Definition: StorageDB.cpp:76
References load_internal().
Referenced by load().
◆ _storage_db
The documentation for this class was generated from the following files: