Squashed 'deps/nostalgia/' changes from 1cc1d561..ff666eda

ff666eda [studio] Make NewMenu default Name field to focus when it appears
0d8b82ba [studio] Cleanup
5598dfdd [nostalgia/player] Update hardcoded tilesheet refs to new file ext
6ef462ad [keel] Add clearer Error handling
9511cb57 [studio] Fix prev tracking

git-subtree-dir: deps/nostalgia
git-subtree-split: ff666eda9b20181135e163b0553a70101c196589
This commit is contained in:
Gary Talent 2025-01-23 21:20:06 -06:00
parent 3fddeeee3e
commit dff9f81e07
9 changed files with 37 additions and 55 deletions

View File

@ -65,7 +65,7 @@ static void testKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool d
[[maybe_unused]]
static ox::Error runTest(turbine::Context &tctx) {
constexpr ox::StringView TileSheetAddr{"/TileSheets/Charset.ng"};
constexpr ox::StringView TileSheetAddr{"/TileSheets/Charset.nts"};
constexpr ox::StringView PaletteAddr{"/Palettes/Chester.npal"};
OX_REQUIRE_M(cctx, gfx::init(tctx));
turbine::setApplicationData(tctx, cctx.get());
@ -91,10 +91,10 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
gfx::TileSheetSet const set{
.bpp = 4,
.entries = {
{ .tilesheet = ox::StringLiteral{"/TileSheets/Chester.ng"}, .sections{{.begin = 0, .tiles = 1}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/AB.ng"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/CD.ng"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/AB.ng"}, .sections{{.begin = 1, .tiles = 1}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/Chester.nts"}, .sections{{.begin = 0, .tiles = 1}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/AB.nts"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/CD.nts"}, .sections{{.begin = 0, .tiles = 2}} },
{ .tilesheet = ox::StringLiteral{"/TileSheets/AB.nts"}, .sections{{.begin = 1, .tiles = 1}} },
},
};
constexpr auto bgPalBank = 1;

View File

@ -63,8 +63,11 @@ namespace detail {
template<typename T>
constexpr auto makeLoader(Context &ctx) {
return [&ctx](ox::StringViewCR assetId) -> ox::Result<T> {
OX_REQUIRE(p, ctx.uuidToPath.at(assetId));
OX_REQUIRE(buff, ctx.rom->read(*p));
auto const p = ctx.uuidToPath.at(assetId);
if (p.error) {
return ox::Error{1, "Asset ID not found"};
}
OX_REQUIRE(buff, ctx.rom->read(*p.value));
auto [obj, err] = readAsset<T>(buff);
if (err) {
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {

View File

@ -76,8 +76,11 @@ ox::Error buildUuidMap(Context &ctx) noexcept {
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
#ifndef OX_BARE_METAL
OX_REQUIRE(out, ctx.pathToUuid.at(path));
return *out;
auto const out = ctx.pathToUuid.at(path);
if (out.error) {
return ox::Error{1, "Path not found"};
}
return *out.value;
#else
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif

View File

@ -53,6 +53,7 @@ void NewMenu::draw(StudioContext &sctx) noexcept {
case Stage::NewItemType:
drawNewItemType(sctx);
break;
case Stage::NewItemTransitioningToPath:
case Stage::NewItemPath:
drawNewItemPath(sctx);
break;
@ -90,8 +91,8 @@ void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept {
}, m_types.size(), m_selectedType, {200, 100});
auto const&im = *m_types[m_selectedType];
drawFirstPageButtons(im.itemTemplates().size() == 1 ?
Stage::NewItemPath : Stage::NewItemTemplate);
if (m_stage == Stage::NewItemPath) {
Stage::NewItemTransitioningToPath : Stage::NewItemTemplate);
if (m_stage == Stage::NewItemTransitioningToPath || m_stage == Stage::NewItemTemplate) {
if (m_path.len() == 0) {
m_path = im.defaultPath();
}
@ -108,16 +109,18 @@ void NewMenu::drawNewItemTemplate(StudioContext const&sctx) noexcept {
ig::ListBox("Template", [&](size_t const i) -> ox::CStringView {
return templates[i]->name();
}, templates.size(), m_selectedTemplate, {200, 100});
drawButtons(Stage::NewItemType, Stage::NewItemPath);
drawButtons(Stage::NewItemTransitioningToPath);
});
}
void NewMenu::drawNewItemPath(StudioContext &sctx) noexcept {
setSize({380, 340});
drawWindow(sctx.tctx, m_open, [this, &sctx] {
if (m_selectedType < m_types.size()) {
ig::InputText("Name", m_itemName);
if (m_stage == Stage::NewItemTransitioningToPath) [[unlikely]] {
ImGui::SetKeyboardFocusHere();
m_stage = Stage::NewItemPath;
}
ig::InputText("Name", m_itemName);
ImGui::NewLine();
ImGui::Text("Path");
auto const vp = ImGui::GetContentRegionAvail();
@ -126,15 +129,19 @@ void NewMenu::drawNewItemPath(StudioContext &sctx) noexcept {
});
}
void NewMenu::drawButtons(Stage const prev, Stage const next) noexcept {
void NewMenu::drawButtons(Stage const next) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) {
m_stage = prev;
if (auto const p = m_prev.back(); p.ok()) {
m_stage = *p.value;
}
m_prev.pop_back();
}
ImGui::SameLine();
if (ImGui::Button("Next", btnSz)) {
m_prev.emplace_back(m_stage);
m_stage = next;
}
ImGui::SameLine();
@ -149,6 +156,7 @@ void NewMenu::drawFirstPageButtons(Stage const next) noexcept {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Next", btnSz)) {
m_prev.emplace_back(m_stage);
m_stage = next;
}
ImGui::SameLine();
@ -163,7 +171,10 @@ void NewMenu::drawLastPageButtons(StudioContext &sctx) noexcept {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) {
m_stage = Stage::NewItemType;
if (auto const p = m_prev.back(); p.ok()) {
m_stage = *p.value;
}
m_prev.pop_back();
}
ImGui::SameLine();
if (ImGui::Button("Finish", btnSz)) {

View File

@ -20,6 +20,7 @@ class NewMenu final: public Popup {
Closed,
Opening,
NewItemType,
NewItemTransitioningToPath,
NewItemPath,
NewItemTemplate,
};
@ -29,6 +30,7 @@ class NewMenu final: public Popup {
private:
Stage m_stage = Stage::Closed;
ox::Vector<Stage, 2> m_prev;
keel::Context &m_kctx;
ox::String m_typeName;
ox::IString<255> m_itemName;
@ -79,7 +81,7 @@ class NewMenu final: public Popup {
void drawNewItemTemplate(StudioContext const &sctx) noexcept;
void drawButtons(Stage prev, Stage next) noexcept;
void drawButtons(Stage next) noexcept;
void drawFirstPageButtons(Stage next) noexcept;

View File

@ -2,8 +2,6 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <algorithm>
#include <imgui.h>
#include "projectexplorer.hpp"

View File

@ -1,16 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/memory.hpp>
#include <ox/std/string.hpp>
#include <turbine/context.hpp>
#include <studio/filetreemodel.hpp>
namespace studio {
}

View File

@ -2,7 +2,6 @@ add_library(
Studio
configio.cpp
editor.cpp
projectfilepicker.cpp
filetreemodel.cpp
imguiutil.cpp
module.cpp

View File

@ -1,18 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <studio/filetreemodel.hpp>
#include <studio/projectfilepicker.hpp>
namespace studio {
class ProjectFilePicker: public FileExplorer {
public:
explicit ProjectFilePicker(keel::Context &kctx) noexcept: FileExplorer{kctx} {}
protected:
};
}