[nostalgia,studio] Make module handling consistent
This commit is contained in:
@@ -2,7 +2,7 @@ add_library(
|
||||
NostalgiaCore
|
||||
context.cpp
|
||||
gfx.cpp
|
||||
module.cpp
|
||||
keelmodule.cpp
|
||||
tilesheet.cpp
|
||||
typeconv.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/model/model.hpp>
|
||||
|
||||
#include <keel/asset.hpp>
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include "gfx.hpp"
|
||||
#include "typeconv.hpp"
|
||||
|
||||
#include "keelmodule.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class CoreModule: public keel::Module {
|
||||
private:
|
||||
NostalgiaPaletteToPaletteConverter nostalgiaPaletteToPaletteConverter;
|
||||
TileSheetV1ToTileSheetConverter nostalgiaGraphicToTileSheetConverter;
|
||||
TileSheetToCompactTileSheetConverter tileSheetToCompactTileSheetConverter;
|
||||
TileSheetV2ToTileSheetConverter tileSheetV2ToTileSheetConverter;
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept final {
|
||||
return {
|
||||
keel::generateTypeDesc<TileSheetV1>,
|
||||
keel::generateTypeDesc<TileSheetV2>,
|
||||
keel::generateTypeDesc<TileSheet>,
|
||||
keel::generateTypeDesc<CompactTileSheet>,
|
||||
keel::generateTypeDesc<NostalgiaPalette>,
|
||||
keel::generateTypeDesc<Palette>,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::BaseConverter*> converters() const noexcept final {
|
||||
return {
|
||||
&nostalgiaPaletteToPaletteConverter,
|
||||
&nostalgiaGraphicToTileSheetConverter,
|
||||
&tileSheetToCompactTileSheetConverter,
|
||||
&tileSheetV2ToTileSheetConverter,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
|
||||
return {
|
||||
// convert tilesheets to CompactTileSheets
|
||||
[](keel::Context *ctx, ox::Buffer *buff) -> ox::Error {
|
||||
oxRequire(hdr, keel::readAssetHeader(*buff));
|
||||
const auto typeId = ox::buildTypeId(hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
|
||||
if (typeId == ox::buildTypeId<TileSheetV1>() ||
|
||||
typeId == ox::buildTypeId<TileSheetV2>() ||
|
||||
typeId == ox::buildTypeId<TileSheet>()) {
|
||||
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
|
||||
ctx, *buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
}
|
||||
return {};
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
static CoreModule mod;
|
||||
const keel::Module *keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,6 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
const keel::Module *module() noexcept;
|
||||
const keel::Module *keelModule() noexcept;
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/model/model.hpp>
|
||||
|
||||
#include <keel/asset.hpp>
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include "gfx.hpp"
|
||||
#include "typeconv.hpp"
|
||||
|
||||
#include "module.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class CoreModule: public keel::Module {
|
||||
private:
|
||||
NostalgiaPaletteToPaletteConverter nostalgiaPaletteToPaletteConverter;
|
||||
TileSheetV1ToTileSheetConverter nostalgiaGraphicToTileSheetConverter;
|
||||
TileSheetToCompactTileSheetConverter tileSheetToCompactTileSheetConverter;
|
||||
TileSheetV2ToTileSheetConverter tileSheetV2ToTileSheetConverter;
|
||||
|
||||
public:
|
||||
static CoreModule mod;
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept override;
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::BaseConverter*> converters() const noexcept override;
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept override;
|
||||
};
|
||||
|
||||
CoreModule CoreModule::mod;
|
||||
|
||||
const keel::Module *module() noexcept {
|
||||
return &CoreModule::mod;
|
||||
}
|
||||
|
||||
ox::Vector<keel::TypeDescGenerator> CoreModule::types() const noexcept {
|
||||
return {
|
||||
keel::generateTypeDesc<TileSheetV1>,
|
||||
keel::generateTypeDesc<TileSheetV2>,
|
||||
keel::generateTypeDesc<TileSheet>,
|
||||
keel::generateTypeDesc<CompactTileSheet>,
|
||||
keel::generateTypeDesc<NostalgiaPalette>,
|
||||
keel::generateTypeDesc<Palette>,
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<const keel::BaseConverter*> CoreModule::converters() const noexcept {
|
||||
return {
|
||||
&nostalgiaPaletteToPaletteConverter,
|
||||
&nostalgiaGraphicToTileSheetConverter,
|
||||
&tileSheetToCompactTileSheetConverter,
|
||||
&tileSheetV2ToTileSheetConverter,
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<keel::PackTransform> CoreModule::packTransforms() const noexcept {
|
||||
return {
|
||||
// convert tilesheets to CompactTileSheets
|
||||
[](keel::Context *ctx, ox::Buffer *buff) -> ox::Error {
|
||||
oxRequire(hdr, keel::readAssetHeader(*buff));
|
||||
const auto typeId = ox::buildTypeId(hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
|
||||
if (typeId == ox::buildTypeId<TileSheetV1>() ||
|
||||
typeId == ox::buildTypeId<TileSheetV2>() ||
|
||||
typeId == ox::buildTypeId<TileSheet>()) {
|
||||
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
|
||||
ctx, *buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
}
|
||||
return {};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
add_library(
|
||||
NostalgiaCore-Studio OBJECT
|
||||
module.cpp
|
||||
studiomodule.cpp
|
||||
paletteeditor.cpp
|
||||
paletteeditor-imgui.cpp
|
||||
tilesheeteditor-imgui.cpp
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class StudioModule: public studio::Module {
|
||||
public:
|
||||
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) noexcept override;
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> itemMakers(turbine::Context*) noexcept override;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -7,11 +7,17 @@
|
||||
#include "paletteeditor-imgui.hpp"
|
||||
#include "tilesheeteditor-imgui.hpp"
|
||||
|
||||
#include "module.hpp"
|
||||
#include "studiomodule.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noexcept {
|
||||
class StudioModule: public studio::Module {
|
||||
public:
|
||||
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept override;
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept override;
|
||||
};
|
||||
|
||||
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) const noexcept {
|
||||
return {
|
||||
{
|
||||
{FileExt_ng},
|
||||
@@ -32,11 +38,16 @@ ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noe
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) noexcept {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) const noexcept {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", "ng"));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", "npal"));
|
||||
return out;
|
||||
}
|
||||
|
||||
static StudioModule mod;
|
||||
const studio::Module *studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
const studio::Module *studioModule() noexcept;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user