From 4466b394cbdd584d70f83024852a710a6460212e Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 2 Feb 2025 22:37:54 +0500 Subject: upd: path, name and extension in TilesetTile --- src/sets/tileset.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 +#include +#include "../utils/string.hpp" #include "entryset.hpp" -#include #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(tile)); } -- cgit v1.2.3