/*
 * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include "updatesubsheetcommand.hpp"

namespace nostalgia::gfx {

UpdateSubSheetCommand::UpdateSubSheetCommand(
		TileSheet &img,
		TileSheet::SubSheetIdx idx,
		ox::StringParam name,
		int const cols,
		int const rows):
		m_img{img},
		m_idx{std::move(idx)},
		m_sheet{getSubSheet(m_img, m_idx)} {
	m_sheet.name = std::move(name);
	OX_THROW_ERROR(resizeSubsheet(m_sheet, {cols, rows}));
}

ox::Error UpdateSubSheetCommand::redo() noexcept {
	std::swap(m_sheet, getSubSheet(m_img, m_idx));
	return {};
}

ox::Error UpdateSubSheetCommand::undo() noexcept {
	std::swap(m_sheet, getSubSheet(m_img, m_idx));
	return {};
}

int UpdateSubSheetCommand::commandId() const noexcept {
	return static_cast<int>(CommandId::UpdateSubSheet);
}

TileSheet::SubSheetIdx const &UpdateSubSheetCommand::subsheetIdx() const noexcept {
	return m_idx;
}

}
