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 17:23:05 +03:00
|
|
|
world(w) {}
|
|
|
|
|
|
|
|
|
|
void GridManager::init() {
|
|
|
|
|
if(world.netObjMan.is_server())
|
|
|
|
|
grids = world.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);
|
2025-12-11 16:05:41 +03:00
|
|
|
grids->emplace_back_direct(grids, g);
|
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) {
|
2025-12-11 16:05:41 +03:00
|
|
|
if(grids)
|
|
|
|
|
grids->erase(grids, indexToRemove);
|
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++) {
|
2025-12-13 13:03:27 +03:00
|
|
|
auto& g = grids->at(i)->obj;
|
|
|
|
|
if(!g->displayInFront)
|
|
|
|
|
g->draw(*this, canvas, drawData);
|
2025-12-10 13:06:45 +03:00
|
|
|
}
|
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++) {
|
2025-12-13 13:03:27 +03:00
|
|
|
auto& g = grids->at(i)->obj;
|
|
|
|
|
if(g->displayInFront)
|
|
|
|
|
g->draw(*this, canvas, drawData);
|
2025-12-10 13:06:45 +03:00
|
|
|
}
|
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++) {
|
2025-12-13 13:03:27 +03:00
|
|
|
auto& g = grids->at(i)->obj;
|
2025-12-10 13:06:45 +03:00
|
|
|
if(g->coordinatesWillBeDrawn && g->coordinatesAxisOnBounds) {
|
|
|
|
|
g->draw_coordinates(canvas, drawData, axisOffset);
|
|
|
|
|
g->coordinatesWillBeDrawn = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(uint32_t i = 0; i < grids->size(); i++) {
|
2025-12-13 13:03:27 +03:00
|
|
|
auto& g = grids->at(i)->obj;
|
2025-12-10 13:06:45 +03:00
|
|
|
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) {
|
2025-12-13 13:03:27 +03:00
|
|
|
for(uint32_t i = 0; i < grids->size(); i++)
|
|
|
|
|
grids->at(i)->obj->scale_up(scaleUpAmount);
|
2025-09-30 11:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|