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

#include <studio/studio.hpp>

#include <jasper/world/consts.hpp>

#include "worldobjectseteditor/worldobjectseteditor-imgui.hpp"
#include "worldeditor/worldeditor-imgui.hpp"

namespace jasper::world {

static struct: studio::Module {

	ox::String id() const noexcept final {
		return ox::String{"net.drinkingtea.jasper.world"};
	}

	ox::Vector<studio::EditorMaker> editors(studio::Context &ctx) const noexcept override {
		return {
			 studio::editorMaker<WorldObjectSetEditorImGui>(ctx, FileExt_jwob),
			 studio::editorMaker<WorldEditorImGui>(ctx, FileExt_jwld),
		};
	}

	ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept override {
		ox::Vector<ox::UPtr<studio::ItemMaker>> out;
		out.emplace_back(ox::make<studio::ItemMakerT<WorldObjectSet>>(
				"World Object Set", "WorldObjectSets", FileExt_jwob, ox::ClawFormat::Organic));
		out.emplace_back(ox::make<studio::ItemMakerT<WorldDoc>>(
				"World", "Worlds", FileExt_jwld, ox::ClawFormat::Organic));
		return out;
	}

	ox::Vector<ox::UPtr<studio::ItemTemplate>> itemTemplates(studio::Context&) const noexcept override {
		ox::Vector<ox::UniquePtr<studio::ItemTemplate>> out;
		// Person TileSheet
		ngfx::TileSheetV5 ts;
		ts.bpp = 4;
		auto const addSheet = [&ts](
			ngfx::TileSheetV5::SubSheet &ss,
			ox::StringParam name,
			int const cols,
			int const rows) -> auto& {
			return ss.subsheets.emplace_back(++ts.idIt, std::move(name), cols, rows);
		};
		auto const addSheetSet = [&ts, &addSheet](ox::StringParam name) {
			auto &s = addSheet(ts.subsheet, std::move(name), -1, -1);
			addSheet(s, "Still", 2, 3);
			addSheet(s, "Step 1", 2, 3);
			addSheet(s, "Step 2", 2, 3);
		};
		addSheetSet("Front");
		addSheetSet("Back");
		addSheetSet("Side");
		out.emplace_back(ox::make<studio::ItemTemplateT<ngfx::TileSheetV5>>(
			"Jasper World Person",
			std::move(ts)));
		return out;
	}

} const mod;

studio::Module const*studioModule() noexcept {
	return &mod;
}

}
