Skip to content

Commit

Permalink
Add basic layer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 30, 2023
1 parent 5de0b52 commit ac874ca
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
87 changes: 87 additions & 0 deletions modules/core/inc/tactile/core/map/layer/layer.hpp
Original file line number Diff line number Diff line change
@@ -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<int32> 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<int32> = 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<ILayer> = 0;
};

} // namespace tactile
46 changes: 46 additions & 0 deletions modules/core/inc/tactile/core/map/layer/layer_visitor.hpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac874ca

Please sign in to comment.