aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-04-03 19:38:27 +0200
committer Hop311 <hop3114@gmail.com>2023-04-03 19:38:27 +0200
commitc7def7396da00b39eced666ad360397733712bfd (patch)
tree06fd1047a6193e9062c53375eeea2a8419f3cc1d /extension/src/openvic2
parent60ddfc88fd6dc259792532fadf9cc4407f90e95f (diff)
Basic province id and shape loading and rendering.
Diffstat (limited to 'extension/src/openvic2')
-rw-r--r--extension/src/openvic2/Map.cpp29
-rw-r--r--extension/src/openvic2/Map.hpp28
2 files changed, 57 insertions, 0 deletions
diff --git a/extension/src/openvic2/Map.cpp b/extension/src/openvic2/Map.cpp
new file mode 100644
index 0000000..c53b86d
--- /dev/null
+++ b/extension/src/openvic2/Map.cpp
@@ -0,0 +1,29 @@
+#include "Map.hpp"
+
+#include <sstream>
+#include <iomanip>
+
+using namespace OpenVic2;
+
+std::string Province::to_string() const {
+ std::ostringstream stream;
+ stream << "(" << identifier << ", " << std::hex << std::setfill('0') << std::setw(6) << colour << ")";
+ return stream.str();
+}
+
+bool Map::add_province(std::string const& identifier, Province::colour_t colour, std::string& error_message) {
+ Province new_province = { identifier, colour };
+ for (Province const& province : provinces) {
+ if (province.identifier == identifier) {
+ error_message = "Duplicate province identifiers: " + province.to_string() + " and " + new_province.to_string();
+ return false;
+ }
+ if (province.colour == colour) {
+ error_message = "Duplicate province colours: " + province.to_string() + " and " + new_province.to_string();
+ return false;
+ }
+ }
+ provinces.push_back(new_province);
+ error_message = "Added province: " + new_province.to_string();
+ return true;
+} \ No newline at end of file
diff --git a/extension/src/openvic2/Map.hpp b/extension/src/openvic2/Map.hpp
new file mode 100644
index 0000000..3c9c6de
--- /dev/null
+++ b/extension/src/openvic2/Map.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <string>
+#include <cstdint>
+#include <vector>
+
+namespace OpenVic2 {
+
+ struct Province {
+ using colour_t = uint32_t;
+
+ static const colour_t NULL_COLOUR = 0;
+
+ std::string identifier;
+ colour_t colour;
+
+ std::string to_string() const;
+ };
+
+ struct Map {
+ private:
+ std::vector<Province> provinces;
+
+ public:
+ bool add_province(std::string const& identifier, Province::colour_t colour, std::string& error_message);
+ };
+
+}