Skip to content

Commit

Permalink
Add skeletons for layer types
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 30, 2023
1 parent ac874ca commit 689d308
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 0 deletions.
47 changes: 47 additions & 0 deletions modules/core/inc/tactile/core/map/layer/group_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/map/layer/layer.hpp"
#include "tactile/core/map/layer/layer_behavior_delegate.hpp"
#include "tactile/core/prelude.hpp"

namespace tactile {

/**
* \brief A layer variant consisting of a collection of other layers.
*/
class TACTILE_CORE_API GroupLayer final : public ILayer {
public:
void accept(ILayerVisitor& visitor) override;

void set_persistent_id(Maybe<int32> id) override;

void set_opacity(float opacity) override;

void set_visible(bool visible) override;

[[nodiscard]]
auto get_persistent_id() const -> Maybe<int32> override;

[[nodiscard]]
auto get_opacity() const -> float override;

[[nodiscard]]
auto is_visible() const -> bool override;

[[nodiscard]]
auto clone() const -> Shared<ILayer> override;

[[nodiscard]]
auto get_meta() -> Metadata& override;

[[nodiscard]]
auto get_meta() const -> const Metadata& override;

private:
LayerBehaviorDelegate mDelegate;
};

} // namespace tactile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/context/metadata.hpp"
#include "tactile/core/functional/maybe.hpp"
#include "tactile/core/prelude.hpp"

namespace tactile {

/**
* \brief Used by layer types to implement the common subset of the `ILayer` interface.
*/
class TACTILE_CORE_API LayerBehaviorDelegate final {
public:
void set_persistent_id(Maybe<int32> id);

void set_opacity(float opacity);

void set_visible(bool visible);

[[nodiscard]]
auto get_persistent_id() const -> Maybe<int32>;

[[nodiscard]]
auto get_opacity() const -> float;

[[nodiscard]]
auto is_visible() const -> bool;

[[nodiscard]]
auto get_meta() -> Metadata&;

[[nodiscard]]
auto get_meta() const -> const Metadata&;

private:
Metadata mMeta;
Maybe<int32> mPersistentId;
float mOpacity {1.0f};
bool mVisible {true};
};

} // namespace tactile
47 changes: 47 additions & 0 deletions modules/core/inc/tactile/core/map/layer/object_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/map/layer/layer.hpp"
#include "tactile/core/map/layer/layer_behavior_delegate.hpp"
#include "tactile/core/prelude.hpp"

namespace tactile {

/**
* \brief A layer variant consisting of an arbitrary collection of objects.
*/
class TACTILE_CORE_API ObjectLayer final : public ILayer {
public:
void accept(ILayerVisitor& visitor) override;

void set_persistent_id(Maybe<int32> id) override;

void set_opacity(float opacity) override;

void set_visible(bool visible) override;

[[nodiscard]]
auto get_persistent_id() const -> Maybe<int32> override;

[[nodiscard]]
auto get_opacity() const -> float override;

[[nodiscard]]
auto is_visible() const -> bool override;

[[nodiscard]]
auto clone() const -> Shared<ILayer> override;

[[nodiscard]]
auto get_meta() -> Metadata& override;

[[nodiscard]]
auto get_meta() const -> const Metadata& override;

private:
LayerBehaviorDelegate mDelegate;
};

} // namespace tactile
47 changes: 47 additions & 0 deletions modules/core/inc/tactile/core/map/layer/tile_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/map/layer/layer.hpp"
#include "tactile/core/map/layer/layer_behavior_delegate.hpp"
#include "tactile/core/prelude.hpp"

namespace tactile {

/**
* \brief A layer variant consisting of a two-dimensional grid of tile identifiers.
*/
class TACTILE_CORE_API TileLayer final : public ILayer {
public:
void accept(ILayerVisitor& visitor) override;

void set_persistent_id(Maybe<int32> id) override;

void set_opacity(float opacity) override;

void set_visible(bool visible) override;

[[nodiscard]]
auto get_persistent_id() const -> Maybe<int32> override;

[[nodiscard]]
auto get_opacity() const -> float override;

[[nodiscard]]
auto is_visible() const -> bool override;

[[nodiscard]]
auto clone() const -> Shared<ILayer> override;

[[nodiscard]]
auto get_meta() -> Metadata& override;

[[nodiscard]]
auto get_meta() const -> const Metadata& override;

private:
LayerBehaviorDelegate mDelegate;
};

} // namespace tactile
63 changes: 63 additions & 0 deletions modules/core/src/tactile/core/map/layer/group_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/map/layer/group_layer.hpp"

