2025-07-06 20:43:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include "UndoManager.hpp"
|
|
|
|
|
#include "BookmarkManager.hpp"
|
|
|
|
|
#include "ResourceManager.hpp"
|
|
|
|
|
#include "ConnectionManager.hpp"
|
|
|
|
|
#include "DrawingProgram/DrawingProgram.hpp"
|
|
|
|
|
#include "Toolbar.hpp"
|
|
|
|
|
#include "SharedTypes.hpp"
|
2025-09-06 19:06:30 +03:00
|
|
|
#include "GridManager.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
class MainProgram;
|
|
|
|
|
|
2025-08-01 20:07:47 +03:00
|
|
|
#define DEFAULT_CANVAS_BACKGROUND_COLOR Vector3f{0.12f, 0.12f, 0.12f}
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
class World {
|
|
|
|
|
public:
|
|
|
|
|
static constexpr std::string FILE_EXTENSION = "infpnt";
|
|
|
|
|
static constexpr size_t CHAT_SIZE = 10;
|
|
|
|
|
|
|
|
|
|
enum ConnectionType : int {
|
|
|
|
|
CONNECTIONTYPE_CLIENT,
|
|
|
|
|
CONNECTIONTYPE_SERVER,
|
|
|
|
|
CONNECTIONTYPE_LOCAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct OpenWorldInfo {
|
|
|
|
|
ConnectionType conType;
|
|
|
|
|
std::string fileSource;
|
|
|
|
|
std::string netSource;
|
|
|
|
|
std::string serverLocalID;
|
|
|
|
|
std::string_view fileDataBuffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
World(MainProgram& initMain, OpenWorldInfo& worldInfo);
|
|
|
|
|
|
|
|
|
|
struct SaveLoadFileOp {
|
|
|
|
|
World* world;
|
2025-08-01 20:07:47 +03:00
|
|
|
std::string versionStr;
|
2025-07-06 20:43:53 +03:00
|
|
|
void save(cereal::PortableBinaryOutputArchive& a) const;
|
|
|
|
|
void load(cereal::PortableBinaryInputArchive& a);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MainProgram& main;
|
|
|
|
|
DrawData drawData;
|
|
|
|
|
UndoManager undo;
|
|
|
|
|
ResourceManager rMan;
|
|
|
|
|
DrawingProgram drawProg;
|
|
|
|
|
BookmarkManager bMan;
|
|
|
|
|
ConnectionManager con;
|
2025-09-06 19:06:30 +03:00
|
|
|
GridManager gridMan;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
std::deque<Toolbar::ChatMessage> chatMessages;
|
|
|
|
|
|
|
|
|
|
std::string netSource;
|
|
|
|
|
|
|
|
|
|
std::string displayName;
|
|
|
|
|
|
|
|
|
|
void start_hosting(const std::string& initNetSource, const std::string& serverLocalID);
|
|
|
|
|
|
|
|
|
|
void send_chat_message(const std::string& message);
|
|
|
|
|
void add_chat_message(const std::string& message, Toolbar::ChatMessage::Color color);
|
|
|
|
|
|
|
|
|
|
WorldVec get_mouse_world_pos();
|
|
|
|
|
WorldVec get_mouse_world_move();
|
|
|
|
|
|
|
|
|
|
WorldScalar calculate_zoom_from_uniform_zoom(WorldScalar uniformZoom, WorldVec oldWindowSize);
|
|
|
|
|
|
|
|
|
|
ServerClientID get_new_id();
|
|
|
|
|
|
|
|
|
|
void focus_update();
|
|
|
|
|
void unfocus_update();
|
|
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas);
|
|
|
|
|
void early_destroy();
|
|
|
|
|
|
|
|
|
|
bool network_being_used();
|
|
|
|
|
|
|
|
|
|
ConnectionType conType;
|
|
|
|
|
bool clientStillConnecting = false;
|
|
|
|
|
|
|
|
|
|
void save_to_file(const std::filesystem::path& fileName);
|
|
|
|
|
void load_from_file(const std::filesystem::path& fileName, std::string_view buffer);
|
|
|
|
|
|
2025-07-27 20:08:46 +03:00
|
|
|
void undo_with_checks();
|
|
|
|
|
void redo_with_checks();
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
ServerPortionID ownID;
|
|
|
|
|
|
|
|
|
|
std::filesystem::path filePath;
|
|
|
|
|
Vector3f userColor = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
std::string name;
|
|
|
|
|
std::unordered_map<ServerPortionID, ClientData> clients;
|
2025-08-01 10:58:45 +03:00
|
|
|
|
2025-08-01 20:07:47 +03:00
|
|
|
void set_canvas_background_color(const Vector3f& newBackColor, bool sendChangeOverNetwork = true);
|
2025-08-01 10:58:45 +03:00
|
|
|
|
|
|
|
|
struct CanvasTheme {
|
2025-08-01 20:07:47 +03:00
|
|
|
SkColor4f backColor;
|
|
|
|
|
SkColor4f toolFrontColor;
|
2025-08-01 10:58:45 +03:00
|
|
|
} canvasTheme;
|
|
|
|
|
|
2025-09-30 11:45:03 +03:00
|
|
|
void scale_up(const WorldScalar& scaleUpAmount);
|
2025-09-30 16:36:09 +03:00
|
|
|
void scale_up_step();
|
|
|
|
|
|
|
|
|
|
uint64_t canvasScale = 0;
|
2025-07-06 20:43:53 +03:00
|
|
|
private:
|
2025-09-30 11:45:03 +03:00
|
|
|
|
2025-09-24 16:18:20 +03:00
|
|
|
ClientPortionID get_max_id(ServerPortionID serverID);
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
void init_client_callbacks();
|
|
|
|
|
void set_name(const std::string& n);
|
|
|
|
|
|
2025-09-06 19:06:30 +03:00
|
|
|
void draw_other_player_cursors(SkCanvas* canvas, const DrawData& drawData);
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
ClientPortionID nextClientID = 0;
|
|
|
|
|
WorldVec mousePreviousWorldVec = {0, 0};
|
|
|
|
|
WorldVec mouseWorldMove = {0, 0};
|
|
|
|
|
};
|