2025-07-06 20:43:53 +03:00
|
|
|
#include "GridManager.hpp"
|
2025-12-10 13:06:45 +03:00
|
|
|
#include "Helpers/Networking/NetLibrary.hpp"
|
2025-09-24 16:18:20 +03:00
|
|
|
#include "Server/CommandList.hpp"
|
2025-09-24 13:32:50 +03:00
|
|
|
#include "SharedTypes.hpp"
|
2025-09-16 16:44:33 +03:00
|
|
|
#include "World.hpp"
|
2025-09-17 17:17:43 +03:00
|
|
|
#include "MainProgram.hpp"
|
2025-09-24 13:32:50 +03:00
|
|
|
#include <algorithm>
|
2025-07-06 20:43:53 +03:00
|
|
|
|
2025-09-06 19:06:30 +03:00
|
|
|
GridManager::GridManager(World& w):
|
2025-12-10 13:06:45 +03:00
|
|
|
world(w) {
|
|
|
|
|
if(w.netObjMan.is_server())
|
|
|
|
|
grids = w.netObjMan.make_obj<NetworkingObjects::NetObjOrderedList<WorldGrid>>();
|
2025-08-01 10:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
2025-12-10 13:06:45 +03:00
|
|
|
void GridManager::add_default_grid(const std::string& newName) {
|
|
|
|
|
if(grids) {
|
|
|
|
|
WorldGrid g;
|
|
|
|
|
g.name = newName;
|
|
|
|
|
g.color = color_mul_alpha(convert_vec4<Vector4f>(world.canvasTheme.toolFrontColor), 0.4f);
|
|
|
|
|
g.size = world.drawData.cam.c.inverseScale * WorldScalar(WorldGrid::GRID_UNIT_PIXEL_SIZE);
|
|
|
|
|
g.offset = world.drawData.cam.c.pos + world.drawData.cam.c.dir_from_space(world.main.window.size.cast<float>() * 0.5f);
|
|
|
|
|
NetworkingObjects::NetObjPtr<WorldGrid> gridPtr = grids->emplace_back_direct(grids, g);
|
|
|
|
|
|
|
|
|
|
uint32_t pos = grids->size() - 1;
|
|
|
|
|
world.undo.push({[&grids = grids, gridPtr](){
|
|
|
|
|
grids->erase(grids, gridPtr);
|
2025-11-16 12:40:56 +03:00
|
|
|
return true;
|
|
|
|
|
},
|
2025-12-10 13:06:45 +03:00
|
|
|
[&grids = grids, gridPtr, pos]() {
|
|
|
|
|
grids->insert_and_send_create(grids, pos, gridPtr);
|
2025-11-16 12:40:56 +03:00
|
|
|
return true;
|
|
|
|
|
}});
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
2025-09-06 19:06:30 +03:00
|
|
|
}
|
2025-07-06 20:43:53 +03:00
|
|
|
|
2025-12-10 13:06:45 +03:00
|
|
|
void GridManager::remove_grid(uint32_t indexToRemove) {
|
|
|
|
|
if(grids) {
|
|
|
|
|
NetworkingObjects::NetObjPtr<WorldGrid> gridPtr = grids->erase(grids, indexToRemove);
|
|
|
|
|
world.undo.push({[&grids = grids, gridPtr, indexToRemove]() {
|
|
|
|
|
grids->insert_and_send_create(grids, indexToRemove, gridPtr);
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&grids = grids, gridPtr](){
|
|
|
|
|
grids->erase(grids, gridPtr);
|
|
|
|
|
return true;
|
|
|
|
|
}});
|
2025-09-24 16:18:20 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 21:31:16 +03:00
|
|
|
void GridManager::draw_back(SkCanvas* canvas, const DrawData& drawData) {
|
2025-12-10 13:06:45 +03:00
|
|
|
if(grids) {
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
|
|
|
|
if(!grids->at(i)->displayInFront)
|
|
|
|
|
grids->at(i)->draw(*this, canvas, drawData);
|
|
|
|
|
}
|
2025-10-01 21:31:16 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GridManager::draw_front(SkCanvas* canvas, const DrawData& drawData) {
|
2025-12-10 13:06:45 +03:00
|
|
|
if(grids) {
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
|
|
|
|
if(grids->at(i)->displayInFront)
|
|
|
|
|
grids->at(i)->draw(*this, canvas, drawData);
|
|
|
|
|
}
|
2025-10-01 21:31:16 +03:00
|
|
|
}
|
2025-09-25 10:21:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GridManager::draw_coordinates(SkCanvas* canvas, const DrawData& drawData) {
|
2025-12-10 13:06:45 +03:00
|
|
|
if(grids) {
|
|
|
|
|
Vector2f axisOffset{0.0f, 0.0f};
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
|
|
|
|
auto& g = grids->at(i);
|
|
|
|
|
if(g->coordinatesWillBeDrawn && g->coordinatesAxisOnBounds) {
|
|
|
|
|
g->draw_coordinates(canvas, drawData, axisOffset);
|
|
|
|
|
g->coordinatesWillBeDrawn = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
|
|
|
|
auto& g = grids->at(i);
|
|
|
|
|
if(g->coordinatesWillBeDrawn && !g->coordinatesAxisOnBounds)
|
|
|
|
|
g->draw_coordinates(canvas, drawData, axisOffset);
|
|
|
|
|
g->coordinatesWillBeDrawn = false;
|
2025-09-25 10:21:47 +03:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
2025-09-30 11:45:03 +03:00
|
|
|
|
|
|
|
|
void GridManager::scale_up(const WorldScalar& scaleUpAmount) {
|
2025-12-10 13:06:45 +03:00
|
|
|
if(grids) {
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
|
|
|
|
grids->at(i)->scale_up(scaleUpAmount);
|
|
|
|
|
}
|
2025-09-30 11:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|