summaryrefslogtreecommitdiffhomepage
path: root/Icons.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-21 21:17:27 +0200
committerAki <please@ignore.pl>2022-05-21 21:17:27 +0200
commit3e8ebf3133ece10efc8cf9219dafc02e780bc3ab (patch)
treee5427ceac77f2bf8939a56940e081fa07e4e6246 /Icons.cpp
parent5ea4d9d4c2f9c99fc5773a2ba91c470078368165 (diff)
downloadderelict-3e8ebf3133ece10efc8cf9219dafc02e780bc3ab.zip
derelict-3e8ebf3133ece10efc8cf9219dafc02e780bc3ab.tar.gz
derelict-3e8ebf3133ece10efc8cf9219dafc02e780bc3ab.tar.bz2
Added naive icons loading
Diffstat (limited to 'Icons.cpp')
-rw-r--r--Icons.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/Icons.cpp b/Icons.cpp
new file mode 100644
index 0000000..7b90ae0
--- /dev/null
+++ b/Icons.cpp
@@ -0,0 +1,93 @@
+#include "Icons.h"
+
+#include <string>
+#include <unordered_map>
+
+#include <raylib.h>
+
+
+static const std::unordered_map<long int, std::string> FILENAMES {
+ {11176, "resources/frigate_16.png"},
+ {11198, "resources/frigate_16.png"},
+ {11202, "resources/frigate_16.png"},
+ {11393, "resources/frigate_16.png"},
+ {11400, "resources/frigate_16.png"},
+ {11963, "resources/cruiser_16.png"},
+ {11965, "resources/cruiser_16.png"},
+ {11969, "resources/cruiser_16.png"},
+ {11971, "resources/cruiser_16.png"},
+ {11987, "resources/cruiser_16.png"},
+ {11989, "resources/cruiser_16.png"},
+ {11993, "resources/cruiser_16.png"},
+ {12017, "resources/cruiser_16.png"},
+ {12034, "resources/frigate_16.png"},
+ {17920, "resources/battleship_16.png"},
+ {19720, "resources/dreadnought_16.png"},
+ {19722, "resources/dreadnought_16.png"},
+ {2161, "resources/frigate_16.png"},
+ {22442, "resources/battleCruiser_16.png"},
+ {22456, "resources/destroyer_16.png"},
+ {22460, "resources/destroyer_16.png"},
+ {22464, "resources/destroyer_16.png"},
+ {32876, "resources/destroyer_16.png"},
+ {33468, "resources/frigate_16.png"},
+ {33474, "resources/mobileStorage.png"},
+ {33476, "resources/mobileCynosuralInhibitor.png"},
+ {34828, "resources/destroyer_16.png"},
+ {35683, "resources/destroyer_16.png"},
+ {37480, "resources/destroyer_16.png"},
+ {37482, "resources/destroyer_16.png"},
+ {37604, "resources/forceAuxiliary_16.png"},
+ {3766, "resources/frigate_16.png"},
+ {45534, "resources/cruiser_16.png"},
+ {583, "resources/frigate_16.png"},
+ {585, "resources/frigate_16.png"},
+ {606, "resources/rookie_16.png"},
+ {634, "resources/cruiser_16.png"},
+ {640, "resources/battleship_16.png"},
+ {644, "resources/battleship_16.png"},
+ {651, "resources/industrial_16.png"},
+ {670, "resources/frozenCorpse.png"},
+ {672, "resources/shuttle_16.png"},
+};
+
+
+Icons::Icons() :
+ m_cache {}
+{
+}
+
+
+Icons::~Icons()
+{
+ reset();
+}
+
+
+void
+Icons::reset()
+{
+ for (const auto& [_, texture] : m_cache)
+ UnloadTexture(texture);
+ m_cache.clear();
+}
+
+
+Texture2D
+Icons::find(const long int type)
+{
+ const auto existing = m_cache.find(type);
+ if (existing != m_cache.end()) {
+ return existing->second;
+ }
+ else {
+ Texture2D texture;
+ const auto filename = FILENAMES.find(type);
+ if (filename != FILENAMES.end())
+ texture = LoadTexture(filename->second.data());
+ else
+ texture = LoadTexture("resources/wreck.png");
+ m_cache[type] = texture;
+ return texture;
+ }
+}