-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10a54f1
commit 42c5f70
Showing
4 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include "tactile/base/document/map_view.hpp" | ||
#include "tactile/base/prelude.hpp" | ||
|
||
namespace tactile { | ||
|
||
struct CMap; | ||
struct CMapIdCache; | ||
class MapDocument; | ||
|
||
/** | ||
* A map view implementation. | ||
*/ | ||
class MapViewImpl final : public IMapView | ||
{ | ||
public: | ||
/** | ||
* Creates a view of a map. | ||
* | ||
* \param document The associated map document. | ||
*/ | ||
MapViewImpl(const MapDocument* document); | ||
|
||
void accept(IDocumentVisitor& visitor) const override; | ||
|
||
[[nodiscard]] | ||
auto get_tile_size() const -> Int2 override; | ||
|
||
[[nodiscard]] | ||
auto get_extent() const -> MatrixExtent override; | ||
|
||
[[nodiscard]] | ||
auto get_next_layer_id() const -> LayerID override; | ||
|
||
[[nodiscard]] | ||
auto get_next_object_id() const -> ObjectID override; | ||
|
||
[[nodiscard]] | ||
auto layer_count() const -> usize override; | ||
|
||
[[nodiscard]] | ||
auto tileset_count() const -> usize override; | ||
|
||
[[nodiscard]] | ||
auto component_count() const -> usize override; | ||
|
||
private: | ||
const MapDocument* mDocument; | ||
|
||
[[nodiscard]] | ||
auto _get_map() const -> const CMap&; | ||
|
||
[[nodiscard]] | ||
auto _get_id_cache() const -> const CMapIdCache&; | ||
}; | ||
|
||
} // namespace tactile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/document/map_view_impl.hpp" | ||
|
||
#include "tactile/base/document/document_visitor.hpp" | ||
#include "tactile/core/debug/validation.hpp" | ||
#include "tactile/core/document/layer_view_impl.hpp" | ||
#include "tactile/core/document/map_document.hpp" | ||
#include "tactile/core/document/tileset_view_impl.hpp" | ||
#include "tactile/core/entity/registry.hpp" | ||
#include "tactile/core/layer/group_layer.hpp" | ||
#include "tactile/core/map/map.hpp" | ||
|
||
namespace tactile { | ||
|
||
MapViewImpl::MapViewImpl(const MapDocument* document) | ||
: mDocument {require_not_null(document, "null document")} | ||
{} | ||
|
||
void MapViewImpl::accept(IDocumentVisitor& visitor) const | ||
{ | ||
const auto& registry = mDocument->get_registry(); | ||
|
||
const auto& map = _get_map(); | ||
const auto& root_layer = registry.get<CGroupLayer>(map.root_layer); | ||
|
||
visitor.visit(*this); | ||
|
||
for (const auto tileset_id : map.attached_tilesets) { | ||
const TilesetViewImpl tileset_view {mDocument, tileset_id}; | ||
tileset_view.accept(visitor); | ||
} | ||
|
||
for (const auto layer_id : root_layer.layers) { | ||
const LayerViewImpl layer_view {mDocument, nullptr, layer_id}; | ||
layer_view.accept(visitor); | ||
} | ||
|
||
// TODO iterate component definitions | ||
} | ||
|
||
auto MapViewImpl::get_tile_size() const -> Int2 | ||
{ | ||
return _get_map().tile_size; | ||
} | ||
|
||
auto MapViewImpl::get_extent() const -> MatrixExtent | ||
{ | ||
return _get_map().extent; | ||
} | ||
|
||
auto MapViewImpl::get_next_layer_id() const -> LayerID | ||
{ | ||
return _get_id_cache().next_layer_id; | ||
} | ||
|
||
auto MapViewImpl::get_next_object_id() const -> ObjectID | ||
{ | ||
return _get_id_cache().next_object_id; | ||
} | ||
|
||
auto MapViewImpl::layer_count() const -> usize | ||
{ | ||
const auto& registry = mDocument->get_registry(); | ||
const auto& map = _get_map(); | ||
|
||
return count_layers(registry, map.root_layer); | ||
} | ||
|
||
auto MapViewImpl::tileset_count() const -> usize | ||
{ | ||
return _get_map().attached_tilesets.size(); | ||
} | ||
|
||
auto MapViewImpl::component_count() const -> usize | ||
{ | ||
return 0; // TODO | ||
} | ||
|
||
auto MapViewImpl::_get_map() const -> const CMap& | ||
{ | ||
const auto& registry = mDocument->get_registry(); | ||
const auto map_id = mDocument->get_root_entity(); | ||
return registry.get<CMap>(map_id); | ||
} | ||
|
||
auto MapViewImpl::_get_id_cache() const -> const CMapIdCache& | ||
{ | ||
const auto& registry = mDocument->get_registry(); | ||
const auto map_id = mDocument->get_root_entity(); | ||
return registry.get<CMapIdCache>(map_id); | ||
} | ||
|
||
} // namespace tactile |