Restore minimap saving
This commit is contained in:
parent
5812a511d8
commit
356368ddae
|
@ -2,8 +2,6 @@ DEFAULT_ZOOM = 60
|
||||||
MAX_FLOOR_UP = 0
|
MAX_FLOOR_UP = 0
|
||||||
MAX_FLOOR_DOWN = 15
|
MAX_FLOOR_DOWN = 15
|
||||||
|
|
||||||
G.minimapFirstLoad = true
|
|
||||||
|
|
||||||
navigating = false
|
navigating = false
|
||||||
minimapWidget = nil
|
minimapWidget = nil
|
||||||
minimapButton = nil
|
minimapButton = nil
|
||||||
|
@ -15,8 +13,11 @@ minimapWindow = nil
|
||||||
you change floor it will not update the minimap.
|
you change floor it will not update the minimap.
|
||||||
]]
|
]]
|
||||||
function init()
|
function init()
|
||||||
connect(g_game, { onGameStart = reset,
|
connect(g_game, {
|
||||||
onForceWalk = center })
|
onGameStart = online,
|
||||||
|
onGameEnd = offline,
|
||||||
|
onForceWalk = center,
|
||||||
|
})
|
||||||
|
|
||||||
g_keyboard.bindKeyDown('Ctrl+M', toggle)
|
g_keyboard.bindKeyDown('Ctrl+M', toggle)
|
||||||
|
|
||||||
|
@ -37,29 +38,18 @@ function init()
|
||||||
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
||||||
|
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
-- load only the first time (avoid load/save between reloads)
|
|
||||||
--[[
|
|
||||||
if G.minimapFirstLoad then
|
|
||||||
G.minimapFirstLoad = false
|
|
||||||
if g_resources.fileExists('/minimap.otcm') then
|
|
||||||
if g_game.isOnline() then
|
|
||||||
perror('cannot load minimap while online')
|
|
||||||
else
|
|
||||||
g_map.loadOtcm('/minimap.otcm')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- save only when closing the client
|
|
||||||
connect(g_app, { onTerminate = function()
|
|
||||||
g_map.saveOtcm('/minimap.otcm')
|
|
||||||
end})
|
|
||||||
end]]--
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function terminate()
|
function terminate()
|
||||||
disconnect(g_game, { onGameStart = reset,
|
disconnect(g_game, {
|
||||||
onForceWalk = center })
|
onGameStart = online,
|
||||||
|
onGameEnd = offline,
|
||||||
|
onForceWalk = center,
|
||||||
|
})
|
||||||
|
|
||||||
|
if g_game.isOnline() then
|
||||||
|
saveMap()
|
||||||
|
end
|
||||||
|
|
||||||
g_keyboard.unbindKeyDown('Ctrl+M')
|
g_keyboard.unbindKeyDown('Ctrl+M')
|
||||||
|
|
||||||
|
@ -67,6 +57,28 @@ function terminate()
|
||||||
minimapWindow:destroy()
|
minimapWindow:destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function online()
|
||||||
|
reset()
|
||||||
|
loadMap()
|
||||||
|
end
|
||||||
|
|
||||||
|
function offline()
|
||||||
|
saveMap()
|
||||||
|
end
|
||||||
|
|
||||||
|
function loadMap()
|
||||||
|
local clientVersion = g_game.getClientVersion()
|
||||||
|
local minimapName = '/minimap_' .. clientVersion .. '.otcm'
|
||||||
|
g_map.clean()
|
||||||
|
g_map.loadOtcm(minimapName)
|
||||||
|
end
|
||||||
|
|
||||||
|
function saveMap()
|
||||||
|
local clientVersion = g_game.getClientVersion()
|
||||||
|
local minimapName = '/minimap_' .. clientVersion .. '.otcm'
|
||||||
|
g_map.saveOtcm(minimapName)
|
||||||
|
end
|
||||||
|
|
||||||
function toggle()
|
function toggle()
|
||||||
if minimapButton:isOn() then
|
if minimapButton:isOn() then
|
||||||
minimapWindow:close()
|
minimapWindow:close()
|
||||||
|
|
|
@ -89,6 +89,7 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_map", "getThing", &Map::getThing, &g_map);
|
g_lua.bindSingletonFunction("g_map", "getThing", &Map::getThing, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "removeThingByPos", &Map::removeThingByPos, &g_map);
|
g_lua.bindSingletonFunction("g_map", "removeThingByPos", &Map::removeThingByPos, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "removeThing", &Map::removeThing, &g_map);
|
g_lua.bindSingletonFunction("g_map", "removeThing", &Map::removeThing, &g_map);
|
||||||
|
g_lua.bindSingletonFunction("g_map", "clean", &Map::clean, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "cleanTile", &Map::cleanTile, &g_map);
|
g_lua.bindSingletonFunction("g_map", "cleanTile", &Map::cleanTile, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "cleanTexts", &Map::cleanTexts, &g_map);
|
g_lua.bindSingletonFunction("g_map", "cleanTexts", &Map::cleanTexts, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "getTile", &Map::getTile, &g_map);
|
g_lua.bindSingletonFunction("g_map", "getTile", &Map::getTile, &g_map);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
#include <framework/core/application.h>
|
#include <framework/core/application.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
@ -300,7 +300,7 @@ void Map::saveOtbm(const std::string &fileName)
|
||||||
Position base(-1, -1, -1);
|
Position base(-1, -1, -1);
|
||||||
bool firstNode = true;
|
bool firstNode = true;
|
||||||
|
|
||||||
for(uint8_t z = 0; z < Otc::MAX_Z + 1; ++z) {
|
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
|
||||||
for(const auto& it : m_tileBlocks[z]) {
|
for(const auto& it : m_tileBlocks[z]) {
|
||||||
const TileBlock& block = it.second;
|
const TileBlock& block = it.second;
|
||||||
for(const TilePtr& tile : block.getTiles()) {
|
for(const TilePtr& tile : block.getTiles()) {
|
||||||
|
@ -499,9 +499,8 @@ bool Map::loadOtcm(const std::string& fileName)
|
||||||
|
|
||||||
void Map::saveOtcm(const std::string& fileName)
|
void Map::saveOtcm(const std::string& fileName)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
try {
|
try {
|
||||||
g_clock.update();
|
stdext::timer saveTimer;
|
||||||
|
|
||||||
FileStreamPtr fin = g_resources.createFile(fileName);
|
FileStreamPtr fin = g_resources.createFile(fileName);
|
||||||
fin->cache();
|
fin->cache();
|
||||||
|
@ -527,12 +526,14 @@ void Map::saveOtcm(const std::string& fileName)
|
||||||
fin->addU16(start);
|
fin->addU16(start);
|
||||||
fin->seek(start);
|
fin->seek(start);
|
||||||
|
|
||||||
for(auto& pair : m_tiles) {
|
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
|
||||||
const TilePtr& tile = pair.second;
|
for(const auto& it : m_tileBlocks[z]) {
|
||||||
|
const TileBlock& block = it.second;
|
||||||
|
for(const TilePtr& tile : block.getTiles()) {
|
||||||
if(!tile || tile->isEmpty())
|
if(!tile || tile->isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Position pos = pair.first;
|
Position pos = tile->getPosition();
|
||||||
fin->addU16(pos.x);
|
fin->addU16(pos.x);
|
||||||
fin->addU16(pos.y);
|
fin->addU16(pos.y);
|
||||||
fin->addU8(pos.z);
|
fin->addU8(pos.z);
|
||||||
|
@ -551,6 +552,8 @@ void Map::saveOtcm(const std::string& fileName)
|
||||||
// end of tile
|
// end of tile
|
||||||
fin->addU16(0xFFFF);
|
fin->addU16(0xFFFF);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// end of file
|
// end of file
|
||||||
Position invalidPos;
|
Position invalidPos;
|
||||||
|
@ -559,9 +562,10 @@ void Map::saveOtcm(const std::string& fileName)
|
||||||
fin->addU8(invalidPos.z);
|
fin->addU8(invalidPos.z);
|
||||||
|
|
||||||
fin->flush();
|
fin->flush();
|
||||||
|
|
||||||
fin->close();
|
fin->close();
|
||||||
|
g_logger.debug(stdext::format("Otcm save time: %.2f seconds", saveTimer.elapsed_seconds()));
|
||||||
} catch(stdext::exception& e) {
|
} catch(stdext::exception& e) {
|
||||||
g_logger.error(stdext::format("failed to save OTCM map: %s", e.what()));
|
g_logger.error(stdext::format("failed to save OTCM map: %s", e.what()));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue