refactor(tools): replace name_space parser with ResourceLocation

This commit is contained in:
2026-08-08 14:56:52 +08:00
parent 1baa2d6672
commit bc4bbe1ff2
4 changed files with 55 additions and 39 deletions

View File

@@ -2,7 +2,7 @@
#include "Cubed/tools/cubed_assert.hpp"
#include "Cubed/tools/log.hpp"
#include "Cubed/tools/name_space.hpp"
#include "Cubed/tools/resource_location.hpp"
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
@@ -57,15 +57,18 @@ HitboxManager::Handle HitboxManager::get_hitbox(const std::string& name) {
}
HitboxManager::Handle HitboxManager::load(std::string_view name) {
auto space = parse_namespace(name);
ASSERT(space.size() >= 2);
auto space = ResourceLocation::parse(name);
if (!space) {
Logger::error("Can't load hitbox {}", name);
ASSERT(false);
}
fs::path p;
if (space[0] == "cubed") {
if (space->ns == "cubed") {
p = std::format("{}model/creature/{}/collision.json", ASSETS_PATH,
space[1]);
space->path);
} else {
p = std::format("{}/model/creature/{}/collision.json", space[0],
space[1]);
p = std::format("{}/model/creature/{}/collision.json", space->ns,
space->path);
}
try {

View File

@@ -2,7 +2,7 @@
#include "Cubed/tools/cubed_assert.hpp"
#include "Cubed/tools/log.hpp"
#include "Cubed/tools/name_space.hpp"
#include "Cubed/tools/resource_location.hpp"
#include <filesystem>
#include <rapidjson/document.h>
@@ -67,23 +67,19 @@ const std::string& ModelManager::get_model_name(ModelID id) {
}
ModelManager::Handle ModelManager::load_model(std::string_view model_name) {
auto p = model_name.find(':');
if (p == std::string::npos) {
Logger::error("Can't Parse Model name {}", model_name);
ASSERT(false);
}
auto space = parse_namespace(model_name);
if (space.size() < 2) {
auto space = ResourceLocation::parse(model_name);
if (!space) {
Logger::error("Can't Parse Model name {}", model_name);
ASSERT(false);
}
std::string path;
if (space[0] == "cubed") {
path = std::format("{}model/creature/{}/{}.glb", ASSETS_PATH, space[1],
space[1]);
if (space->ns == "cubed") {
path = std::format("{}model/creature/{}/{}.glb", ASSETS_PATH,
space->path, space->path);
} else {
path = std::format("./{}/model/creature/{}/{}.glb", space[0], space[1],
space[1]);
path = std::format("./{}/model/creature/{}/{}.glb", space->ns,
space->path, space->path);
}
auto model = m_loader.load(path);
fs::path anim_path = path;