1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add ModStorageAPI to client side modding (#5396)

mod storage is located into user_path / client / mod_storage
This commit is contained in:
Loïc Blot 2017-03-16 07:53:39 +01:00 committed by GitHub
parent 46276414ed
commit eb88e5dd4b
8 changed files with 68 additions and 11 deletions

View file

@ -249,7 +249,8 @@ Client::Client(
m_removed_sounds_check_timer(0),
m_state(LC_Created),
m_localdb(NULL),
m_script(NULL)
m_script(NULL),
m_mod_storage_save_timer(10.0f)
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
@ -730,6 +731,18 @@ void Client::step(float dtime)
}
}
m_mod_storage_save_timer -= dtime;
if (m_mod_storage_save_timer <= 0.0f) {
verbosestream << "Saving registered mod storages." << std::endl;
m_mod_storage_save_timer = g_settings->getFloat("server_map_save_interval");
for (UNORDERED_MAP<std::string, ModMetadata *>::const_iterator
it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) {
if (it->second->isModified()) {
it->second->save(getModStoragePath());
}
}
}
// Write server map
if (m_localdb && m_localdb_save_interval.step(dtime,
m_cache_save_interval)) {
@ -1998,3 +2011,31 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
smgr->getMeshCache()->removeMesh(mesh);
return mesh;
}
bool Client::registerModStorage(ModMetadata *storage)
{
if (m_mod_storages.find(storage->getModName()) != m_mod_storages.end()) {
errorstream << "Unable to register same mod storage twice. Storage name: "
<< storage->getModName() << std::endl;
return false;
}
m_mod_storages[storage->getModName()] = storage;
return true;
}
void Client::unregisterModStorage(const std::string &name)
{
UNORDERED_MAP<std::string, ModMetadata *>::const_iterator it = m_mod_storages.find(name);
if (it != m_mod_storages.end()) {
// Save unconditionaly on unregistration
it->second->save(getModStoragePath());
m_mod_storages.erase(name);
}
}
std::string Client::getModStoragePath() const
{
return porting::path_user + DIR_DELIM + "client" + DIR_DELIM + "mod_storage";
}