Grids can be saved in files and used online
This commit is contained in:
parent
0c0d7d8439
commit
52de64907a
14 changed files with 122 additions and 42 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "GridManager.hpp"
|
||||
#include "Server/CommandList.hpp"
|
||||
#include "SharedTypes.hpp"
|
||||
#include "World.hpp"
|
||||
#include "MainProgram.hpp"
|
||||
|
|
@ -8,6 +9,19 @@ GridManager::GridManager(World& w):
|
|||
world(w) {}
|
||||
|
||||
void GridManager::init_client_callbacks() {
|
||||
world.con.client_add_recv_callback(CLIENT_SET_GRID, [&](cereal::PortableBinaryInputArchive& message) {
|
||||
ServerClientID gID;
|
||||
message(gID);
|
||||
auto& g = grids[gID];
|
||||
message(g);
|
||||
changed = true;
|
||||
});
|
||||
world.con.client_add_recv_callback(CLIENT_REMOVE_GRID, [&](cereal::PortableBinaryInputArchive& message) {
|
||||
ServerClientID gID;
|
||||
message(gID);
|
||||
grids.erase(gID);
|
||||
changed = true;
|
||||
});
|
||||
}
|
||||
|
||||
ServerClientID GridManager::add_default_grid(const std::string& newName) {
|
||||
|
|
@ -22,8 +36,17 @@ ServerClientID GridManager::add_default_grid(const std::string& newName) {
|
|||
return newID;
|
||||
}
|
||||
|
||||
void GridManager::send_grid_info(ServerClientID gridID) {
|
||||
auto gridFoundIt = grids.find(gridID);
|
||||
if(gridFoundIt != grids.end()) {
|
||||
WorldGrid& g = gridFoundIt->second;
|
||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_SET_GRID, gridID, g);
|
||||
}
|
||||
}
|
||||
|
||||
void GridManager::remove_grid(ServerClientID idToRemove) {
|
||||
grids.erase(idToRemove);
|
||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_REMOVE_GRID, idToRemove);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +66,15 @@ const std::vector<ServerClientID>& GridManager::sorted_grid_ids() {
|
|||
return sortedGridIDs;
|
||||
}
|
||||
|
||||
ClientPortionID GridManager::get_max_id(ServerPortionID serverID) const {
|
||||
ClientPortionID maxClientID = 0;
|
||||
for(auto& p : grids) {
|
||||
if(p.first.first == serverID)
|
||||
maxClientID = std::max(maxClientID, p.first.second);
|
||||
}
|
||||
return maxClientID;
|
||||
}
|
||||
|
||||
void GridManager::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
for(auto& [str, g] : grids)
|
||||
g.draw(*this, canvas, drawData);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue