Compare commits

..

No commits in common. "829dc0298e08ae64069ba6e138fe34eb706e2871" and "92d85d1145c065164a0cdea37d5693a2730fb6ca" have entirely different histories.

7 changed files with 44 additions and 71 deletions

View File

@ -24,8 +24,7 @@ namespace ox {
class OrganicClawWriter {
friend Result<ox::Buffer> writeOC(const auto &val) noexcept;
friend Result<ox::String> writeOCString(const auto &val) noexcept;
friend Result<Buffer> writeOC(const auto &val) noexcept;
protected:
Json::Value m_json{Json::Value(Json::objectValue)};
@ -248,27 +247,14 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
return OxError(0);
}
Result<ox::Buffer> writeOC(const auto &val) noexcept {
Result<Buffer> writeOC(const auto &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
oxReturnError(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
Json::StreamWriterBuilder jsonBuilder;
const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<Buffer> buff;
buff.value.resize(str.size() + 1);
memcpy(buff.value.data(), str.data(), str.size() + 1);
return buff;
}
Result<ox::String> writeOCString(const auto &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
oxReturnError(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<ox::String> buff;
buff.value.resize(str.size());
memcpy(buff.value.data(), str.data(), str.size() + 1);
Buffer buff(str.size() + 1);
memcpy(buff.data(), str.c_str(), str.size() + 1);
return buff;
}

View File

@ -64,9 +64,6 @@ class HashMap {
[[nodiscard]]
constexpr Vector<K> const&keys() const noexcept;
[[nodiscard]]
constexpr Vector<T> values() const noexcept;
constexpr void clear();
private:
@ -201,16 +198,6 @@ constexpr Vector<K> const&HashMap<K, T>::keys() const noexcept {
return m_keys;
}
template<typename K, typename T>
constexpr Vector<T> HashMap<K, T>::values() const noexcept {
Vector<T> out;
out.reserve(m_pairs.size());
for (auto const&p : m_pairs) {
out.emplace_back(p->value);
}
return out;
}
template<typename K, typename T>
constexpr void HashMap<K, T>::clear() {
for (std::size_t i = 0; i < m_pairs.size(); i++) {

View File

@ -67,22 +67,12 @@ struct NostalgiaPalette {
ox::Vector<Color16> colors = {};
};
oxModelBegin(NostalgiaPalette)
oxModelField(colors)
oxModelEnd()
struct PaletteV1 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
static constexpr auto TypeVersion = 1;
ox::Vector<Color16> colors;
};
oxModelBegin(PaletteV1)
oxModelField(colors)
oxModelEnd()
struct PaletteV2 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
static constexpr auto TypeVersion = 2;
@ -90,10 +80,6 @@ struct PaletteV2 {
ox::Vector<ox::Vector<Color16>> pages;
};
oxModelBegin(PaletteV2)
oxModelField(pages)
oxModelEnd()
struct PaletteV3 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
@ -110,15 +96,6 @@ struct PaletteV3 {
ox::Vector<ox::Vector<Color16>> pages;
};
oxModelBegin(PaletteV3::ColorInfo)
oxModelField(name)
oxModelEnd()
oxModelBegin(PaletteV3)
oxModelField(colorInfo)
oxModelField(pages)
oxModelEnd()
[[nodiscard]]
constexpr bool valid(PaletteV3 const&p) noexcept {
auto const colors = p.colorInfo.size();
@ -144,11 +121,6 @@ struct PaletteV4 {
ox::Vector<PalettePageV1> pages;
};
oxModelBegin(PaletteV4)
oxModelField(colorNames)
oxModelField(pages)
oxModelEnd()
[[nodiscard]]
constexpr bool valid(PaletteV4 const&p) noexcept {
auto const colors = p.colorNames.size();
@ -176,10 +148,6 @@ struct CompactPaletteV1 {
ox::Vector<ox::Vector<Color16>> pages{};
};
oxModelBegin(CompactPaletteV1)
oxModelField(pages)
oxModelEnd()
[[nodiscard]]
constexpr bool valid(CompactPaletteV1 const&p) noexcept {
size_t colors{};
@ -286,4 +254,34 @@ constexpr size_t largestPage(CompactPalette const&pal) noexcept {
return out;
}
oxModelBegin(NostalgiaPalette)
oxModelField(colors)
oxModelEnd()
oxModelBegin(PaletteV1)
oxModelField(colors)
oxModelEnd()
oxModelBegin(PaletteV2)
oxModelField(pages)
oxModelEnd()
oxModelBegin(PaletteV3::ColorInfo)
oxModelField(name)
oxModelEnd()
oxModelBegin(PaletteV3)
oxModelField(colorInfo)
oxModelField(pages)
oxModelEnd()
oxModelBegin(PaletteV4)
oxModelField(colorNames)
oxModelField(pages)
oxModelEnd()
oxModelBegin(CompactPaletteV1)
oxModelField(pages)
oxModelEnd()
}

View File

@ -41,7 +41,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
m_sctx(sctx),
m_tctx(sctx.tctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {
if (keel::ensureValid(m_pal).errCode) {
if (!valid(m_pal)) {
throw OxException(1, "PaletteEditorImGui: invalid Palette object");
}
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);

View File

@ -76,8 +76,8 @@ static ox::Error pack(
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
oxReturnError(writeFileBuff(argRomBin, romBuff));
oxRequire(manifestJson, ox::writeOCString(manifest));
oxReturnError(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
oxRequire(manifestJson, ox::writeOC(manifest));
oxReturnError(writeFileBuff(argManifest, manifestJson));
return {};
}

View File

@ -107,7 +107,7 @@ class Project {
void indexFile(ox::CRStringView path) noexcept;
ox::Error writeBuff(ox::CRStringView path, ox::BufferView const&buff) noexcept;
ox::Error writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept;
ox::Result<ox::Buffer> loadBuff(ox::CRStringView path) const noexcept;

View File

@ -81,10 +81,12 @@ ox::Error Project::writeTypeStore() noexcept {
// write all descriptors because we don't know which types T depends on
oxReturnError(mkdir(m_typeDescPath));
for (auto const &t: m_typeStore.typeList()) {
oxRequire(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
oxRequireM(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
// replace garbage last character with new line
*typeOut.back().value = '\n';
// write to FS
auto const typePath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*t));
oxReturnError(writeBuff(typePath, {typeOut.data(), typeOut.size() - 1}));
oxReturnError(writeBuff(typePath, typeOut));
}
return {};
}
@ -112,7 +114,7 @@ void Project::indexFile(ox::CRStringView path) noexcept {
m_fileExtFileMap[ext].emplace_back(path);
}
ox::Error Project::writeBuff(ox::CRStringView path, ox::BufferView const&buff) noexcept {
ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept {
constexpr auto HdrSz = 40;
ox::Buffer outBuff;
outBuff.reserve(buff.size() + HdrSz);