[nostalgia] Cleanup config IO

This commit is contained in:
2024-06-01 20:14:29 -05:00
parent 6cbafc75bf
commit 3635702ede
3 changed files with 36 additions and 44 deletions
@@ -15,16 +15,6 @@ namespace nostalgia::core {
namespace ig = studio::ig;
static ox::String configName(ox::StringView str) noexcept {
auto out = ox::String{str};
for (auto &c : out) {
if (c == '/' || c == '\\') {
c = '%';
}
}
return out;
}
struct TileSheetEditorConfig {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetEditorConfig";
static constexpr auto TypeVersion = 1;
@@ -35,16 +25,6 @@ oxModelBegin(TileSheetEditorConfig)
oxModelFieldRename(activeSubsheet, active_subsheet)
oxModelEnd()
struct TileSheetEditorConfigs {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetEditorConfigs";
static constexpr auto TypeVersion = 1;
ox::HashMap<ox::String, TileSheetEditorConfig> configs;
};
oxModelBegin(TileSheetEditorConfigs)
oxModelField(configs)
oxModelEnd()
static ox::Vector<uint32_t> normalizePixelSizes(
ox::Vector<uint8_t> const&inPixels,
int const bpp) noexcept {
@@ -120,7 +100,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::Stri
m_model.paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
// load config
auto const&config = studio::readConfig<TileSheetEditorConfig>(
keelCtx(m_sctx), configName(itemPath()));
keelCtx(m_sctx), itemPath());
if (config.ok()) {
m_model.setActiveSubsheet(validateSubSheetIdx(m_model.img(), config.value.activeSubsheet));
}
@@ -537,9 +517,9 @@ ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
void TileSheetEditorImGui::setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept {
m_model.setActiveSubsheet(path);
studio::editConfig<TileSheetEditorConfig>(keelCtx(m_sctx), configName(itemPath()),
[&path](TileSheetEditorConfig *config) {
config->activeSubsheet = std::move(path);
studio::editConfig<TileSheetEditorConfig>(keelCtx(m_sctx), itemPath(),
[&path](TileSheetEditorConfig &config) {
config.activeSubsheet = std::move(path);
});
}