[keel,nostalgia,studio,turbine] Fixes for ox::String explicit change
This commit is contained in:
parent
3a62650d62
commit
da98aa864c
@ -194,13 +194,13 @@ class AssetManager {
|
||||
ox::HashMap<ox::String, ox::UniquePtr<AssetContainer<T>>> m_cache;
|
||||
|
||||
public:
|
||||
ox::Result<AssetRef<T>> getAsset(const ox::String &assetId) const noexcept {
|
||||
ox::Result<AssetRef<T>> getAsset(const ox::StringView &assetId) const noexcept {
|
||||
auto out = m_cache.at(assetId);
|
||||
oxReturnError(out);
|
||||
return AssetRef<T>(out.value->get());
|
||||
}
|
||||
|
||||
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, const T &obj) noexcept {
|
||||
ox::Result<AssetRef<T>> setAsset(const ox::StringView &assetId, const T &obj) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(obj);
|
||||
@ -211,7 +211,7 @@ class AssetManager {
|
||||
return AssetRef<T>(p.get());
|
||||
}
|
||||
|
||||
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, T &&obj) noexcept {
|
||||
ox::Result<AssetRef<T>> setAsset(const ox::StringView &assetId, T &&obj) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(obj);
|
||||
@ -247,13 +247,13 @@ class AssetManager {
|
||||
|
||||
public:
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> getAsset(const ox::String &assetId) noexcept {
|
||||
ox::Result<AssetRef<T>> getAsset(ox::CRStringView assetId) noexcept {
|
||||
auto m = getTypeManager<T>();
|
||||
return m->getAsset(assetId);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> setAsset(const ox::String &assetId, const T &obj) noexcept {
|
||||
ox::Result<AssetRef<T>> setAsset(ox::CRStringView assetId, const T &obj) noexcept {
|
||||
auto m = getTypeManager<T>();
|
||||
return m->setAsset(assetId, obj);
|
||||
}
|
||||
|
@ -25,8 +25,11 @@ ox::Result<char*> loadRom(ox::CRStringView path) noexcept {
|
||||
file.read(buff, size);
|
||||
return buff;
|
||||
} catch (const std::ios_base::failure &e) {
|
||||
oxErrorf("Could not read ROM file: {}", e.what());
|
||||
oxErrorf("Could not read ROM file due to file IO failure: {}", e.what());
|
||||
return OxError(2, "Could not read ROM file");
|
||||
} catch (const std::bad_alloc &e) {
|
||||
oxErrorf("Could not read ROM file due to new failure: {}", e.what());
|
||||
return OxError(2, "Could not allocate memory for ROM file");
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +145,7 @@ ox::Error setRomFs(Context *ctx, ox::UPtr<ox::FileSystem> fs) noexcept {
|
||||
|
||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
|
||||
const auto lastDot = ox_lastIndexOf(path, '.');
|
||||
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
|
||||
const auto fsExt = lastDot != -1 ? substr(path, static_cast<std::size_t>(lastDot)) : "";
|
||||
if (ox_strcmp(fsExt, ".oxfs") == 0) {
|
||||
oxRequire(rom, loadRom(path));
|
||||
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
||||
|
@ -52,28 +52,24 @@ ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
ox::StringView path;
|
||||
ox::UUIDStr uuidStr;
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
assetId = assetId.substr(7);
|
||||
assetId = substr(assetId, 7);
|
||||
path = ctx->uuidToPath[assetId];
|
||||
} else {
|
||||
path = assetId;
|
||||
// Warning: StringView to String
|
||||
uuidStr = ctx->pathToUuid[ox::String(path)].toString();
|
||||
uuidStr = ctx->pathToUuid[path].toString();
|
||||
assetId = uuidStr;
|
||||
}
|
||||
if (forceLoad) {
|
||||
oxRequire(buff, ctx->rom->read(path));
|
||||
oxRequire(obj, readConvert(ctx, buff));
|
||||
// Warning: StringView to String
|
||||
oxRequire(cached, ctx->assetManager.setAsset(ox::String(assetId), obj));
|
||||
oxRequire(cached, ctx->assetManager.setAsset(assetId, obj));
|
||||
return cached;
|
||||
} else {
|
||||
// Warning: StringView to String
|
||||
auto [cached, err] = ctx->assetManager.getAsset<T>(ox::String(assetId));
|
||||
auto [cached, err] = ctx->assetManager.getAsset<T>(assetId);
|
||||
if (err) {
|
||||
oxRequire(buff, ctx->rom->read(path));
|
||||
oxRequire(obj, readConvert(ctx, buff));
|
||||
// Warning: StringView to String
|
||||
oxReturnError(ctx->assetManager.setAsset(ox::String(assetId), obj).moveTo(&cached));
|
||||
oxReturnError(ctx->assetManager.setAsset(assetId, obj).moveTo(&cached));
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
@ -107,14 +103,12 @@ ox::Result<AssetRef<T>> setAsset(keel::Context *ctx, ox::StringView assetId, T c
|
||||
}
|
||||
ox::UUIDStr idStr;
|
||||
if (assetId[0] == '/') {
|
||||
// Warning: StringView to String
|
||||
const auto [id, err] = ctx->pathToUuid.at(ox::String(assetId));
|
||||
const auto [id, err] = ctx->pathToUuid.at(assetId);
|
||||
oxReturnError(err);
|
||||
idStr = id->toString();
|
||||
assetId = idStr;
|
||||
}
|
||||
// Warning: StringView to String
|
||||
return ctx->assetManager.setAsset(ox::String(assetId), asset);
|
||||
return ctx->assetManager.setAsset(assetId, asset);
|
||||
#else
|
||||
return OxError(1, "Not supported on this platform");
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ static ox::Error pathToInode(
|
||||
}
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
#ifndef OX_BARE_METAL
|
||||
const auto uuid = ox::StringView(path).substr(7);
|
||||
const auto uuid = substr(ox::StringView(path), 7);
|
||||
path = ctx->uuidToPath[uuid];
|
||||
#else
|
||||
return OxError(1, "UUID to path conversion not supported on this platform");
|
||||
|
@ -29,10 +29,10 @@ class StudioModule: public studio::Module {
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", "ng"));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", "npal"));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", FileExt_ng));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", FileExt_npal));
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
@ -632,7 +632,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
}
|
||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||
if (ox::beginsWith(path, uuidPrefix)) {
|
||||
auto uuid = ox::StringView(path + uuidPrefix.bytes(), ox_strlen(path) - uuidPrefix.bytes());
|
||||
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
|
||||
auto out = m_ctx->keelCtx.uuidToPath.at(uuid);
|
||||
if (out.error) {
|
||||
return {};
|
||||
|
@ -35,17 +35,7 @@ int main(int argc, const char **argv) {
|
||||
#endif
|
||||
OX_INIT_DEBUG_LOGGER(loggerConn, "Nostalgia Player")
|
||||
ox::Error err;
|
||||
#ifdef __cpp_exceptions
|
||||
try {
|
||||
err = run(argc, argv);
|
||||
} catch (ox::Exception const&ex) {
|
||||
err = ex.toError();
|
||||
} catch (...) {
|
||||
err = OxError(1, "Non-Ox exception");
|
||||
}
|
||||
#else
|
||||
err = run(argc, argv);
|
||||
#endif
|
||||
oxAssert(err, "Something went wrong...");
|
||||
return static_cast<int>(err);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
||||
if (!extStart) {
|
||||
return OxError(1, "Cannot open a file without valid extension.");
|
||||
}
|
||||
return path.substr(extStart + 1);
|
||||
return substr(path, extStart + 1);
|
||||
}
|
||||
|
||||
class Project {
|
||||
|
@ -104,7 +104,7 @@ ox::Error BaseEditor::saveItem() noexcept {
|
||||
|
||||
ox::StringView BaseEditor::pathToItemName(ox::CRStringView path) noexcept {
|
||||
const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset();
|
||||
return path.substr(lastSlash + 1);
|
||||
return substr(path, lastSlash + 1);
|
||||
}
|
||||
|
||||
void BaseEditor::setRequiresConstantRefresh(bool value) noexcept {
|
||||
|
@ -23,7 +23,7 @@ static void generateTypes(ox::TypeStore *ts) noexcept {
|
||||
|
||||
Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDataDir) noexcept:
|
||||
m_ctx(ctx),
|
||||
m_path(path),
|
||||
m_path(std::move(path)),
|
||||
m_projectDataDir(projectDataDir),
|
||||
m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)),
|
||||
m_fs(ctx->rom.get()) {
|
||||
@ -57,8 +57,7 @@ bool Project::exists(ox::CRStringView path) const noexcept {
|
||||
}
|
||||
|
||||
const ox::Vector<ox::String> &Project::fileList(ox::CRStringView ext) noexcept {
|
||||
// Warning: StringView to String
|
||||
return m_fileExtFileMap[ox::String(ext)];
|
||||
return m_fileExtFileMap[ext];
|
||||
}
|
||||
|
||||
void Project::buildFileIndex() noexcept {
|
||||
@ -81,8 +80,7 @@ void Project::indexFile(ox::CRStringView path) noexcept {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
// Warning: StringView to String
|
||||
m_fileExtFileMap[ox::String(ext)].emplace_back(path);
|
||||
m_fileExtFileMap[ext].emplace_back(path);
|
||||
}
|
||||
|
||||
ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept {
|
||||
@ -90,8 +88,7 @@ ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff)
|
||||
ox::Buffer outBuff;
|
||||
outBuff.reserve(buff.size() + HdrSz);
|
||||
ox::BufferWriter writer(&outBuff);
|
||||
// Warning: StringView to String
|
||||
const auto [uuid, err] = m_ctx->pathToUuid.at(ox::String(path));
|
||||
const auto [uuid, err] = m_ctx->pathToUuid.at(path);
|
||||
if (!err) {
|
||||
oxReturnError(keel::writeUuidHeader(writer, *uuid));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user