[nostalgia] Replace most new calls with ox::make

This commit is contained in:
Gary Talent 2022-12-17 22:30:29 -06:00
parent 716b3d6022
commit 31e9af032a
5 changed files with 19 additions and 19 deletions

View File

@ -17,7 +17,7 @@ ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const
auto ctx = ox::make_unique<Context>(); auto ctx = ox::make_unique<Context>();
ctx->rom = std::move(fs); ctx->rom = std::move(fs);
ctx->appName = appName; ctx->appName = appName;
const auto id = new GlfwImplData; const auto id = ox::make<GlfwImplData>();
ctx->setWindowerData(id); ctx->setWindowerData(id);
using namespace std::chrono; using namespace std::chrono;
id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count(); id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

View File

@ -16,7 +16,7 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
{"ng"}, {"ng"},
[ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> { [ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> {
try { try {
return new TileSheetEditorImGui(ctx, path); return ox::make<TileSheetEditorImGui>(ctx, path);
} catch (const ox::Exception &ex) { } catch (const ox::Exception &ex) {
return ex.toError(); return ex.toError();
} }
@ -33,8 +33,8 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> Module::itemMakers(core::Context*) noexcept { ox::Vector<ox::UniquePtr<studio::ItemMaker>> Module::itemMakers(core::Context*) noexcept {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out; ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
out.emplace_back(new studio::ItemMakerT<core::TileSheet>("Tile Sheet", "TileSheets", "ng")); out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", "ng"));
out.emplace_back(new studio::ItemMakerT<core::Palette>("Palette", "Palettes", "npal")); out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", "npal"));
return out; return out;
} }

View File

@ -565,7 +565,7 @@ void TileSheetEditorModel::cut() {
const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin;
const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight);
setClipboardObject(m_ctx, std::move(cb)); setClipboardObject(m_ctx, std::move(cb));
pushCommand(new CutPasteCommand<CommandId::Cut>(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); pushCommand(ox::make<CutPasteCommand<CommandId::Cut>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
} }
void TileSheetEditorModel::copy() { void TileSheetEditorModel::copy() {
@ -594,7 +594,7 @@ void TileSheetEditorModel::paste() {
const auto s = activeSubSheet(); const auto s = activeSubSheet();
const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin;
const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight);
pushCommand(new CutPasteCommand<CommandId::Paste>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb));
} }
const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept { const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept {
@ -602,7 +602,7 @@ const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept {
} }
ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept { ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept {
pushCommand(new PaletteChangeCommand(activeSubSheetIdx(), &m_img, path)); pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), &m_img, path));
return OxError(0); return OxError(0);
} }
@ -615,7 +615,7 @@ void TileSheetEditorModel::drawCommand(const geo::Point &pt, std::size_t palIdx)
if (m_ongoingDrawCommand) { if (m_ongoingDrawCommand) {
m_updated = m_updated || m_ongoingDrawCommand->append(idx); m_updated = m_updated || m_ongoingDrawCommand->append(idx);
} else if (activeSubSheet.getPixel(m_img.bpp, idx) != palIdx) { } else if (activeSubSheet.getPixel(m_img.bpp, idx) != palIdx) {
pushCommand(new DrawCommand(&m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx))); pushCommand(ox::make<DrawCommand>(&m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
} }
} }
@ -624,23 +624,23 @@ void TileSheetEditorModel::endDrawCommand() noexcept {
} }
void TileSheetEditorModel::addSubsheet(const TileSheet::SubSheetIdx &parentIdx) noexcept { void TileSheetEditorModel::addSubsheet(const TileSheet::SubSheetIdx &parentIdx) noexcept {
pushCommand(new AddSubSheetCommand(&m_img, parentIdx)); pushCommand(ox::make<AddSubSheetCommand>(&m_img, parentIdx));
} }
void TileSheetEditorModel::rmSubsheet(const TileSheet::SubSheetIdx &idx) noexcept { void TileSheetEditorModel::rmSubsheet(const TileSheet::SubSheetIdx &idx) noexcept {
pushCommand(new RmSubSheetCommand(&m_img, idx)); pushCommand(ox::make<RmSubSheetCommand>(&m_img, idx));
} }
void TileSheetEditorModel::insertTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept { void TileSheetEditorModel::insertTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept {
pushCommand(new InsertTilesCommand(&m_img, idx, tileIdx, tileCnt)); pushCommand(ox::make<InsertTilesCommand>(&m_img, idx, tileIdx, tileCnt));
} }
void TileSheetEditorModel::deleteTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept { void TileSheetEditorModel::deleteTiles(const TileSheet::SubSheetIdx &idx, std::size_t tileIdx, std::size_t tileCnt) noexcept {
pushCommand(new DeleteTilesCommand(&m_img, idx, tileIdx, tileCnt)); pushCommand(ox::make<DeleteTilesCommand>(&m_img, idx, tileIdx, tileCnt));
} }
ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept { ox::Error TileSheetEditorModel::updateSubsheet(const TileSheet::SubSheetIdx &idx, const ox::String &name, int cols, int rows) noexcept {
pushCommand(new UpdateSubSheetCommand(&m_img, idx, name, cols, rows)); pushCommand(ox::make<UpdateSubSheetCommand>(&m_img, idx, name, cols, rows));
return OxError(0); return OxError(0);
} }
@ -670,7 +670,7 @@ void TileSheetEditorModel::fill(const geo::Point &pt, int palIdx) noexcept {
if (m_ongoingDrawCommand) { if (m_ongoingDrawCommand) {
m_updated = m_updated || m_ongoingDrawCommand->append(idxList); m_updated = m_updated || m_ongoingDrawCommand->append(idxList);
} else if (s.getPixel(m_img.bpp, pt) != palIdx) { } else if (s.getPixel(m_img.bpp, pt) != palIdx) {
pushCommand(new DrawCommand(&m_img, m_activeSubsSheetIdx, idxList, palIdx)); pushCommand(ox::make<DrawCommand>(&m_img, m_activeSubsSheetIdx, idxList, palIdx));
} }
} }

