summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-02-02 22:37:54 +0500
committerilotterytea <iltsu@alright.party>2025-02-02 22:37:54 +0500
commit4466b394cbdd584d70f83024852a710a6460212e (patch)
treea0b46ac1028f6675c7f13ad841f18c7533cc4b84
parentd7b3911ad879cc85a12e3e4979fc8d8f4b526960 (diff)
upd: path, name and extension in TilesetTile
-rw-r--r--src/sets/tileset.hpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/sets/tileset.hpp b/src/sets/tileset.hpp
index 3e8938b..0206f1c 100644
--- a/src/sets/tileset.hpp
+++ b/src/sets/tileset.hpp
@@ -1,8 +1,9 @@
#pragma once
#include <SFML/Graphics/Texture.hpp>
+#include <algorithm>
+#include "../utils/string.hpp"
#include "entryset.hpp"
-#include <algorithm>
#define TILE_WIDTH 16
#define TILE_HEIGHT 16
@@ -12,6 +13,7 @@ namespace silly::editor {
struct TilesetTile {
int id;
sf::Texture texture;
+ std::string path, name, extension;
TilesetTileType type;
};
@@ -20,6 +22,7 @@ namespace silly::editor {
void add_entry(const std::string &path, TilesetTileType type) override {
TilesetTile tile;
tile.type = type;
+ tile.path = path;
tile.id = this->entries.size();
if (!tile.texture.loadFromFile(path)) {
@@ -27,6 +30,21 @@ namespace silly::editor {
return;
}
+ // parsing name and extension
+#ifdef WIN32
+ char delim = '\\';
+#else
+ char delim = '/';
+#endif
+ auto path_parts = utils::split_text(path, delim);
+
+ std::string name_with_extension = path_parts[path_parts.size() - 1];
+ auto nwe_parts = utils::split_text(name_with_extension, '.');
+
+ tile.extension = nwe_parts[nwe_parts.size() - 1];
+ tile.name = name_with_extension.substr(
+ 0, name_with_extension.length() - tile.extension.length() - 1);
+
this->entries.push_back(std::make_shared<TilesetTile>(tile));
}