[jasper] Add missing files, update for Nostalgia changes
All checks were successful
Build / build (push) Successful in 2m51s

This commit is contained in:
Gary Talent 2024-04-21 13:15:17 -05:00
parent 26d2645174
commit eecc9da3ce
6 changed files with 166 additions and 6 deletions

View File

@ -0,0 +1,52 @@
/*
* Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <turbine/context.hpp>
#include <nostalgia/core/gfx.hpp>
#include <jasper/world/worlddoc.hpp>
#include <jasper/world/worldobject.hpp>
namespace jasper::world {
class ObjectCache {
public:
struct Obj {
ObjectId id{};
uint16_t palBank{};
size_t tileIdx{};
};
private:
struct ObjSet {
uint64_t setId{};
ox::Vector<Obj> objects;
};
ox::Vector<ox::FileAddress> m_tilesheets;
ox::Vector<PaletteCycle> m_palettes;
size_t m_tileIdx{};
size_t m_palBank{};
ox::Vector<ObjSet> m_objSets;
ncore::TileSheetSet m_tilesheetSet;
public:
void clear() noexcept;
ox::Error indexSet(
keel::Context &kctx,
uint64_t setId,
WorldObjectSet const&objSet) noexcept;
[[nodiscard]]
ox::Optional<Obj> obj(uint64_t setId, ObjectId objId) const noexcept;
[[nodiscard]]
ncore::TileSheetSet const&tilesheets() const noexcept;
[[nodiscard]]
ox::Vector<PaletteCycle> const&palettes() const noexcept;
private:
void addTileSheet(ox::FileAddress path, int32_t tiles) noexcept;
};
ox::Result<ObjectCache> buildObjCache(keel::Context &kctx, WorldDoc const&doc) noexcept;
}

View File

@ -0,0 +1,108 @@
/*
* Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/fs/fs.hpp>
#include <ox/std/error.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp>
#include <ox/std/vector.hpp>
#include <nostalgia/core/tilesheet.hpp>
#include "worldobject.hpp"
namespace jasper::world {
namespace ncore = nostalgia::core;
struct SpriteDoc {
constexpr static auto TypeName = "net.drinkingtea.jasper.world.SpriteDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
ox::String tilesheetPath;
ox::Vector<ncore::SubSheetId> subsheetId;
};
struct DocObjRef {
constexpr static auto TypeName = "net.drinkingtea.jasper.world.DocObjRef";
constexpr static auto TypeVersion = 1;
uint64_t worldObjectSetId{};
ObjectId worldObjectId{};
};
oxModelBegin(DocObjRef)
oxModelFieldRename(worldObjectSetId, world_object_set_id)
oxModelFieldRename(worldObjectId, world_object_id)
oxModelEnd()
struct TileDoc {
constexpr static auto TypeName = "net.drinkingtea.jasper.world.TileDoc";
constexpr static auto TypeVersion = 1;
DocObjRef obj;
uint8_t type = 0;
uint8_t palBank = 0;
uint8_t topLayerAttachment{};
uint8_t bottomLayerAttachment{};
uint8_t leftLayerAttachment{};
uint8_t rightLayerAttachment{};
};
oxModelBegin(TileDoc)
oxModelField(obj)
oxModelField(type)
oxModelFieldRename(palBank, pal_bank)
oxModelFieldRename(topLayerAttachment, top_layer_attachment)
oxModelFieldRename(bottomLayerAttachment, bottom_layer_attachment)
oxModelFieldRename(leftLayerAttachment, left_layer_attachment)
oxModelFieldRename(rightLayerAttachment, right_layer_attachment)
oxModelEnd()
struct ObjectSetEntry {
constexpr static auto TypeName = "net.drinkingtea.jasper.world.ObjectSetEntry";
constexpr static auto TypeVersion = 1;
ox::String path;
uint64_t id{};
};
oxModelBegin(ObjectSetEntry)
oxModelField(path)
oxModelField(id)
oxModelEnd()
struct WorldDoc {
using TileMapRow = ox::Vector<TileDoc>;
using TileMapLayer = ox::Vector<TileMapRow>;
using TileMap = ox::Array<TileMapLayer, 3>;
constexpr static auto TypeName = "net.drinkingtea.jasper.world.WorldDoc";
constexpr static auto TypeVersion = 1;
ox::Vector<ObjectSetEntry> objSets; // paths
uint64_t objSetIdIdx{};
int columns{};
int rows{};
TileMap tiles;
};
oxModelBegin(WorldDoc)
oxModelFieldRename(objSets, object_sets)
oxModelFieldRename(objSetIdIdx, object_set_id_idx)
oxModelField(columns)
oxModelField(rows)
oxModelField(tiles)
oxModelEnd()
[[nodiscard]]
ObjectSetEntry const*objSetEntry(WorldDoc const&doc, size_t id) noexcept;
[[nodiscard]]
auto &tile(ox::CommonRefWith<WorldDoc> auto &doc, size_t lyr, size_t col, size_t row) noexcept {
return doc.tiles[lyr][row][col];
}
void resize(WorldDoc &doc, ox::Size const&sz) noexcept;
}

View File

@ -59,7 +59,7 @@ WorldEditorImGui::WorldEditorImGui(studio::StudioContext &sctx, ox::StringView p
m_sctx.project->fileUpdated.connect(this, &WorldEditorImGui::handleObjectSetUpdate); m_sctx.project->fileUpdated.connect(this, &WorldEditorImGui::handleObjectSetUpdate);
} }
void WorldEditorImGui::draw(turbine::Context&) noexcept { void WorldEditorImGui::draw(studio::StudioContext&) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail(); const auto paneSize = ImGui::GetContentRegionAvail();
constexpr auto resourcesWidth = 300.f; constexpr auto resourcesWidth = 300.f;
{ {

View File

@ -36,7 +36,7 @@ class WorldEditorImGui: public studio::Editor {
public: public:
WorldEditorImGui(studio::StudioContext &ctx, ox::StringView path); WorldEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(turbine::Context&) noexcept final; void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override; void onActivated() noexcept override;

View File

@ -36,7 +36,7 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui(
buildPaletteDisplayNameList(); buildPaletteDisplayNameList();
} }
void WorldObjectSetEditorImGui::draw(turbine::Context&) noexcept { void WorldObjectSetEditorImGui::draw(studio::StudioContext&) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail(); const auto paneSize = ImGui::GetContentRegionAvail();
constexpr auto resourcesWidth = 300.f; constexpr auto resourcesWidth = 300.f;
ImGui::BeginChild("ObjEditor", ImVec2(paneSize.x - resourcesWidth, 0)); ImGui::BeginChild("ObjEditor", ImVec2(paneSize.x - resourcesWidth, 0));
@ -122,7 +122,7 @@ void WorldObjectSetEditorImGui::loadObj() noexcept {
} }
auto const&obj = activeObj(); auto const&obj = activeObj();
auto &nameBuff = m_objEditor.nameBuff; auto &nameBuff = m_objEditor.nameBuff;
ox_strncpy(nameBuff.data(), obj.name.data(), nameBuff.size()); ox::strncpy(nameBuff.data(), obj.name.data(), nameBuff.size());
m_objEditor.palette = obj.palBank; m_objEditor.palette = obj.palBank;
m_subsheet = getSubsheet(*m_tileSheet, obj.subsheetId); m_subsheet = getSubsheet(*m_tileSheet, obj.subsheetId);
int w = 0; int w = 0;
@ -159,7 +159,7 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
undoStack()->push(ox::make_unique<EditObjectName>( undoStack()->push(ox::make_unique<EditObjectName>(
m_doc, m_doc,
m_selectedObj, m_selectedObj,
ox::String(nameBuff.data(), ox_strnlen(nameBuff.data(), nameBuff.size())))); ox::String(nameBuff.data(), ox::strnlen(nameBuff.data(), nameBuff.size()))));
} }
// SubSheet Selector // SubSheet Selector
{ {

View File

@ -42,7 +42,7 @@ class WorldObjectSetEditorImGui: public studio::Editor {
public: public:
WorldObjectSetEditorImGui(studio::StudioContext &ctx, ox::StringView path); WorldObjectSetEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(turbine::Context&) noexcept final; void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override; void onActivated() noexcept override;