diff --git a/modules/core/inc/tactile/core/map/layer/layer.hpp b/modules/core/inc/tactile/core/map/layer/layer.hpp new file mode 100644 index 0000000000..83717fbac5 --- /dev/null +++ b/modules/core/inc/tactile/core/map/layer/layer.hpp @@ -0,0 +1,87 @@ +// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) + +#pragma once + +#include "tactile/core/api.hpp" +#include "tactile/core/container/smart_ptr.hpp" +#include "tactile/core/context/meta_context.hpp" +#include "tactile/core/functional/maybe.hpp" +#include "tactile/core/prelude.hpp" + +namespace tactile { + +TACTILE_FWD(class ILayerVisitor) + +/** + * \interface ILayer + * \brief The common interface for all layer variants. + */ +class TACTILE_CORE_API ILayer : public IMetaContext { + public: + TACTILE_INTERFACE_CLASS(ILayer); + + /** + * \brief Inspects the layer using the given visitor. + * + * \param visitor the visitor to use. + */ + virtual void accept(ILayerVisitor& visitor) = 0; + + /** + * \brief Sets the associated identifier used in save files. + * + * \param id the new persistent identifier, if any. + */ + virtual void set_persistent_id(Maybe id) = 0; + + /** + * \brief Sets the opacity of the layer content. + * + * \param opacity the opacity value, will be clamped to [0, 1]. + */ + virtual void set_opacity(float opacity) = 0; + + /** + * \brief Sets the visibility of the layer content. + * + * \param visible true if the layer content should be rendered; false otherwise. + */ + virtual void set_visible(bool visible) = 0; + + /** + * \brief Returns the associated persistent identifier, if any. + * + * \return a layer identifier. + */ + [[nodiscard]] + virtual auto get_persistent_id() const -> Maybe = 0; + + /** + * \brief Returns the layer content opacity. + * + * \return an opacity value in the interval [0, 1]. + */ + [[nodiscard]] + virtual auto get_opacity() const -> float = 0; + + /** + * \brief Indicates whether the layer content is rendered. + * + * \return true if the content is visible; false otherwise. + */ + [[nodiscard]] + virtual auto is_visible() const -> bool = 0; + + /** + * \brief Creates a clone of the layer. + * + * \note The layer clone may not be identical to the source layer, the only guarantee + * is that the layer clone is logically equivalent. + * + * \return the new layer. + */ + [[nodiscard]] + virtual auto clone() const -> Shared = 0; +}; + +} // namespace tactile diff --git a/modules/core/inc/tactile/core/map/layer/layer_visitor.hpp b/modules/core/inc/tactile/core/map/layer/layer_visitor.hpp new file mode 100644 index 0000000000..2af84ed077 --- /dev/null +++ b/modules/core/inc/tactile/core/map/layer/layer_visitor.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) + +#pragma once + +#include "tactile/core/api.hpp" +#include "tactile/core/prelude.hpp" + +namespace tactile { + +TACTILE_FWD(class TileLayer) +TACTILE_FWD(class ObjectLayer) +TACTILE_FWD(class GroupLayer) + +/** + * \brief Visitor type used to inspect non-const layers. + */ +class TACTILE_CORE_API ILayerVisitor { + public: + TACTILE_INTERFACE_CLASS(ILayerVisitor); + + /** + * \brief Visits a tile layer. + * + * \param layer the visited layer. + */ + virtual void visit([[maybe_unused]] TileLayer& layer) + {} + + /** + * \brief Visits an object layer. + * + * \param layer the visited layer. + */ + virtual void visit([[maybe_unused]] ObjectLayer& layer) + {} + + /** + * \brief Visits a group layer. + * + * \param layer the visited layer. + */ + virtual void visit([[maybe_unused]] GroupLayer& layer) + {} +}; + +} // namespace tactile