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

#include "palettechangecommand.hpp"

namespace nostalgia::gfx {

PaletteChangeCommand::PaletteChangeCommand(
		TileSheet::SubSheetIdx idx,
		TileSheet &img,
		ox::StringViewCR newPalette) noexcept:
		m_img{img},
		m_idx{std::move(idx)},
		m_oldPalette{m_img.defaultPalette},
		m_newPalette{ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)} {
}

ox::Error PaletteChangeCommand::redo() noexcept {
	m_img.defaultPalette = m_newPalette;
	return {};
}

ox::Error PaletteChangeCommand::undo() noexcept {
	m_img.defaultPalette = m_oldPalette;
	return {};
}

int PaletteChangeCommand::commandId() const noexcept {
	return static_cast<int>(CommandId::PaletteChange);
}

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

}
