Compare commits
6 Commits
92d85d1145
...
829dc0298e
Author | SHA1 | Date | |
---|---|---|---|
829dc0298e | |||
e8a1ff0643 | |||
bdfb5e972a | |||
396fecab5b | |||
5373b63cca | |||
8b655c40b9 |
24
deps/ox/src/ox/oc/write.hpp
vendored
24
deps/ox/src/ox/oc/write.hpp
vendored
@ -24,7 +24,8 @@ namespace ox {
|
||||
|
||||
class OrganicClawWriter {
|
||||
|
||||
friend Result<Buffer> writeOC(const auto &val) noexcept;
|
||||
friend Result<ox::Buffer> writeOC(const auto &val) noexcept;
|
||||
friend Result<ox::String> writeOCString(const auto &val) noexcept;
|
||||
|
||||
protected:
|
||||
Json::Value m_json{Json::Value(Json::objectValue)};
|
||||
@ -247,14 +248,27 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Result<Buffer> writeOC(const auto &val) noexcept {
|
||||
Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
||||
oxReturnError(model(&handler, &val));
|
||||
Json::StreamWriterBuilder jsonBuilder;
|
||||
Json::StreamWriterBuilder const jsonBuilder;
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Buffer buff(str.size() + 1);
|
||||
memcpy(buff.data(), str.c_str(), str.size() + 1);
|
||||
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);
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
13
deps/ox/src/ox/std/hashmap.hpp
vendored
13
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -64,6 +64,9 @@ class HashMap {
|
||||
[[nodiscard]]
|
||||
constexpr Vector<K> const&keys() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector<T> values() const noexcept;
|
||||
|
||||
constexpr void clear();
|
||||
|
||||
private:
|
||||
@ -198,6 +201,16 @@ 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++) {
|
||||
|
@ -67,12 +67,22 @@ 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;
|
||||
@ -80,6 +90,10 @@ struct PaletteV2 {
|
||||
ox::Vector<ox::Vector<Color16>> pages;
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteV2)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
|
||||
|
||||
struct PaletteV3 {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
|
||||
@ -96,6 +110,15 @@ 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();
|
||||
@ -121,6 +144,11 @@ 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();
|
||||
@ -148,6 +176,10 @@ struct CompactPaletteV1 {
|
||||
ox::Vector<ox::Vector<Color16>> pages{};
|
||||
};
|
||||
|
||||
oxModelBegin(CompactPaletteV1)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(CompactPaletteV1 const&p) noexcept {
|
||||
size_t colors{};
|
||||
@ -254,34 +286,4 @@ 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()
|
||||
|
||||
}
|
||||
|
@ -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 (!valid(m_pal)) {
|
||||
if (keel::ensureValid(m_pal).errCode) {
|
||||
throw OxException(1, "PaletteEditorImGui: invalid Palette object");
|
||||
}
|
||||
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
|
||||
|
@ -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::writeOC(manifest));
|
||||
oxReturnError(writeFileBuff(argManifest, manifestJson));
|
||||
oxRequire(manifestJson, ox::writeOCString(manifest));
|
||||
oxReturnError(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class Project {
|
||||
|
||||
void indexFile(ox::CRStringView path) noexcept;
|
||||
|
||||
ox::Error writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept;
|
||||
ox::Error writeBuff(ox::CRStringView path, ox::BufferView const&buff) noexcept;
|
||||
|
||||
ox::Result<ox::Buffer> loadBuff(ox::CRStringView path) const noexcept;
|
||||
|
||||
|
@ -81,12 +81,10 @@ 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()) {
|
||||
oxRequireM(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
|
||||
// replace garbage last character with new line
|
||||
*typeOut.back().value = '\n';
|
||||
oxRequire(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
|
||||
// write to FS
|
||||
auto const typePath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*t));
|
||||
oxReturnError(writeBuff(typePath, typeOut));
|
||||
oxReturnError(writeBuff(typePath, {typeOut.data(), typeOut.size() - 1}));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -114,7 +112,7 @@ void Project::indexFile(ox::CRStringView path) noexcept {
|
||||
m_fileExtFileMap[ext].emplace_back(path);
|
||||
}
|
||||
|
||||
ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexcept {
|
||||
ox::Error Project::writeBuff(ox::CRStringView path, ox::BufferView const&buff) noexcept {
|
||||
constexpr auto HdrSz = 40;
|
||||
ox::Buffer outBuff;
|
||||
outBuff.reserve(buff.size() + HdrSz);
|
||||
|
Loading…
x
Reference in New Issue
Block a user