#include "tactile/core/map/layer/layer_visitor.hpp"

namespace tactile {

void GroupLayer::accept(ILayerVisitor& visitor)
{
visitor.visit(*this);
}

void GroupLayer::set_persistent_id(const Maybe<int32> id)
{
mDelegate.set_persistent_id(id);
}

void GroupLayer::set_opacity(const float opacity)
{
mDelegate.set_opacity(opacity);
}

void GroupLayer::set_visible(const bool visible)
{
mDelegate.set_visible(visible);
}

auto GroupLayer::get_persistent_id() const -> Maybe<int32>
{
return mDelegate.get_persistent_id();
}

auto GroupLayer::get_opacity() const -> float
{
return mDelegate.get_opacity();
}

auto GroupLayer::is_visible() const -> bool
{
return mDelegate.is_visible();
}

auto GroupLayer::clone() const -> Shared<ILayer>
{
auto clone = make_shared<GroupLayer>(*this);

clone->set_persistent_id(kNone);

return clone;
}

auto GroupLayer::get_meta() -> Metadata&
{
return mDelegate.get_meta();
}

auto GroupLayer::get_meta() const -> const Metadata&
{
return mDelegate.get_meta();
}

} // namespace tactile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/map/layer/layer_behavior_delegate.hpp"

#include <algorithm> // clamp

namespace tactile {

void LayerBehaviorDelegate::set_persistent_id(const Maybe<int32> id)
{
mPersistentId = id;
}

void LayerBehaviorDelegate::set_opacity(const float opacity)
{
mOpacity = std::clamp(opacity, 0.0f, 1.0f);
}

void LayerBehaviorDelegate::set_visible(const bool visible)
{
mVisible = visible;
}

auto LayerBehaviorDelegate::get_persistent_id() const -> Maybe<int32>
{
return mPersistentId;
}

auto LayerBehaviorDelegate::get_opacity() const -> float
{
return mOpacity;
}

auto LayerBehaviorDelegate::is_visible() const -> bool
{
return mVisible;
}

auto LayerBehaviorDelegate::get_meta() -> Metadata&
{
return mMeta;
}

auto LayerBehaviorDelegate::get_meta() const -> const Metadata&
{
return mMeta;
}

} // namespace tactile
63 changes: 63 additions & 0 deletions modules/core/src/tactile/core/map/layer/object_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/map/layer/object_layer.hpp"

#include "tactile/core/map/layer/layer_visitor.hpp"

namespace tactile {

void ObjectLayer::accept(ILayerVisitor& visitor)
{
visitor.visit(*this);
}

void ObjectLayer::set_persistent_id(const Maybe<int32> id)
{
mDelegate.set_persistent_id(id);
}

void ObjectLayer::set_opacity(const float opacity)
{
mDelegate.set_opacity(opacity);
}

void ObjectLayer::set_visible(const bool visible)
{
mDelegate.set_visible(visible);
}

auto ObjectLayer::get_persistent_id() const -> Maybe<int32>
{
return mDelegate.get_persistent_id();
}

auto ObjectLayer::get_opacity() const -> float
{
return mDelegate.get_opacity();
}

auto ObjectLayer::is_visible() const -> bool
{
return mDelegate.is_visible();
}

auto ObjectLayer::clone() const -> Shared<ILayer>
{
auto clone = make_shared<ObjectLayer>(*this);

clone->set_persistent_id(kNone);

return clone;
}

auto ObjectLayer::get_meta() -> Metadata&
{
return mDelegate.get_meta();
}

auto ObjectLayer::get_meta() const -> const Metadata&
{
return mDelegate.get_meta();
}

} // namespace tactile
Loading

0 comments on commit 689d308

Please sign in to comment.