FeatherMC/src/world/Palette.h

38 lines
869 B
C
Raw Normal View History

2020-08-13 04:10:44 +01:00
#pragma once
#include "data/IDMapper.h"
namespace Feather
{
template <typename T>
class Palette
{
protected:
const IDMapper<T>& m_registry;
public:
Palette(const IDMapper<T>& registry) :
m_registry(registry)
{}
virtual int GetID(const T& value) const = 0;
2020-08-13 04:10:44 +01:00
virtual const T& ByID(int id) const = 0;
};
template <typename T>
class GlobalPalette : public Palette<T>
{
const T* m_defaultValue;
public:
GlobalPalette(const IDMapper<T>& registry, const T* defaultValue) :
Palette(registry),
m_defaultValue(defaultValue)
{}
inline const T& GetDefault() const { return *m_defaultValue; }
inline int GetDefaultID() const { return GetID(GetDefault()); }
inline virtual int GetID(const T& value) const final { return m_registry.GetID(value); }
2020-08-13 04:10:44 +01:00
inline virtual const T& ByID(int id) const final { return m_registry.ByID(id); }
};
}