21std::string extensionOf(
const std::string &
path) {
22 const auto pos =
path.find_last_of(
'.');
23 if (
pos == std::string::npos)
return {};
24 std::string ext =
path.substr(
pos);
25 for (
char &
c : ext)
c = static_cast<char>(
std::tolower(static_cast<unsigned char>(
c)));
29bool isImagePath(
const std::string &
path) {
30 const std::string ext = extensionOf(
path);
31 return ext ==
".png" || ext ==
".jpg" || ext ==
".jpeg" || ext ==
".bmp" || ext ==
".tga" ||
32 ext ==
".gif" || ext ==
".webp" || ext ==
".exr" || ext ==
".hdr";
37 for (
char &
c :
path) {
38 if (
c ==
'\\')
c =
'/';
40 while (
path.size() >= 2 &&
path[0] ==
'.' &&
path[1] ==
'/')
path.erase(0, 2);
41 while (
path.size() > 1 &&
path.back() ==
'/')
path.pop_back();
47 const char *reloadKind()
const override {
return "tilemap"; }
49 bool handlesPath(
const std::string &normPath)
const override {
50 const std::string ext = extensionOf(normPath);
51 return ext ==
".json" || ext ==
".tmj" || ext ==
".tsj" || ext ==
".tsx" || isImagePath(normPath);
60 static bool reloadConfig(
const std::string &normPath) {
62 auto view = ecs::View<TileLayer, TileLayer::Config, TileLayer::Resource>();
63 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
64 auto [cfg, res] = *it;
65 if (!cfg->entity || res->path.empty())
continue;
66 bool matches =
normalize(res->path) == normPath;
67 for (
const std::string &dependency : res->dependencyPaths)
68 matches = matches ||
normalize(dependency) == normPath;
69 if (!matches)
continue;
75 static bool rebindTileset(
const std::string &normPath) {
76 auto *gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>(
"Graphics");
77 if (!gfx)
return false;
80 auto view = ecs::View<TileLayer, TileLayer::Config, TileLayer::Resource, TileLayer::Tileset>();
81 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
82 auto [cfg, res, ts] = *it;
83 if (!cfg->entity)
continue;
85 for (
auto &atlas : ts->atlases) {
86 if (
normalize(atlas.imagePath) != normPath)
continue;
87 atlas.texture = gfx->newTextureFromFile(normPath);
88 if (atlas.firstGid == ts->firstGid) ts->texture = atlas.texture;
100 static TileLayerReloader reloader;
101 eve::cap::addListener<eve::caps::IAssetReloader>(&reloader,
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
EVENGINE_API_FOUNDATION public API.
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
bool reloadConfigFile(TileLayer *layer, std::string *error)
Reloads config file.
Vec2 normalize(const Vec2 &a)
Normalize.