View File

@ -42,9 +42,9 @@ struct TileSheetToCompactTileSheetConverter: public Converter<TileSheet, Compact
static const auto converters = [] { static const auto converters = [] {
ox::Vector<ox::UniquePtr<BaseConverter>, 3> converters; ox::Vector<ox::UniquePtr<BaseConverter>, 3> converters;
converters.emplace_back(new NostalgiaGraphicToTileSheetConverter()); converters.emplace_back(ox::make<NostalgiaGraphicToTileSheetConverter>());
converters.emplace_back(new NostalgiaPaletteToPaletteConverter()); converters.emplace_back(ox::make<NostalgiaPaletteToPaletteConverter>());
converters.emplace_back(new TileSheetToCompactTileSheetConverter()); converters.emplace_back(ox::make<TileSheetToCompactTileSheetConverter>());
return converters; return converters;
}(); }();

View File

@ -70,12 +70,12 @@ class NewMenu: public studio::Popup {
template<typename T> template<typename T>
void NewMenu::addItemType(ox::String displayName, ox::String parentDir, ox::String fileExt, T itemTempl, ox::ClawFormat pFmt) noexcept { void NewMenu::addItemType(ox::String displayName, ox::String parentDir, ox::String fileExt, T itemTempl, ox::ClawFormat pFmt) noexcept {
m_types.emplace_back(new studio::ItemMakerT<T>(std::move(displayName), std::move(parentDir), std::move(fileExt), std::move(itemTempl), pFmt)); m_types.emplace_back(ox::make<studio::ItemMakerT<T>>(std::move(displayName), std::move(parentDir), std::move(fileExt), std::move(itemTempl), pFmt));
} }
template<typename T> template<typename T>
void NewMenu::addItemType(ox::String displayName, ox::String parentDir, ox::String fileExt, ox::ClawFormat pFmt) noexcept { void NewMenu::addItemType(ox::String displayName, ox::String parentDir, ox::String fileExt, ox::ClawFormat pFmt) noexcept {
m_types.emplace_back(new studio::ItemMakerT<T>(std::move(displayName), std::move(parentDir), std::move(fileExt), pFmt)); m_types.emplace_back(ox::make<studio::ItemMakerT<T>>(std::move(displayName), std::move(parentDir), std::move(fileExt), pFmt));
} }
} }