Squashed 'deps/nostalgia/' changes from 161640fa..a75c4a11
a75c4a11 [nfde] Address CMake warning, remove unwanted logging 347a1657 [sample_project] Update type descriptors fd64bfae [keel] Fix a use after free, cleanup aaeec20a [nostalgia/player] Fix build 37030f9c [keel] Cleanup pack tool 462f2bca [nostalgia,olympic] Change macro names to comply with broader conventions dc72500b [glutils] Change macro names to comply with broader conventions 962fe8bc [ox] Change macro names to comply with broader conventions 305eb626 [studio] Fix build 4754359a [ox/std] Cleanup Vec2 dc07f3d5 [studio] Change FilePicker consturctor to take StringParams fcdcfd10 [ox/std] Run liccor b74f6a7a [studio,turbine] Run liccor ac7e5be1 [ox] Remove OxException ed910c0b [nostalgia/core/studio/tilesheeteditor] Fix access overflow on out of bounds Fill command 345fb038 [ox] Remove OxError 9881253f [glutils] Cleanup OxError 96d27eec [nostalgia,olympic] Cleanup 28ebe93b [ox/std] Make source_location::current only init if valid e849e7a3 [ox/std] Add source_location e6777b0a [cityhash] Add install rule c488c336 [turbine/glfw] Fix mandatoryRefreshPeriodEnd tracking 003f9720 [turbine/glfw] Move MandatoryRefreshPeriod to config.hpp d85a10af [nostalgia/core/studio] Cleanup ff05d860 [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd 76794037 [turbine] Add init wrapper that takes FS path c51a45e1 [olympic] Cleanup a6e24ff2 [ox/std] Add CString type alias e0ec9e0c [nostalgia,olympic] Move olympic::run to global namespace 9a42a9b9 [nfde] Fix Windows warnings 03a05c51 Merge commit '4ccdfc3a6e5bd501968903a01f7d8141b6f88375' bd91137d [nostalgia,olympic] Fix pack tool build for Windows 2b7d1294 [nostalgia/core/studio] Fix MSVC build git-subtree-dir: deps/nostalgia git-subtree-split: a75c4a11d3c555f4d3bed1ea1f70bb29fe49e99c
This commit is contained in:
@@ -32,18 +32,18 @@ struct Sprite {
|
||||
unsigned priority = 0;
|
||||
};
|
||||
|
||||
oxModelBegin(Sprite)
|
||||
oxModelField(idx)
|
||||
oxModelField(x)
|
||||
oxModelField(y)
|
||||
oxModelField(enabled)
|
||||
oxModelField(tileIdx)
|
||||
oxModelField(spriteShape)
|
||||
oxModelField(spriteSize)
|
||||
oxModelField(flipX)
|
||||
oxModelField(bpp)
|
||||
oxModelField(priority)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(Sprite)
|
||||
OX_MODEL_FIELD(idx)
|
||||
OX_MODEL_FIELD(x)
|
||||
OX_MODEL_FIELD(y)
|
||||
OX_MODEL_FIELD(enabled)
|
||||
OX_MODEL_FIELD(tileIdx)
|
||||
OX_MODEL_FIELD(spriteShape)
|
||||
OX_MODEL_FIELD(spriteSize)
|
||||
OX_MODEL_FIELD(flipX)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(priority)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct BgTile {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.BgTile";
|
||||
@@ -54,12 +54,12 @@ struct BgTile {
|
||||
unsigned flipY = false;
|
||||
};
|
||||
|
||||
oxModelBegin(BgTile)
|
||||
oxModelField(tileIdx)
|
||||
oxModelField(palBank)
|
||||
oxModelField(horizontalFlip)
|
||||
oxModelField(verticalFlip)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(BgTile)
|
||||
OX_MODEL_FIELD(tileIdx)
|
||||
OX_MODEL_FIELD(palBank)
|
||||
OX_MODEL_FIELD(horizontalFlip)
|
||||
OX_MODEL_FIELD(verticalFlip)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct TileSheetSetEntrySection {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntrySection";
|
||||
@@ -72,10 +72,10 @@ struct TileSheetSetEntrySection {
|
||||
}
|
||||
};
|
||||
|
||||
oxModelBegin(TileSheetSetEntrySection)
|
||||
oxModelField(begin)
|
||||
oxModelField(tiles)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetSetEntrySection)
|
||||
OX_MODEL_FIELD(begin)
|
||||
OX_MODEL_FIELD(tiles)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct TileSheetSetEntry {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntry";
|
||||
@@ -84,10 +84,10 @@ struct TileSheetSetEntry {
|
||||
ox::Vector<TileSheetSetEntrySection> sections;
|
||||
};
|
||||
|
||||
oxModelBegin(TileSheetSetEntry)
|
||||
oxModelField(tilesheet)
|
||||
oxModelField(sections)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetSetEntry)
|
||||
OX_MODEL_FIELD(tilesheet)
|
||||
OX_MODEL_FIELD(sections)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct TileSheetSet {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet";
|
||||
@@ -97,10 +97,10 @@ struct TileSheetSet {
|
||||
ox::Vector<TileSheetSetEntry> entries;
|
||||
};
|
||||
|
||||
oxModelBegin(TileSheetSet)
|
||||
oxModelField(bpp)
|
||||
oxModelField(entries)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetSet)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(entries)
|
||||
OX_MODEL_END()
|
||||
|
||||
void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept;
|
||||
|
||||
|
@@ -26,12 +26,12 @@ struct PaletteColorV1 {
|
||||
constexpr operator Color16() const noexcept { return color16(r, g, b, a); }
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteColorV1)
|
||||
oxModelField(r)
|
||||
oxModelField(g)
|
||||
oxModelField(b)
|
||||
oxModelField(a)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteColorV1)
|
||||
OX_MODEL_FIELD(r)
|
||||
OX_MODEL_FIELD(g)
|
||||
OX_MODEL_FIELD(b)
|
||||
OX_MODEL_FIELD(a)
|
||||
OX_MODEL_END()
|
||||
|
||||
using PaletteColor = PaletteColorV1;
|
||||
|
||||
@@ -53,10 +53,10 @@ struct PalettePageV1 {
|
||||
}
|
||||
};
|
||||
|
||||
oxModelBegin(PalettePageV1)
|
||||
oxModelField(name)
|
||||
oxModelField(colors)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PalettePageV1)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_FIELD(colors)
|
||||
OX_MODEL_END()
|
||||
|
||||
using PalettePage = PalettePageV1;
|
||||
|
||||
@@ -67,9 +67,9 @@ struct NostalgiaPalette {
|
||||
ox::Vector<Color16> colors = {};
|
||||
};
|
||||
|
||||
oxModelBegin(NostalgiaPalette)
|
||||
oxModelField(colors)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(NostalgiaPalette)
|
||||
OX_MODEL_FIELD(colors)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
struct PaletteV1 {
|
||||
@@ -78,9 +78,9 @@ struct PaletteV1 {
|
||||
ox::Vector<Color16> colors;
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteV1)
|
||||
oxModelField(colors)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteV1)
|
||||
OX_MODEL_FIELD(colors)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
struct PaletteV2 {
|
||||
@@ -90,9 +90,9 @@ struct PaletteV2 {
|
||||
ox::Vector<ox::Vector<Color16>> pages;
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteV2)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteV2)
|
||||
OX_MODEL_FIELD(pages)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
struct PaletteV3 {
|
||||
@@ -110,14 +110,14 @@ struct PaletteV3 {
|
||||
ox::Vector<ox::Vector<Color16>> pages;
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteV3::ColorInfo)
|
||||
oxModelField(name)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteV3::ColorInfo)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(PaletteV3)
|
||||
oxModelField(colorInfo)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteV3)
|
||||
OX_MODEL_FIELD(colorInfo)
|
||||
OX_MODEL_FIELD(pages)
|
||||
OX_MODEL_END()
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(PaletteV3 const&p) noexcept {
|
||||
@@ -144,10 +144,10 @@ struct PaletteV4 {
|
||||
ox::Vector<PalettePageV1> pages;
|
||||
};
|
||||
|
||||
oxModelBegin(PaletteV4)
|
||||
oxModelField(colorNames)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PaletteV4)
|
||||
OX_MODEL_FIELD(colorNames)
|
||||
OX_MODEL_FIELD(pages)
|
||||
OX_MODEL_END()
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(PaletteV4 const&p) noexcept {
|
||||
@@ -176,9 +176,9 @@ struct CompactPaletteV1 {
|
||||
ox::Vector<ox::Vector<Color16>> pages{};
|
||||
};
|
||||
|
||||
oxModelBegin(CompactPaletteV1)
|
||||
oxModelField(pages)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(CompactPaletteV1)
|
||||
OX_MODEL_FIELD(pages)
|
||||
OX_MODEL_END()
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(CompactPaletteV1 const&p) noexcept {
|
||||
|
@@ -96,7 +96,7 @@ constexpr void repair(TileSheetV2::SubSheet &ss, int bpp) noexcept {
|
||||
|
||||
constexpr ox::Error repair(TileSheetV2 &ts) noexcept {
|
||||
if (ts.bpp != 4 && ts.bpp != 8) {
|
||||
return OxError(1, "Unable to repair TileSheet");
|
||||
return ox::Error(1, "Unable to repair TileSheet");
|
||||
}
|
||||
repair(ts.subsheet, ts.bpp);
|
||||
return {};
|
||||
@@ -166,7 +166,7 @@ constexpr void repair(TileSheetV3::SubSheet &ss, int bpp) noexcept {
|
||||
|
||||
constexpr ox::Error repair(TileSheetV3 &ts) noexcept {
|
||||
if (ts.bpp != 4 && ts.bpp != 8) {
|
||||
return OxError(1, "Unable to repair TileSheet");
|
||||
return ox::Error(1, "Unable to repair TileSheet");
|
||||
}
|
||||
repair(ts.subsheet, ts.bpp);
|
||||
return {};
|
||||
@@ -254,7 +254,7 @@ constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
|
||||
|
||||
constexpr ox::Error repair(TileSheetV4 &ts) noexcept {
|
||||
if (ts.bpp != 4 && ts.bpp != 8) {
|
||||
return OxError(1, "Unable to repair TileSheet");
|
||||
return ox::Error(1, "Unable to repair TileSheet");
|
||||
}
|
||||
repair(ts.subsheet, ts.bpp);
|
||||
return {};
|
||||
@@ -437,65 +437,65 @@ ox::Pair<uint8_t> get2Pixels8Bpp(
|
||||
CompactTileSheet const&ts,
|
||||
size_t idx) noexcept;
|
||||
|
||||
oxModelBegin(TileSheetV1)
|
||||
oxModelField(bpp)
|
||||
oxModelField(rows)
|
||||
oxModelField(columns)
|
||||
oxModelField(defaultPalette)
|
||||
oxModelField(pal)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV1)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(defaultPalette)
|
||||
OX_MODEL_FIELD(pal)
|
||||
OX_MODEL_FIELD(pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV2::SubSheet)
|
||||
oxModelField(name)
|
||||
oxModelField(rows)
|
||||
oxModelField(columns)
|
||||
oxModelField(subsheets)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV2::SubSheet)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(subsheets)
|
||||
OX_MODEL_FIELD(pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV2)
|
||||
oxModelField(bpp)
|
||||
oxModelField(defaultPalette)
|
||||
oxModelField(subsheet)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV2)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(defaultPalette)
|
||||
OX_MODEL_FIELD(subsheet)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV3::SubSheet)
|
||||
oxModelField(name)
|
||||
oxModelField(rows)
|
||||
oxModelField(columns)
|
||||
oxModelField(subsheets)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV3::SubSheet)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(subsheets)
|
||||
OX_MODEL_FIELD(pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV3)
|
||||
oxModelField(bpp)
|
||||
oxModelField(idIt)
|
||||
oxModelField(defaultPalette)
|
||||
oxModelField(subsheet)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV3)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(idIt)
|
||||
OX_MODEL_FIELD(defaultPalette)
|
||||
OX_MODEL_FIELD(subsheet)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV4::SubSheet)
|
||||
oxModelField(id)
|
||||
oxModelField(name)
|
||||
oxModelField(rows)
|
||||
oxModelField(columns)
|
||||
oxModelField(subsheets)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV4::SubSheet)
|
||||
OX_MODEL_FIELD(id)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(subsheets)
|
||||
OX_MODEL_FIELD(pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetV4)
|
||||
oxModelField(bpp)
|
||||
oxModelField(idIt)
|
||||
oxModelField(defaultPalette)
|
||||
oxModelField(subsheet)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetV4)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(idIt)
|
||||
OX_MODEL_FIELD(defaultPalette)
|
||||
OX_MODEL_FIELD(subsheet)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(CompactTileSheetV1)
|
||||
oxModelField(bpp)
|
||||
oxModelField(defaultPalette)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(CompactTileSheetV1)
|
||||
OX_MODEL_FIELD(bpp)
|
||||
OX_MODEL_FIELD(defaultPalette)
|
||||
OX_MODEL_FIELD(pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
ox::Vector<uint32_t> resizeTileSheetData(
|
||||
ox::Vector<uint32_t> const&srcPixels,
|
||||
|
@@ -21,7 +21,7 @@ ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||
|
||||
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<Context>(tctx);
|
||||
oxReturnError(initGfx(*ctx, params));
|
||||
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||
return ContextUPtr(std::move(ctx));
|
||||
}
|
||||
|
||||
|
@@ -70,9 +70,9 @@ static ox::Error loadTileSheetSet(
|
||||
size_t tileWriteIdx = 0;
|
||||
size_t const bppMod = set.bpp == 4;
|
||||
for (auto const&entry : set.entries) {
|
||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), entry.tilesheet));
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), entry.tilesheet));
|
||||
if (set.bpp != ts->bpp && ts->bpp == 8) {
|
||||
return OxError(1, "cannot load an 8 BPP tilesheet into a 4 BPP CBB");
|
||||
return ox::Error(1, "cannot load an 8 BPP tilesheet into a 4 BPP CBB");
|
||||
}
|
||||
for (auto const&s : entry.sections) {
|
||||
auto const cnt = (static_cast<size_t>(s.tiles) * PixelsPerTile) >> bppMod;
|
||||
@@ -138,7 +138,7 @@ ox::Error loadBgTileSheet(
|
||||
}
|
||||
});
|
||||
if (paletteBank.has_value() && ts.defaultPalette) {
|
||||
oxReturnError(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||
OX_RETURN_ERROR(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -148,7 +148,7 @@ ox::Error loadBgTileSheet(
|
||||
unsigned const cbb,
|
||||
TileSheetSet const&set) noexcept {
|
||||
auto const bpp = static_cast<unsigned>(set.bpp);
|
||||
oxReturnError(loadTileSheetSet(ctx, MEM_BG_TILES[cbb], set));
|
||||
OX_RETURN_ERROR(loadTileSheetSet(ctx, MEM_BG_TILES[cbb], set));
|
||||
// update bpp of all bgs with the updated cbb
|
||||
ctx.cbbData[cbb].bpp = bpp;
|
||||
teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) {
|
||||
@@ -178,7 +178,7 @@ ox::Error loadSpriteTileSheet(
|
||||
MEM_SPRITE_TILES[i] = v;
|
||||
}
|
||||
if (loadDefaultPalette && ts.defaultPalette) {
|
||||
oxReturnError(loadSpritePalette(ctx, ts.defaultPalette));
|
||||
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
|
||||
}
|
||||
setSpritesBpp(static_cast<unsigned>(ts.bpp));
|
||||
return {};
|
||||
@@ -188,7 +188,7 @@ ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
TileSheetSet const&set) noexcept {
|
||||
auto const bpp = static_cast<unsigned>(set.bpp);
|
||||
oxReturnError(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set));
|
||||
OX_RETURN_ERROR(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set));
|
||||
setSpritesBpp(bpp);
|
||||
return {};
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
ox::StringViewCR palettePath) noexcept {
|
||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||
return loadBgPalette(ctx, palBank, *pal, 0);
|
||||
}
|
||||
|
||||
@@ -30,21 +30,21 @@ ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||
return loadBgPalette(ctx, palBank, *pal, 0);
|
||||
}
|
||||
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
ox::StringViewCR palettePath) noexcept {
|
||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||
return loadSpritePalette(ctx, *pal, 0);
|
||||
}
|
||||
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||
return loadSpritePalette(ctx, *pal, 0);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ ox::Error loadBgTileSheet(
|
||||
size_t dstTileIdx,
|
||||
size_t srcTileIdx,
|
||||
size_t tileCnt) noexcept {
|
||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsAddr));
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsAddr));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ ox::Error loadBgTileSheet(
|
||||
size_t dstTileIdx,
|
||||
size_t srcTileIdx,
|
||||
size_t tileCnt) noexcept {
|
||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsPath));
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsPath));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ ox::Error loadBgTileSheet(
|
||||
unsigned cbb,
|
||||
ox::StringViewCR tilesheetPath,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ ox::Error loadBgTileSheet(
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
ox::StringViewCR tilesheetPath,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
oxRequire(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||
OX_REQUIRE(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
oxRequire(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
OX_REQUIRE(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
||||
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal");
|
||||
setBgStatus(ctx, 0b0001);
|
||||
setBgCbb(ctx, 0, 0);
|
||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr));
|
||||
OX_RETURN_ERROR(loadBgTileSheet(ctx, 0, TilesheetAddr));
|
||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||
}
|
||||
|
||||
|
@@ -72,7 +72,7 @@ static class: public keel::Module {
|
||||
typeId == ox::ModelTypeId_v<TileSheetV2> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV3> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV4>) {
|
||||
oxReturnError(keel::convertBuffToBuff<CompactTileSheet>(
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactTileSheet>(
|
||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
return true;
|
||||
}
|
||||
@@ -81,10 +81,10 @@ static class: public keel::Module {
|
||||
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Result<bool> {
|
||||
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV1> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV2> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV3> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV4>) {
|
||||
oxReturnError(keel::convertBuffToBuff<CompactPalette>(
|
||||
typeId == ox::ModelTypeId_v<PaletteV2> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV3> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV4>) {
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactPalette>(
|
||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
return true;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ static class: public keel::Module {
|
||||
},
|
||||
};
|
||||
}
|
||||
} mod;
|
||||
} const mod;
|
||||
|
||||
keel::Module const*keelModule() noexcept {
|
||||
return &mod;
|
||||
|
@@ -25,7 +25,7 @@ Context::~Context() noexcept {
|
||||
|
||||
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<Context>(tctx, params);
|
||||
oxReturnError(initGfx(*ctx, params));
|
||||
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||
return ContextUPtr(ctx.release());
|
||||
}
|
||||
|
||||
|
@@ -464,8 +464,8 @@ ox::Error initGfx(
|
||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
||||
oxReturnError(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx.bgShader));
|
||||
oxReturnError(
|
||||
OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx.bgShader));
|
||||
OX_RETURN_ERROR(
|
||||
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx.spriteShader));
|
||||
for (auto &cbb : ctx.cbbs) {
|
||||
initBackgroundBufferset(ctx.bgShader, cbb);
|
||||
@@ -538,8 +538,8 @@ static ox::Result<TileSheetData> buildSetTsd(
|
||||
TileSheetData setTsd;
|
||||
setTsd.width = TileWidth;
|
||||
for (auto const&entry : set.entries) {
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, entry.tilesheet));
|
||||
oxRequire(tsd, normalizeTileSheet(*tilesheet));
|
||||
OX_REQUIRE(tilesheet, readObj<CompactTileSheet>(kctx, entry.tilesheet));
|
||||
OX_REQUIRE(tsd, normalizeTileSheet(*tilesheet));
|
||||
for (auto const&s : entry.sections) {
|
||||
auto const size = s.tiles * PixelsPerTile;
|
||||
for (auto i = 0; i < size; ++i) {
|
||||
@@ -586,7 +586,7 @@ ox::Error loadBgTileSheet(
|
||||
auto const srcPxIdx = srcTileIdx * PixelsPerTile;
|
||||
auto const dstPxIdx = dstTileIdx * PixelsPerTile;
|
||||
if (dstPxIdx + pxlCnt >= cbbPxls.size()) {
|
||||
return OxError(1, "video mem dst overflow");
|
||||
return ox::Error(1, "video mem dst overflow");
|
||||
}
|
||||
auto const dst = ox::Span{cbbPxls} + dstPxIdx;
|
||||
copyPixels(ts, dst, srcPxIdx, pxlCnt);
|
||||
@@ -604,9 +604,9 @@ ox::Error loadBgTileSheet(
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
auto const bytesPerTile = static_cast<uint64_t>(PixelsPerTile / (1 + (ts.bpp == 4)));
|
||||
auto const tiles = ts.pixels.size() / bytesPerTile;
|
||||
oxReturnError(loadBgTileSheet(ctx, cbb, ts, 0, 0, tiles));
|
||||
OX_RETURN_ERROR(loadBgTileSheet(ctx, cbb, ts, 0, 0, tiles));
|
||||
if (paletteBank.has_value() && ts.defaultPalette) {
|
||||
oxReturnError(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||
OX_RETURN_ERROR(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -615,7 +615,7 @@ ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
TileSheetSet const&set) noexcept {
|
||||
oxRequire(setTsd, buildSetTsd(ctx, set));
|
||||
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
|
||||
ctx.cbbs[cbb].tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
||||
return {};
|
||||
}
|
||||
@@ -624,11 +624,11 @@ ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
CompactTileSheet const&ts,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
oxRequire(tsd, normalizeTileSheet(ts));
|
||||
OX_REQUIRE(tsd, normalizeTileSheet(ts));
|
||||
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
|
||||
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
|
||||
if (loadDefaultPalette) {
|
||||
oxReturnError(loadSpritePalette(ctx, ts.defaultPalette));
|
||||
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -636,7 +636,7 @@ ox::Error loadSpriteTileSheet(
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
TileSheetSet const&set) noexcept {
|
||||
oxRequire(setTsd, buildSetTsd(ctx, set));
|
||||
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
|
||||
ctx.spriteBlocks.tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
||||
return {};
|
||||
}
|
||||
|
@@ -1,5 +1,13 @@
|
||||
target_sources(
|
||||
NostalgiaCore-Studio PRIVATE
|
||||
paletteeditor.cpp
|
||||
commands/addcolorcommand.cpp
|
||||
commands/applycolorallpagescommand.cpp
|
||||
commands/duplicatepagecommand.cpp
|
||||
commands/movecolorcommand.cpp
|
||||
commands/removecolorcommand.cpp
|
||||
commands/removepagecommand.cpp
|
||||
commands/renamepagecommand.cpp
|
||||
commands/updatecolorcommand.cpp
|
||||
commands/updatecolorinfocommand.cpp
|
||||
paletteeditor-imgui.cpp
|
||||
)
|
||||
|
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "addcolorcommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
AddColorCommand::AddColorCommand(Palette &pal, Color16 const color, size_t const idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_color(color),
|
||||
m_idx(idx) {}
|
||||
|
||||
int AddColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::AddColor);
|
||||
}
|
||||
|
||||
ox::Error AddColorCommand::redo() noexcept {
|
||||
m_pal.colorNames.emplace(m_idx, ox::sfmt("Color {}", m_pal.colorNames.size() + 1));
|
||||
for (auto &page : m_pal.pages) {
|
||||
page.colors.emplace(m_idx, m_color);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error AddColorCommand::undo() noexcept {
|
||||
OX_RETURN_ERROR(m_pal.colorNames.erase(m_idx));
|
||||
for (auto &page : m_pal.pages) {
|
||||
OX_RETURN_ERROR(page.colors.erase(m_idx));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class AddColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
Color16 m_color = 0;
|
||||
size_t const m_idx = 0;
|
||||
|
||||
public:
|
||||
AddColorCommand(Palette &pal, Color16 color, size_t idx) noexcept;
|
||||
|
||||
~AddColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "applycolorallpagescommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ApplyColorAllPagesCommand::ApplyColorAllPagesCommand(Palette &pal, size_t const page, size_t const idx):
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_idx(idx),
|
||||
m_origColors([this] {
|
||||
ox::Vector<Color16> colors;
|
||||
colors.reserve(m_pal.pages.size());
|
||||
for (auto const&p : m_pal.pages) {
|
||||
colors.emplace_back(p.colors[m_idx]);
|
||||
}
|
||||
return colors;
|
||||
}()) {
|
||||
auto const c = color(m_pal, m_page, m_idx);
|
||||
if (ox::all_of(m_pal.pages.begin(), m_pal.pages.end(), [this, c](PalettePage const&page) {
|
||||
return page.colors[m_idx] == c;
|
||||
})) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
int ApplyColorAllPagesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::ApplyColorAllPages);
|
||||
}
|
||||
|
||||
ox::Error ApplyColorAllPagesCommand::redo() noexcept {
|
||||
auto const c = color(m_pal, m_page, m_idx);
|
||||
for (auto &page : m_pal.pages) {
|
||||
page.colors[m_idx] = c;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error ApplyColorAllPagesCommand::undo() noexcept {
|
||||
for (size_t p = 0u; auto &page : m_pal.pages) {
|
||||
page.colors[m_idx] = m_origColors[p];
|
||||
++p;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class ApplyColorAllPagesCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page{};
|
||||
size_t const m_idx{};
|
||||
ox::Vector<Color16> const m_origColors;
|
||||
|
||||
public:
|
||||
ApplyColorAllPagesCommand(Palette &pal, size_t page, size_t idx);
|
||||
|
||||
~ApplyColorAllPagesCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
enum class PaletteEditorCommandId {
|
||||
ApplyColorAllPages,
|
||||
RenamePage,
|
||||
DuplicatePage,
|
||||
RemovePage,
|
||||
AddColor,
|
||||
RemoveColor,
|
||||
UpdateColorInfo,
|
||||
UpdateColor,
|
||||
MoveColor,
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
#include "duplicatepagecommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
DuplicatePageCommand::DuplicatePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_dstIdx(dstIdx) {
|
||||
auto const&src = m_pal.pages[srcIdx];
|
||||
m_page.reserve(src.colors.size());
|
||||
for (auto const&s : src.colors) {
|
||||
m_page.emplace_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
int DuplicatePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::DuplicatePage);
|
||||
}
|
||||
|
||||
ox::Error DuplicatePageCommand::redo() noexcept {
|
||||
m_pal.pages.emplace(m_dstIdx, "", std::move(m_page));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error DuplicatePageCommand::undo() noexcept {
|
||||
m_page = std::move(m_pal.pages[m_dstIdx].colors);
|
||||
return m_pal.pages.erase(m_dstIdx).error;
|
||||
}
|
||||
|
||||
size_t DuplicatePageCommand::insertIdx() const noexcept {
|
||||
return m_dstIdx;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class DuplicatePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_dstIdx = 0;
|
||||
ox::Vector<PaletteColor> m_page;
|
||||
|
||||
public:
|
||||
DuplicatePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~DuplicatePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t insertIdx() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
#include "movecolorcommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
MoveColorCommand::MoveColorCommand(
|
||||
Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_srcIdx(srcIdx),
|
||||
m_dstIdx(dstIdx) {}
|
||||
|
||||
int MoveColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::MoveColor);
|
||||
}
|
||||
|
||||
ox::Error MoveColorCommand::redo() noexcept {
|
||||
moveColor(m_srcIdx, m_dstIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error MoveColorCommand::undo() noexcept {
|
||||
moveColor(m_dstIdx, m_srcIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
void MoveColorCommand::moveColor(size_t srcIdx, size_t dstIdx) noexcept {
|
||||
auto const c = color(m_pal, m_page, srcIdx);
|
||||
std::ignore = colors(m_pal, m_page).erase(srcIdx);
|
||||
colors(m_pal, m_page).emplace(dstIdx, c);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class MoveColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page = 0;
|
||||
std::size_t const m_srcIdx = 0;
|
||||
std::size_t const m_dstIdx = 0;
|
||||
|
||||
public:
|
||||
MoveColorCommand(Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~MoveColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
private:
|
||||
void moveColor(size_t srcIdx, size_t dstIdx) noexcept;
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "removecolorcommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
RemoveColorCommand::RemoveColorCommand(Palette &pal, size_t const idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_idx(idx),
|
||||
m_colors([this] {
|
||||
ox::Vector<Color16> colors;
|
||||
colors.reserve(m_pal.pages.size());
|
||||
for (auto const&p : m_pal.pages) {
|
||||
colors.emplace_back(p.colors[m_idx]);
|
||||
}
|
||||
return colors;
|
||||
}()) {}
|
||||
|
||||
int RemoveColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RemoveColor);
|
||||
}
|
||||
|
||||
ox::Error RemoveColorCommand::redo() noexcept {
|
||||
m_colorInfo = std::move(m_pal.colorNames[m_idx]);
|
||||
OX_RETURN_ERROR(m_pal.colorNames.erase(m_idx));
|
||||
for (auto &page : m_pal.pages) {
|
||||
OX_RETURN_ERROR(page.colors.erase(m_idx));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RemoveColorCommand::undo() noexcept {
|
||||
m_pal.colorNames.emplace(m_idx, std::move(m_colorInfo));
|
||||
for (size_t p = 0; auto &page : m_pal.pages) {
|
||||
page.colors.emplace(m_idx, m_colors[p]);
|
||||
++p;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class RemoveColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_idx = 0;
|
||||
ox::String m_colorInfo;
|
||||
ox::Vector<Color16> const m_colors;
|
||||
|
||||
public:
|
||||
RemoveColorCommand(Palette &pal, size_t idx) noexcept;
|
||||
|
||||
~RemoveColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
#include "removepagecommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
RemovePageCommand::RemovePageCommand(Palette &pal, size_t idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_idx(idx) {}
|
||||
|
||||
int RemovePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RemovePage);
|
||||
}
|
||||
|
||||
ox::Error RemovePageCommand::redo() noexcept {
|
||||
m_page = std::move(m_pal.pages[m_idx]);
|
||||
return m_pal.pages.erase(m_idx).error;
|
||||
}
|
||||
|
||||
ox::Error RemovePageCommand::undo() noexcept {
|
||||
m_pal.pages.emplace(m_idx, std::move(m_page));
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class RemovePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_idx = 0;
|
||||
PalettePage m_page;
|
||||
|
||||
public:
|
||||
RemovePageCommand(Palette &pal, size_t idx) noexcept;
|
||||
|
||||
~RemovePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "renamepagecommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
RenamePageCommand::RenamePageCommand(Palette &pal, size_t const page, ox::StringParam name) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_name{std::move(name)} {}
|
||||
|
||||
int RenamePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RenamePage);
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::redo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::undo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class RenamePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_page = 0;
|
||||
ox::String m_name;
|
||||
|
||||
public:
|
||||
RenamePageCommand(Palette &pal, size_t page, ox::StringParam name) noexcept;
|
||||
|
||||
~RenamePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "updatecolorcommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
UpdateColorCommand::UpdateColorCommand(
|
||||
Palette &pal,
|
||||
size_t page,
|
||||
size_t idx,
|
||||
Color16 newColor):
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_idx(idx),
|
||||
m_altColor(newColor) {
|
||||
if (color(m_pal, m_page, m_idx) == newColor) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
bool UpdateColorCommand::mergeWith(UndoCommand &cmd) noexcept {
|
||||
if (cmd.commandId() != static_cast<int>(PaletteEditorCommandId::UpdateColor)) {
|
||||
return false;
|
||||
}
|
||||
auto ucCmd = dynamic_cast<UpdateColorCommand const*>(&cmd);
|
||||
if (m_idx != ucCmd->m_idx) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::UpdateColor);
|
||||
}
|
||||
|
||||
ox::Error UpdateColorCommand::redo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error UpdateColorCommand::undo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
void UpdateColorCommand::swap() noexcept {
|
||||
auto &dst = colors(m_pal, m_page)[m_idx];
|
||||
std::swap(dst, m_altColor);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class UpdateColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page = 0;
|
||||
size_t const m_idx{};
|
||||
PaletteColor m_altColor{};
|
||||
|
||||
public:
|
||||
UpdateColorCommand(
|
||||
Palette &pal,
|
||||
size_t page,
|
||||
size_t idx,
|
||||
Color16 newColor);
|
||||
|
||||
~UpdateColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
bool mergeWith(UndoCommand &cmd) noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "updatecolorinfocommand.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
UpdateColorInfoCommand::UpdateColorInfoCommand(
|
||||
Palette &pal,
|
||||
size_t idx,
|
||||
ox::StringParam newColorInfo):
|
||||
m_pal(pal),
|
||||
m_idx(idx),
|
||||
m_altColorInfo(std::move(newColorInfo)) {
|
||||
if (m_pal.colorNames[m_idx] == m_altColorInfo) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
bool UpdateColorInfoCommand::mergeWith(UndoCommand &cmd) noexcept {
|
||||
if (cmd.commandId() != static_cast<int>(PaletteEditorCommandId::UpdateColorInfo)) {
|
||||
return false;
|
||||
}
|
||||
auto ucCmd = dynamic_cast<UpdateColorInfoCommand const*>(&cmd);
|
||||
if (m_idx != ucCmd->m_idx) {
|
||||
return false;
|
||||
}
|
||||
m_pal.colorNames[m_idx] = std::move(ucCmd->m_pal.colorNames[m_idx]);
|
||||
setObsolete(m_altColorInfo == m_pal.colorNames[m_idx]);
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateColorInfoCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::UpdateColorInfo);
|
||||
}
|
||||
|
||||
ox::Error UpdateColorInfoCommand::redo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error UpdateColorInfoCommand::undo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
void UpdateColorInfoCommand::swap() noexcept {
|
||||
std::swap(m_pal.colorNames[m_idx], m_altColorInfo);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
class UpdateColorInfoCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_idx{};
|
||||
ox::String m_altColorInfo;
|
||||
|
||||
public:
|
||||
UpdateColorInfoCommand(
|
||||
Palette &pal,
|
||||
size_t idx,
|
||||
ox::StringParam newColorInfo);
|
||||
|
||||
~UpdateColorInfoCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
bool mergeWith(UndoCommand &cmd) noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -6,9 +6,16 @@
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include "commands/addcolorcommand.hpp"
|
||||
#include "commands/applycolorallpagescommand.hpp"
|
||||
#include "commands/duplicatepagecommand.hpp"
|
||||
#include "commands/movecolorcommand.hpp"
|
||||
#include "commands/removecolorcommand.hpp"
|
||||
#include "commands/removepagecommand.hpp"
|
||||
#include "commands/renamepagecommand.hpp"
|
||||
#include "commands/updatecolorcommand.hpp"
|
||||
#include "commands/updatecolorinfocommand.hpp"
|
||||
|
||||
#include "paletteeditor.hpp"
|
||||
#include "paletteeditor-imgui.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
@@ -16,7 +23,7 @@ namespace nostalgia::core {
|
||||
namespace ig = studio::ig;
|
||||
|
||||
|
||||
void PaletteEditorImGui::PageRename::draw(turbine::Context &tctx) noexcept {
|
||||
void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept {
|
||||
if (!m_show) {
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +49,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
m_tctx(sctx.tctx),
|
||||
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {
|
||||
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
|
||||
m_pageRename.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
@@ -58,7 +65,7 @@ void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
drawColorsEditor();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
m_pageRename.draw(m_tctx);
|
||||
m_pageRenameDlg.draw(m_tctx);
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||
@@ -203,7 +210,7 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rename", btnSz)) {
|
||||
m_pageRename.show(m_pal.pages[m_page].name);
|
||||
m_pageRenameDlg.show(m_pal.pages[m_page].name);
|
||||
}
|
||||
ImGui::BeginTable(
|
||||
"PageSelect",
|
||||
@@ -245,7 +252,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
|
||||
m_pal, m_page, m_selectedColorRow);
|
||||
}
|
||||
if (!inputFocused && !m_pageRename.isOpen()) {
|
||||
if (!inputFocused && !m_pageRenameDlg.isOpen()) {
|
||||
if (!ImGui::IsKeyDown(ImGuiKey_ModAlt)) {
|
||||
numShortcuts(m_selectedColorRow, largestPage(m_pal));
|
||||
} else {
|
||||
@@ -258,7 +265,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
}
|
||||
if (newName) {
|
||||
std::ignore = pushCommand<UpdateColorInfoCommand>(
|
||||
m_pal, m_selectedColorRow, ox::String{newName});
|
||||
m_pal, m_selectedColorRow, static_cast<ox::String>(newName.text));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ namespace nostalgia::core {
|
||||
class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
class PageRename {
|
||||
class PageRenameDialog {
|
||||
private:
|
||||
ox::IString<50> m_name;
|
||||
bool m_show = false;
|
||||
@@ -30,7 +30,7 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
[[nodiscard]]
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
void draw(turbine::Context &tctx) noexcept;
|
||||
} m_pageRename;
|
||||
} m_pageRenameDlg;
|
||||
studio::StudioContext &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
Palette m_pal;
|
||||
|
@@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "paletteeditor.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ApplyColorAllPagesCommand::ApplyColorAllPagesCommand(Palette &pal, size_t const page, size_t const idx):
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_idx(idx),
|
||||
m_origColors([this] {
|
||||
ox::Vector<Color16> colors;
|
||||
colors.reserve(m_pal.pages.size());
|
||||
for (auto const&p : m_pal.pages) {
|
||||
colors.emplace_back(p.colors[m_idx]);
|
||||
}
|
||||
return colors;
|
||||
}()) {
|
||||
auto const c = color(m_pal, m_page, m_idx);
|
||||
if (ox::all_of(m_pal.pages.begin(), m_pal.pages.end(), [this, c](PalettePage const&page) {
|
||||
return page.colors[m_idx] == c;
|
||||
})) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
int ApplyColorAllPagesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::ApplyColorAllPages);
|
||||
}
|
||||
|
||||
ox::Error ApplyColorAllPagesCommand::redo() noexcept {
|
||||
auto const c = color(m_pal, m_page, m_idx);
|
||||
for (auto &page : m_pal.pages) {
|
||||
page.colors[m_idx] = c;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error ApplyColorAllPagesCommand::undo() noexcept {
|
||||
for (size_t p = 0u; auto &page : m_pal.pages) {
|
||||
page.colors[m_idx] = m_origColors[p];
|
||||
++p;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
RenamePageCommand::RenamePageCommand(Palette &pal, size_t const page, ox::StringParam name) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_name{std::move(name)} {}
|
||||
|
||||
int RenamePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RenamePage);
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::redo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::undo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
DuplicatePageCommand::DuplicatePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_dstIdx(dstIdx) {
|
||||
auto const&src = m_pal.pages[srcIdx];
|
||||
m_page.reserve(src.colors.size());
|
||||
for (auto const&s : src.colors) {
|
||||
m_page.emplace_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
int DuplicatePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::DuplicatePage);
|
||||
}
|
||||
|
||||
ox::Error DuplicatePageCommand::redo() noexcept {
|
||||
m_pal.pages.emplace(m_dstIdx, "", std::move(m_page));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error DuplicatePageCommand::undo() noexcept {
|
||||
m_page = std::move(m_pal.pages[m_dstIdx].colors);
|
||||
return m_pal.pages.erase(m_dstIdx).error;
|
||||
}
|
||||
|
||||
size_t DuplicatePageCommand::insertIdx() const noexcept {
|
||||
return m_dstIdx;
|
||||
}
|
||||
|
||||
|
||||
RemovePageCommand::RemovePageCommand(Palette &pal, size_t idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_idx(idx) {}
|
||||
|
||||
int RemovePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RemovePage);
|
||||
}
|
||||
|
||||
ox::Error RemovePageCommand::redo() noexcept {
|
||||
m_page = std::move(m_pal.pages[m_idx]);
|
||||
return m_pal.pages.erase(m_idx).error;
|
||||
}
|
||||
|
||||
ox::Error RemovePageCommand::undo() noexcept {
|
||||
m_pal.pages.emplace(m_idx, std::move(m_page));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
AddColorCommand::AddColorCommand(Palette &pal, Color16 const color, size_t const idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_color(color),
|
||||
m_idx(idx) {}
|
||||
|
||||
int AddColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::AddColor);
|
||||
}
|
||||
|
||||
ox::Error AddColorCommand::redo() noexcept {
|
||||
m_pal.colorNames.emplace(m_idx, ox::sfmt("Color {}", m_pal.colorNames.size() + 1));
|
||||
for (auto &page : m_pal.pages) {
|
||||
page.colors.emplace(m_idx, m_color);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error AddColorCommand::undo() noexcept {
|
||||
oxReturnError(m_pal.colorNames.erase(m_idx));
|
||||
for (auto &page : m_pal.pages) {
|
||||
oxReturnError(page.colors.erase(m_idx));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
RemoveColorCommand::RemoveColorCommand(Palette &pal, size_t const idx) noexcept:
|
||||
m_pal(pal),
|
||||
m_idx(idx),
|
||||
m_colors([this] {
|
||||
ox::Vector<Color16> colors;
|
||||
colors.reserve(m_pal.pages.size());
|
||||
for (auto const&p : m_pal.pages) {
|
||||
colors.emplace_back(p.colors[m_idx]);
|
||||
}
|
||||
return colors;
|
||||
}()) {}
|
||||
|
||||
int RemoveColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RemoveColor);
|
||||
}
|
||||
|
||||
ox::Error RemoveColorCommand::redo() noexcept {
|
||||
m_colorInfo = std::move(m_pal.colorNames[m_idx]);
|
||||
oxReturnError(m_pal.colorNames.erase(m_idx));
|
||||
for (auto &page : m_pal.pages) {
|
||||
oxReturnError(page.colors.erase(m_idx));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RemoveColorCommand::undo() noexcept {
|
||||
m_pal.colorNames.emplace(m_idx, std::move(m_colorInfo));
|
||||
for (size_t p = 0; auto &page : m_pal.pages) {
|
||||
page.colors.emplace(m_idx, m_colors[p]);
|
||||
++p;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
UpdateColorInfoCommand::UpdateColorInfoCommand(
|
||||
Palette &pal,
|
||||
size_t idx,
|
||||
ox::StringParam newColorInfo):
|
||||
m_pal(pal),
|
||||
m_idx(idx),
|
||||
m_altColorInfo(std::move(newColorInfo)) {
|
||||
if (m_pal.colorNames[m_idx] == m_altColorInfo) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
bool UpdateColorInfoCommand::mergeWith(UndoCommand &cmd) noexcept {
|
||||
if (cmd.commandId() != static_cast<int>(PaletteEditorCommandId::UpdateColorInfo)) {
|
||||
return false;
|
||||
}
|
||||
auto ucCmd = dynamic_cast<UpdateColorInfoCommand const*>(&cmd);
|
||||
if (m_idx != ucCmd->m_idx) {
|
||||
return false;
|
||||
}
|
||||
m_pal.colorNames[m_idx] = std::move(ucCmd->m_pal.colorNames[m_idx]);
|
||||
setObsolete(m_altColorInfo == m_pal.colorNames[m_idx]);
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateColorInfoCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::UpdateColorInfo);
|
||||
}
|
||||
|
||||
ox::Error UpdateColorInfoCommand::redo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error UpdateColorInfoCommand::undo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
void UpdateColorInfoCommand::swap() noexcept {
|
||||
std::swap(m_pal.colorNames[m_idx], m_altColorInfo);
|
||||
}
|
||||
|
||||
|
||||
UpdateColorCommand::UpdateColorCommand(
|
||||
Palette &pal,
|
||||
size_t page,
|
||||
size_t idx,
|
||||
Color16 newColor):
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_idx(idx),
|
||||
m_altColor(newColor) {
|
||||
if (color(m_pal, m_page, m_idx) == newColor) {
|
||||
throw studio::NoChangesException();
|
||||
}
|
||||
}
|
||||
|
||||
bool UpdateColorCommand::mergeWith(UndoCommand &cmd) noexcept {
|
||||
if (cmd.commandId() != static_cast<int>(PaletteEditorCommandId::UpdateColor)) {
|
||||
return false;
|
||||
}
|
||||
auto ucCmd = dynamic_cast<UpdateColorCommand const*>(&cmd);
|
||||
if (m_idx != ucCmd->m_idx) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::UpdateColor);
|
||||
}
|
||||
|
||||
ox::Error UpdateColorCommand::redo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error UpdateColorCommand::undo() noexcept {
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
void UpdateColorCommand::swap() noexcept {
|
||||
auto &dst = colors(m_pal, m_page)[m_idx];
|
||||
std::swap(dst, m_altColor);
|
||||
}
|
||||
|
||||
|
||||
MoveColorCommand::MoveColorCommand(
|
||||
Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_srcIdx(srcIdx),
|
||||
m_dstIdx(dstIdx) {}
|
||||
|
||||
int MoveColorCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::MoveColor);
|
||||
}
|
||||
|
||||
ox::Error MoveColorCommand::redo() noexcept {
|
||||
moveColor(m_srcIdx, m_dstIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error MoveColorCommand::undo() noexcept {
|
||||
moveColor(m_dstIdx, m_srcIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
void MoveColorCommand::moveColor(size_t srcIdx, size_t dstIdx) noexcept {
|
||||
auto const c = color(m_pal, m_page, srcIdx);
|
||||
std::ignore = colors(m_pal, m_page).erase(srcIdx);
|
||||
colors(m_pal, m_page).emplace(dstIdx, c);
|
||||
}
|
||||
|
||||
}
|
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/core/color.hpp>
|
||||
#include <nostalgia/core/palette.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
enum class PaletteEditorCommandId {
|
||||
ApplyColorAllPages,
|
||||
RenamePage,
|
||||
DuplicatePage,
|
||||
RemovePage,
|
||||
AddColor,
|
||||
RemoveColor,
|
||||
UpdateColorInfo,
|
||||
UpdateColor,
|
||||
MoveColor,
|
||||
};
|
||||
|
||||
|
||||
class ApplyColorAllPagesCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page{};
|
||||
size_t const m_idx{};
|
||||
ox::Vector<Color16> const m_origColors;
|
||||
|
||||
public:
|
||||
ApplyColorAllPagesCommand(Palette &pal, size_t page, size_t idx);
|
||||
|
||||
~ApplyColorAllPagesCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
};
|
||||
|
||||
class RenamePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_page = 0;
|
||||
ox::String m_name;
|
||||
|
||||
public:
|
||||
RenamePageCommand(Palette &pal, size_t page, ox::StringParam name) noexcept;
|
||||
|
||||
~RenamePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
class DuplicatePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_dstIdx = 0;
|
||||
ox::Vector<PaletteColor> m_page;
|
||||
|
||||
public:
|
||||
DuplicatePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~DuplicatePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t insertIdx() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
class RemovePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_idx = 0;
|
||||
PalettePage m_page;
|
||||
|
||||
public:
|
||||
RemovePageCommand(Palette &pal, size_t idx) noexcept;
|
||||
|
||||
~RemovePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
class AddColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
Color16 m_color = 0;
|
||||
size_t const m_idx = 0;
|
||||
|
||||
public:
|
||||
AddColorCommand(Palette &pal, Color16 color, size_t idx) noexcept;
|
||||
|
||||
~AddColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
};
|
||||
|
||||
class RemoveColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_idx = 0;
|
||||
ox::String m_colorInfo;
|
||||
ox::Vector<Color16> const m_colors;
|
||||
|
||||
public:
|
||||
RemoveColorCommand(Palette &pal, size_t idx) noexcept;
|
||||
|
||||
~RemoveColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
};
|
||||
|
||||
class UpdateColorInfoCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_idx{};
|
||||
ox::String m_altColorInfo;
|
||||
|
||||
public:
|
||||
UpdateColorInfoCommand(
|
||||
Palette &pal,
|
||||
size_t idx,
|
||||
ox::StringParam newColorInfo);
|
||||
|
||||
~UpdateColorInfoCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
bool mergeWith(UndoCommand &cmd) noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
class UpdateColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page = 0;
|
||||
size_t const m_idx{};
|
||||
PaletteColor m_altColor{};
|
||||
|
||||
public:
|
||||
UpdateColorCommand(
|
||||
Palette &pal,
|
||||
size_t page,
|
||||
size_t idx,
|
||||
Color16 newColor);
|
||||
|
||||
~UpdateColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
bool mergeWith(UndoCommand &cmd) noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
class MoveColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page = 0;
|
||||
std::size_t const m_srcIdx = 0;
|
||||
std::size_t const m_dstIdx = 0;
|
||||
|
||||
public:
|
||||
MoveColorCommand(Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~MoveColorCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
private:
|
||||
void moveColor(size_t srcIdx, size_t dstIdx) noexcept;
|
||||
};
|
||||
|
||||
}
|
@@ -25,7 +25,7 @@ static class: public studio::Module {
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", FileExt_npal));
|
||||
return out;
|
||||
}
|
||||
} mod;
|
||||
} const mod;
|
||||
|
||||
const studio::Module *studioModule() noexcept {
|
||||
return &mod;
|
||||
|
@@ -49,7 +49,7 @@ ox::Error AddSubSheetCommand::undo() noexcept {
|
||||
--m_img.idIt;
|
||||
} else {
|
||||
for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) {
|
||||
oxReturnError(rmSubSheet(m_img, *idx));
|
||||
OX_RETURN_ERROR(rmSubSheet(m_img, *idx));
|
||||
--m_img.idIt;
|
||||
}
|
||||
}
|
||||
|
@@ -10,14 +10,14 @@
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
oxModelFwdDecl(class TileSheetClipboard);
|
||||
OX_MODEL_FWD_DECL(class TileSheetClipboard);
|
||||
|
||||
class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||
public:
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
oxModelFriend(TileSheetClipboard);
|
||||
OX_MODEL_FRIEND(TileSheetClipboard);
|
||||
|
||||
struct Pixel {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel";
|
||||
@@ -36,14 +36,14 @@ class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||
ox::Vector<Pixel> const&pixels() const noexcept;
|
||||
};
|
||||
|
||||
oxModelBegin(TileSheetClipboard::Pixel)
|
||||
oxModelField(colorIdx)
|
||||
oxModelField(pt)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetClipboard::Pixel)
|
||||
OX_MODEL_FIELD(colorIdx)
|
||||
OX_MODEL_FIELD(pt)
|
||||
OX_MODEL_END()
|
||||
|
||||
oxModelBegin(TileSheetClipboard)
|
||||
oxModelFieldRename(m_pixels, pixels)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetClipboard)
|
||||
OX_MODEL_FIELD_RENAME(m_pixels, pixels)
|
||||
OX_MODEL_END()
|
||||
|
||||
class CutPasteCommand: public TileSheetCommand {
|
||||
private:
|
||||
|
@@ -16,7 +16,7 @@ core::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetId
|
||||
ox::Error RmSubSheetCommand::redo() noexcept {
|
||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||
m_sheet = std::move(parent.subsheets[*m_idx.back().value]);
|
||||
oxReturnError(parent.subsheets.erase(*m_idx.back().value).error);
|
||||
OX_RETURN_ERROR(parent.subsheets.erase(*m_idx.back().value).error);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -21,9 +21,9 @@ struct TileSheetEditorConfig {
|
||||
TileSheet::SubSheetIdx activeSubsheet{};
|
||||
};
|
||||
|
||||
oxModelBegin(TileSheetEditorConfig)
|
||||
oxModelFieldRename(activeSubsheet, active_subsheet)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileSheetEditorConfig)
|
||||
OX_MODEL_FIELD_RENAME(activeSubsheet, active_subsheet)
|
||||
OX_MODEL_END()
|
||||
|
||||
static ox::Vector<uint32_t> normalizePixelSizes(
|
||||
ox::Vector<uint8_t> const&inPixels,
|
||||
@@ -76,7 +76,7 @@ static ox::Error toPngFile(
|
||||
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
|
||||
}
|
||||
constexpr auto fmt = LCT_RGBA;
|
||||
return OxError(static_cast<ox::ErrorCode>(
|
||||
return ox::Error(static_cast<ox::ErrorCode>(
|
||||
lodepng_encode_file(
|
||||
path.c_str(),
|
||||
reinterpret_cast<uint8_t const*>(pixels.data()),
|
||||
@@ -94,7 +94,6 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::Stri
|
||||
m_model(m_view.model()) {
|
||||
std::ignore = setPaletteSelection();
|
||||
// connect signal/slots
|
||||
undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges);
|
||||
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
|
||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
|
||||
m_model.paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
|
||||
@@ -196,7 +195,7 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
}
|
||||
}
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
auto const tileSheetParentSize = ImVec2{paneSize.x - m_palViewWidth, paneSize.y};
|
||||
auto const tileSheetParentSize = ImVec2{paneSize.x - s_palViewWidth, paneSize.y};
|
||||
auto const fbSize = ox::Vec2{tileSheetParentSize.x - 16, tileSheetParentSize.y - 16};
|
||||
ImGui::BeginChild("TileSheetView", tileSheetParentSize, true);
|
||||
{
|
||||
@@ -204,10 +203,10 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("Controls", {m_palViewWidth - 8, paneSize.y}, true);
|
||||
ImGui::BeginChild("Controls", {s_palViewWidth - 8, paneSize.y}, true);
|
||||
{
|
||||
auto const controlsSize = ImGui::GetContentRegionAvail();
|
||||
ImGui::BeginChild("ToolBox", {m_palViewWidth - 24, 30}, true);
|
||||
ImGui::BeginChild("ToolBox", {s_palViewWidth - 24, 30}, true);
|
||||
{
|
||||
auto const btnSz = ImVec2{45, 14};
|
||||
if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) {
|
||||
@@ -227,12 +226,12 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
ImGui::EndChild();
|
||||
auto const ySize = controlsSize.y - 38;
|
||||
// draw palette/color picker
|
||||
ImGui::BeginChild("Palette", {m_palViewWidth - 24, ySize / 2.f}, true);
|
||||
ImGui::BeginChild("Palette", {s_palViewWidth - 24, ySize / 2.f}, true);
|
||||
{
|
||||
drawPaletteSelector();
|
||||
drawPaletteMenu();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("SubSheets", {m_palViewWidth - 24, ySize / 2.f}, true);
|
||||
ImGui::BeginChild("SubSheets", {s_palViewWidth - 24, ySize / 2.f}, true);
|
||||
{
|
||||
static constexpr auto btnHeight = ig::BtnSz.y;
|
||||
auto const btnSize = ImVec2{btnHeight, btnHeight};
|
||||
@@ -347,7 +346,7 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
||||
oxRequire(path, studio::saveFile({{"PNG", "png"}}));
|
||||
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
|
||||
// subsheet to png
|
||||
auto const&img = m_model.img();
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
@@ -434,7 +433,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::drawPaletteSelector() noexcept {
|
||||
void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
auto const&files = m_sctx.project->fileList(core::FileExt_npal);
|
||||
auto const comboWidthSub = 62;
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
|
||||
@@ -474,6 +473,7 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
|
||||
auto const&pal = m_model.pal();
|
||||
if (pal.pages.size() > m_model.palettePage()) {
|
||||
for (auto i = 0u; auto const&c: pal.pages[m_model.palettePage()].colors) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
// Column: color idx
|
||||
ImGui::TableNextColumn();
|
||||
@@ -492,7 +492,6 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
|
||||
ImGui::Text("%s", name);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("(%02d, %02d, %02d)", red16(c), green16(c), blue16(c));
|
||||
ImGui::TableNextRow();
|
||||
ImGui::PopID();
|
||||
++i;
|
||||
}
|
||||
@@ -527,9 +526,12 @@ void TileSheetEditorImGui::setActiveSubsheet(TileSheet::SubSheetIdx path) noexce
|
||||
});
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::markUnsavedChanges(studio::UndoCommand const*) noexcept {
|
||||
setUnsavedChanges(true);
|
||||
return {};
|
||||
|
||||
void TileSheetEditorImGui::SubSheetEditor::show(ox::StringViewCR name, int const cols, int const rows) noexcept {
|
||||
m_show = true;
|
||||
m_name = name;
|
||||
m_cols = cols;
|
||||
m_rows = rows;
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &tctx) noexcept {
|
||||
@@ -558,6 +560,12 @@ void TileSheetEditorImGui::SubSheetEditor::close() noexcept {
|
||||
m_show = false;
|
||||
}
|
||||
|
||||
|
||||
void TileSheetEditorImGui::ExportMenu::show() noexcept {
|
||||
m_show = true;
|
||||
m_scale = 5;
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &tctx) noexcept {
|
||||
constexpr auto popupName = "Export Tile Sheet";
|
||||
if (!m_show) {
|
||||
|
@@ -26,17 +26,12 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
int m_rows = 0;
|
||||
bool m_show = false;
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringView const&name, int cols, int rows)> inputSubmitted;
|
||||
constexpr void show(ox::StringView const&name, int cols, int rows) noexcept {
|
||||
m_show = true;
|
||||
m_name = name;
|
||||
m_cols = cols;
|
||||
m_rows = rows;
|
||||
}
|
||||
ox::Signal<ox::Error(ox::StringViewCR name, int cols, int rows)> inputSubmitted;
|
||||
void show(ox::StringViewCR name, int cols, int rows) noexcept;
|
||||
void draw(turbine::Context &sctx) noexcept;
|
||||
void close() noexcept;
|
||||
[[nodiscard]]
|
||||
inline bool isOpen() const noexcept { return m_show; }
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
};
|
||||
class ExportMenu {
|
||||
private:
|
||||
@@ -44,15 +39,13 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
bool m_show = false;
|
||||
public:
|
||||
ox::Signal<ox::Error(int scale)> inputSubmitted;
|
||||
constexpr void show() noexcept {
|
||||
m_show = true;
|
||||
m_scale = 5;
|
||||
}
|
||||
void show() noexcept;
|
||||
void draw(turbine::Context &sctx) noexcept;
|
||||
void close() noexcept;
|
||||
[[nodiscard]]
|
||||
inline bool isOpen() const noexcept { return m_show; }
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
};
|
||||
static constexpr float s_palViewWidth = 300;
|
||||
std::size_t m_selectedPaletteIdx = 0;
|
||||
studio::StudioContext &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
@@ -62,7 +55,6 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
glutils::FrameBuffer m_framebuffer;
|
||||
TileSheetEditorView m_view;
|
||||
TileSheetEditorModel &m_model;
|
||||
float m_palViewWidth = 300;
|
||||
ox::Vec2 m_prevMouseDownPos;
|
||||
TileSheetTool m_tool = TileSheetTool::Draw;
|
||||
|
||||
@@ -101,7 +93,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
|
||||
void drawTileSheet(ox::Vec2 const&fbSize) noexcept;
|
||||
|
||||
void drawPaletteSelector() noexcept;
|
||||
void drawPaletteMenu() noexcept;
|
||||
|
||||
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
|
||||
|
||||
@@ -109,8 +101,6 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
|
||||
// slots
|
||||
private:
|
||||
ox::Error markUnsavedChanges(studio::UndoCommand const*) noexcept;
|
||||
|
||||
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;
|
||||
|
||||
};
|
||||
|
@@ -132,7 +132,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept {
|
||||
oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path));
|
||||
OX_REQUIRE(uuid, keelCtx(m_tctx).pathToUuid.at(path));
|
||||
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
|
||||
return {};
|
||||
}
|
||||
@@ -190,16 +190,16 @@ void TileSheetEditorModel::setActiveSubsheet(TileSheet::SubSheetIdx const&idx) n
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::fill(ox::Point const&pt, int palIdx) noexcept {
|
||||
const auto &s = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
auto const&activeSubSheet = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
// build idx list
|
||||
ox::Array<bool, PixelsPerTile> updateMap = {};
|
||||
const auto oldColor = getPixel(s, m_img.bpp, pt);
|
||||
if (pt.x >= s.columns * TileWidth || pt.y >= s.rows * TileHeight) {
|
||||
if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) {
|
||||
return;
|
||||
}
|
||||
ox::Array<bool, PixelsPerTile> updateMap = {};
|
||||
auto const oldColor = getPixel(activeSubSheet, m_img.bpp, pt);
|
||||
getFillPixels(updateMap, pt, oldColor);
|
||||
ox::Vector<std::size_t> idxList;
|
||||
auto i = core::idx(s, pt) / PixelsPerTile * PixelsPerTile;
|
||||
auto i = core::idx(activeSubSheet, pt) / PixelsPerTile * PixelsPerTile;
|
||||
for (auto u : updateMap) {
|
||||
if (u) {
|
||||
idxList.emplace_back(i);
|
||||
@@ -209,7 +209,7 @@ void TileSheetEditorModel::fill(ox::Point const&pt, int palIdx) noexcept {
|
||||
// do updates to sheet
|
||||
if (m_ongoingDrawCommand) {
|
||||
m_updated = m_updated || m_ongoingDrawCommand->append(idxList);
|
||||
} else if (getPixel(s, m_img.bpp, pt) != palIdx) {
|
||||
} else if (getPixel(activeSubSheet, m_img.bpp, pt) != palIdx) {
|
||||
pushCommand(ox::make<DrawCommand>(m_img, m_activeSubsSheetIdx, idxList, palIdx));
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
|
||||
m_updated = true;
|
||||
const auto cmdId = cmd->commandId();
|
||||
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
|
||||
oxReturnError(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
|
||||
OX_RETURN_ERROR(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
|
||||
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
|
||||
paletteChanged.emit();
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::String
|
||||
m_pixelsDrawer(m_model) {
|
||||
glBindVertexArray(0);
|
||||
// build shaders
|
||||
oxThrowError(m_pixelsDrawer.buildShader());
|
||||
oxThrowError(m_pixelGridDrawer.buildShader());
|
||||
OX_THROW_ERROR(m_pixelsDrawer.buildShader());
|
||||
OX_THROW_ERROR(m_pixelGridDrawer.buildShader());
|
||||
m_model.activeSubsheetChanged.connect(this, &TileSheetEditorView::setActiveSubsheet);
|
||||
}
|
||||
|
||||
|
@@ -144,7 +144,7 @@ static ox::Error setPixelCount(ox::Vector<uint8_t> &pixels, int8_t pBpp, std::si
|
||||
sz = cnt;
|
||||
break;
|
||||
default:
|
||||
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
||||
return ox::Error(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
||||
}
|
||||
pixels.reserve(sz);
|
||||
pixels.resize(sz);
|
||||
@@ -162,7 +162,7 @@ unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
|
||||
|
||||
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept {
|
||||
ox::Vector<uint8_t> out;
|
||||
oxReturnError(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
||||
OX_RETURN_ERROR(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
||||
auto const w = ox::min<int32_t>(ss.columns, sz.width) * TileWidth;
|
||||
auto const h = ox::min<int32_t>(ss.rows, sz.height) * TileHeight;
|
||||
for (auto x = 0; x < w; ++x) {
|
||||
@@ -187,7 +187,7 @@ ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId p
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return OxError(1, "SubSheet not found");
|
||||
return ox::Error(1, "SubSheet not found");
|
||||
}
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept
|
||||
parent.subsheets.emplace_back(++ts.idIt, "Subsheet 0", parent.columns, parent.rows, ts.bpp);
|
||||
parent.subsheets.emplace_back(++ts.idIt, "Subsheet 1", 1, 1, ts.bpp);
|
||||
}
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
ox::Error rmSubSheet(
|
||||
@@ -345,7 +345,7 @@ static ox::Result<SubSheetId> getIdFor(
|
||||
return getIdFor(ss, pNamePath, pIt + 1);
|
||||
}
|
||||
}
|
||||
return OxError(1, "SubSheet not found");
|
||||
return ox::Error(1, "SubSheet not found");
|
||||
}
|
||||
|
||||
ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexcept {
|
||||
@@ -363,7 +363,7 @@ static ox::Result<unsigned> getTileOffset(
|
||||
unsigned pCurrentTotal = 0) noexcept {
|
||||
// pIt == pNamePath.size() - 1 &&
|
||||
if (ss.name != pNamePath[pIt]) {
|
||||
return OxError(2, "Wrong branch");
|
||||
return ox::Error(2, "Wrong branch");
|
||||
}
|
||||
if (pIt == pNamePath.size() - 1) {
|
||||
return pCurrentTotal;
|
||||
@@ -376,7 +376,7 @@ static ox::Result<unsigned> getTileOffset(
|
||||
}
|
||||
pCurrentTotal += pixelCnt(sub, pBpp) / PixelsPerTile;
|
||||
}
|
||||
return OxError(1, "SubSheet not found");
|
||||
return ox::Error(1, "SubSheet not found");
|
||||
}
|
||||
|
||||
ox::Result<unsigned> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept {
|
||||
|
@@ -16,8 +16,8 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
"readWriteTileSheet",
|
||||
[]() -> ox::Error {
|
||||
core::TileSheet in;
|
||||
oxRequire(buff, ox::writeMC(in));
|
||||
oxRequire(out, ox::readMC<core::TileSheet>(buff));
|
||||
OX_REQUIRE(buff, ox::writeMC(in));
|
||||
OX_REQUIRE(out, ox::readMC<core::TileSheet>(buff));
|
||||
oxAssert(in.subsheet.name == out.subsheet.name, "subsheet.name serialization broken");
|
||||
return {};
|
||||
}
|
||||
|
@@ -57,12 +57,12 @@ struct TileDoc {
|
||||
|
||||
};
|
||||
|
||||
oxModelBegin(TileDoc)
|
||||
oxModelFieldRename(subsheetId, subsheet_id)
|
||||
oxModelFieldRename(subsheetPath, subsheet_path)
|
||||
oxModelField(type)
|
||||
oxModelFieldRename(layerAttachments, layer_attachments)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(TileDoc)
|
||||
OX_MODEL_FIELD_RENAME(subsheetId, subsheet_id)
|
||||
OX_MODEL_FIELD_RENAME(subsheetPath, subsheet_path)
|
||||
OX_MODEL_FIELD(type)
|
||||
OX_MODEL_FIELD_RENAME(layerAttachments, layer_attachments)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct SceneDoc {
|
||||
|
||||
@@ -95,11 +95,11 @@ struct SceneDoc {
|
||||
}
|
||||
};
|
||||
|
||||
oxModelBegin(SceneDoc)
|
||||
oxModelField(tilesheet)
|
||||
oxModelField(palettes)
|
||||
oxModelField(tiles)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(SceneDoc)
|
||||
OX_MODEL_FIELD(tilesheet)
|
||||
OX_MODEL_FIELD(palettes)
|
||||
OX_MODEL_FIELD(tiles)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
@@ -215,14 +215,14 @@ struct SceneStatic {
|
||||
|
||||
};
|
||||
|
||||
oxModelBegin(SceneStatic)
|
||||
oxModelField(tilesheet)
|
||||
oxModelField(palettes)
|
||||
oxModelField(columns)
|
||||
oxModelField(rows)
|
||||
oxModelField(tileMapIdx)
|
||||
oxModelField(tileType)
|
||||
oxModelField(layerAttachments)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(SceneStatic)
|
||||
OX_MODEL_FIELD(tilesheet)
|
||||
OX_MODEL_FIELD(palettes)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(tileMapIdx)
|
||||
OX_MODEL_FIELD(tileType)
|
||||
OX_MODEL_FIELD(layerAttachments)
|
||||
OX_MODEL_END()
|
||||
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ ox::Error SceneDocToSceneStaticConverter::convert(
|
||||
keel::Context &ctx,
|
||||
SceneDoc &src,
|
||||
SceneStatic &dst) const noexcept {
|
||||
oxRequire(ts, keel::readObj<core::TileSheet>(ctx, src.tilesheet));
|
||||
OX_REQUIRE(ts, keel::readObj<core::TileSheet>(ctx, src.tilesheet));
|
||||
const auto layerCnt = src.tiles.size();
|
||||
dst.setLayerCnt(layerCnt);
|
||||
dst.tilesheet = ox::FileAddress(src.tilesheet);
|
||||
@@ -53,8 +53,8 @@ ox::Error SceneDocToSceneStaticConverter::convert(
|
||||
for (const auto &srcTile : row) {
|
||||
auto dstTile = dstLayer.tile(tileIdx);
|
||||
dstTile.tileType = srcTile.type;
|
||||
oxRequire(path, srcTile.getSubsheetPath(*ts));
|
||||
oxRequire(mapIdx, getTileOffset(*ts, path));
|
||||
OX_REQUIRE(path, srcTile.getSubsheetPath(*ts));
|
||||
OX_REQUIRE(mapIdx, getTileOffset(*ts, path));
|
||||
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
|
||||
setLayerAttachments(layerIdx, srcTile, dstTile);
|
||||
++tileIdx;
|
||||
|
@@ -14,11 +14,11 @@ Scene::Scene(SceneStatic const&sceneStatic) noexcept:
|
||||
|
||||
ox::Error Scene::setupDisplay(core::Context &ctx) const noexcept {
|
||||
if (m_sceneStatic.palettes.empty()) {
|
||||
return OxError(1, "Scene has no palettes");
|
||||
return ox::Error(1, "Scene has no palettes");
|
||||
}
|
||||
auto const&palette = m_sceneStatic.palettes[0];
|
||||
oxReturnError(core::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
|
||||
oxReturnError(core::loadBgPalette(ctx, 0, palette));
|
||||
OX_RETURN_ERROR(core::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
|
||||
OX_RETURN_ERROR(core::loadBgPalette(ctx, 0, palette));
|
||||
// disable all backgrounds
|
||||
core::setBgStatus(ctx, 0);
|
||||
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
|
||||
|
@@ -48,7 +48,7 @@ void SceneEditorImGui::onActivated() noexcept {
|
||||
|
||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
||||
OX_RETURN_ERROR(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user