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

#pragma once

#include <ox/mc/mc.hpp>
#include <ox/std/std.hpp>

#include <nostalgia/core/core.hpp>
#include <nostalgia/geo/geo.hpp>

namespace nostalgia::world {

struct Tile {
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.world.Tile";
	static constexpr auto TypeVersion = 1;

	uint8_t bgTile = 0;
	uint8_t type = 0;
};

oxModelBegin(Tile)
	oxModelField(bgTile)
	oxModelField(type)
oxModelEnd()


struct Zone {
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.world.Zone";
	static constexpr auto TypeVersion = 2;

	oxModelFriend(Zone);

	protected:
		geo::Bounds m_bounds;
		Tile *m_tiles = nullptr;

	public:
		Zone() = default;

		~Zone();

		ox::Error init(core::Context *ctx, geo::Bounds bnds, ox::FileAddress tileSheet, ox::FileAddress palette = {});

		void draw(core::Context *ctx);

		std::size_t size();

		Tile *tile(int x, int y);

		void setTile(int x, int y, Tile *td);

};

oxModelBegin(Zone)
	oxModelFieldRename(bounds, m_bounds)
oxModelEnd()

struct Region {
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.world.Region";
	static constexpr auto TypeVersion = 1;

	oxModelFriend(Region);

	protected:
		ox::Vector<Zone*> m_zones;

};

oxModelBegin(Region)
	oxModelFieldRename(zones, m_zones)
oxModelEnd()


}
