Skip to content

Commit

Permalink
Restore support for Godot 3 scene format
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson authored Oct 8, 2024
1 parent 0ccc4c1 commit a77dc7a
Show file tree
Hide file tree
Showing 52 changed files with 2,543 additions and 161 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if (TACTILE_BUILD_TILED_TMX_FORMAT)
endif ()

if (TACTILE_BUILD_GODOT_TSCN_FORMAT)
add_subdirectory("source/godot_tscn_format")
add_subdirectory("source/plugins/godot_tscn")
endif ()

if (TACTILE_BUILD_ZLIB_COMPRESSION)
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ light_themes = Light themes
dark_themes = Dark themes
font = Font
default = Default
version = Version
project_dir = Project directory

[adjective]
orthogonal = Orthogonal
Expand Down Expand Up @@ -137,4 +139,5 @@ about_dialog = About Tactile
credits_dialog = Credits
create_map_dialog = Create Map
create_tileset_dialog = Create Tileset
godot_export_dialog = Export Godot Scene
style_editor = Style Editor
3 changes: 3 additions & 0 deletions assets/lang/en_GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ light_themes = Light themes
dark_themes = Dark themes
font = Font
default = Default
version = Version
project_dir = Project directory

[adjective]
orthogonal = Orthogonal
Expand Down Expand Up @@ -137,4 +139,5 @@ about_dialog = About Tactile
credits_dialog = Credits
create_map_dialog = Create Map
create_tileset_dialog = Create Tileset
godot_export_dialog = Export Godot Scene
style_editor = Style Editor
3 changes: 3 additions & 0 deletions assets/lang/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ light_themes = Ljusa teman
dark_themes = Mörka teman
font = Typsnitt
default = Standard
version = Version
project_dir = Projektmapp

[adjective]
orthogonal = Ortogonal
Expand Down Expand Up @@ -137,4 +139,5 @@ about_dialog = Om Tactile
credits_dialog = Tredjeparter
create_map_dialog = Skapa Karta
create_tileset_dialog = Skapa Tilesamling
godot_export_dialog = Exportera Godotscen
style_editor = Stilhanterare
2 changes: 2 additions & 0 deletions source/base/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(tactile::base ALIAS tactile-base)

target_sources(tactile-base
INTERFACE FILE_SET "HEADERS" BASE_DIRS "inc" FILES
"inc/tactile/base/container/result.hpp"
"inc/tactile/base/container/string_map.hpp"
"inc/tactile/base/document/component_view.hpp"
"inc/tactile/base/document/document.hpp"
Expand Down Expand Up @@ -38,6 +39,7 @@ target_sources(tactile-base
"inc/tactile/base/meta/color.hpp"
"inc/tactile/base/numeric/extent_2d.hpp"
"inc/tactile/base/numeric/index_2d.hpp"
"inc/tactile/base/numeric/literals.hpp"
"inc/tactile/base/numeric/offset_2d.hpp"
"inc/tactile/base/numeric/saturate_cast.hpp"
"inc/tactile/base/numeric/vec.hpp"
Expand Down
16 changes: 16 additions & 0 deletions source/base/lib/inc/tactile/base/container/result.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include <expected> // expected

#include "tactile/base/debug/error_code.hpp"

namespace tactile {

template <typename T>
using Result = std::expected<T, ErrorCode>;

inline constexpr Result<void> kOK {};

} // namespace tactile
88 changes: 88 additions & 0 deletions source/base/lib/inc/tactile/base/debug/error_code.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include <string_view> // string_view

namespace tactile {

/**
* Provides common error codes.
*/
enum class ErrorCode : int
{
/** An unknown error occurred. */
kUnknown,

/** An operation or feature isn't supported. */
kNotSupported,

/** Not enough memory. */
kOutOfMemory,

/** A stack overflow was detected. */
kStackOverflow,

/** A stack underflow was detected. */
kStackUnderflow,

/** Initialization failed. */
kBadInit,

/** A given parameter is invalid. */
kBadParam,

/** An invalid state was detected. */
kBadState,

/** An invalid operation was attempted. */
kBadOperation,

/** A file doesn't exist. */
kNoSuchFile,

/** A file stream couldn't be created. */
kBadFileStream,

/** A file couldn't be copied. */
kBadFileCopy,

/** An invalid image was detected. */
kBadImage,

/** An invalid save file was detected. */
kBadSaveFile,

/** A compression operation failed. */
kCouldNotCompress,

/** A decompression operation failed. */
kCouldNotDecompress,
};

[[nodiscard]]
constexpr auto to_string(const ErrorCode errc) noexcept -> std::string_view
{
switch (errc) {
case ErrorCode::kUnknown: return "unknown";
case ErrorCode::kNotSupported: return "not supported";
case ErrorCode::kOutOfMemory: return "out of memory";
case ErrorCode::kStackOverflow: return "stack overflow";
case ErrorCode::kStackUnderflow: return "stack underflow";
case ErrorCode::kBadInit: return "initialization error";
case ErrorCode::kBadParam: return "invalid parameter";
case ErrorCode::kBadState: return "invalid state";
case ErrorCode::kBadOperation: return "invalid operation";
case ErrorCode::kNoSuchFile: return "no such file";
case ErrorCode::kBadFileStream: return "file stream error";
case ErrorCode::kBadFileCopy: return "file copy error";
case ErrorCode::kBadImage: return "invalid image";
case ErrorCode::kBadSaveFile: return "invalid save file";
case ErrorCode::kCouldNotCompress: return "could not compress";
case ErrorCode::kCouldNotDecompress: return "could not decompress";
}

return "?";
}

} // namespace tactile
23 changes: 23 additions & 0 deletions source/base/lib/inc/tactile/base/document/layer_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ class ILayerView
[[nodiscard]]
virtual auto get_tile(const Index2D& index) const -> std::optional<TileID> = 0;

/**
* Returns the position of a tile in its parent tileset.
*
* \param tile_id The target tile identifier.
*
* \return
* The position of the tile in the tileset if successful; an empty optional otherwise.
*/
[[nodiscard]]
virtual auto get_tile_position_in_tileset(TileID tile_id) const
-> std::optional<Index2D> = 0;

/**
* Indicates whether the tile at a given world position is animated.
*
* \param world_pos The world position of the tile to check.
*
* \return
* True if the tile is animated; false otherwise.
*/
[[nodiscard]]
virtual auto is_tile_animated(const Index2D& world_pos) const -> bool = 0;

/**
* Returns the tile encoding format used by the layer.
*
Expand Down
17 changes: 14 additions & 3 deletions source/base/lib/inc/tactile/base/io/save/save_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

#pragma once

#include <expected> // expected
#include <filesystem> // path
#include <system_error> // error_code
#include <expected> // expected
#include <filesystem> // path
#include <string_view> // string_view
#include <system_error> // error_code
#include <unordered_map> // unordered_map

#include "tactile/base/io/save/ir.hpp"
#include "tactile/base/meta/attribute.hpp"
#include "tactile/base/prelude.hpp"

namespace tactile {

class IMapView;

using SaveFormatExtraSettings = std::unordered_map<std::string_view, Attribute>;

/**
* Provides save format parse options.
*/
struct SaveFormatReadOptions final
{
/** Used for implementation-specific settings. */
SaveFormatExtraSettings extra;

/** The parent directory of the map or tileset file. */
std::filesystem::path base_dir;

Expand All @@ -30,6 +38,9 @@ struct SaveFormatReadOptions final
*/
struct SaveFormatWriteOptions final
{
/** Used for implementation-specific settings. */
SaveFormatExtraSettings extra;

/** The parent directory of the map or tileset file. */
std::filesystem::path base_dir;

Expand Down
21 changes: 21 additions & 0 deletions source/base/lib/inc/tactile/base/numeric/literals.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include <cstddef> // size_t, ptrdiff_t

namespace tactile {

[[nodiscard]]
consteval auto operator""_uz(const unsigned long long int value) noexcept -> std::size_t
{
return static_cast<std::size_t>(value);
}

[[nodiscard]]
consteval auto operator""_z(const unsigned long long int value) noexcept -> std::ptrdiff_t
{
return static_cast<std::ptrdiff_t>(value);
}

} // namespace tactile
2 changes: 2 additions & 0 deletions source/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ target_sources(tactile-core
"src/tactile/core/ui/common/style.cpp"
"src/tactile/core/ui/common/widgets.cpp"
"src/tactile/core/ui/common/window.cpp"
"src/tactile/core/ui/dialog/godot_export_dialog.cpp"
"src/tactile/core/ui/dialog/new_map_dialog.cpp"
"src/tactile/core/ui/dialog/new_property_dialog.cpp"
"src/tactile/core/ui/dialog/new_tileset_dialog.cpp"
Expand Down Expand Up @@ -237,6 +238,7 @@ target_sources(tactile-core
"inc/tactile/core/ui/common/text.hpp"
"inc/tactile/core/ui/common/widgets.hpp"
"inc/tactile/core/ui/common/window.hpp"
"inc/tactile/core/ui/dialog/godot_export_dialog.hpp"
"inc/tactile/core/ui/dialog/new_map_dialog.hpp"
"inc/tactile/core/ui/dialog/new_property_dialog.hpp"
"inc/tactile/core/ui/dialog/new_tileset_dialog.hpp"
Expand Down
6 changes: 6 additions & 0 deletions source/core/inc/tactile/core/document/layer_view_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class LayerViewImpl final : public ILayerView
[[nodiscard]]
auto get_tile(const Index2D& index) const -> std::optional<TileID> override;

[[nodiscard]]
auto get_tile_position_in_tileset(TileID tile_id) const -> std::optional<Index2D> override;

[[nodiscard]]
auto is_tile_animated(const Index2D& position) const -> bool override;

[[nodiscard]]
auto get_tile_encoding() const -> TileEncoding override;

Expand Down
6 changes: 6 additions & 0 deletions source/core/inc/tactile/core/event/map_event_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class WidgetManager;

struct ShowNewMapDialogEvent;
struct ShowOpenMapDialogEvent;
struct ShowGodotExportDialogEvent;
struct CreateMapEvent;
struct ExportAsGodotSceneEvent;

/**
* Handles events related to maps.
Expand Down Expand Up @@ -58,13 +60,17 @@ class MapEventHandler final
*/
void on_show_open_map_dialog(const ShowOpenMapDialogEvent& event);

void on_show_godot_export_dialog(const ShowGodotExportDialogEvent& event);

/**
* Creates a new map.
*
* \param event The associated event.
*/
void on_create_map(const CreateMapEvent& event);

void on_export_as_godot_scene(const ExportAsGodotSceneEvent& event) const;

private:
Model* mModel;
ui::WidgetManager* mWidgetManager;
Expand Down
20 changes: 15 additions & 5 deletions source/core/inc/tactile/core/event/map_events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#pragma once

#include "tactile/base/io/save/save_format_id.hpp"
#include "tactile/base/prelude.hpp"
#include <filesystem> // path

#include "tactile/core/map/map_spec.hpp"

namespace tactile {
Expand Down Expand Up @@ -66,11 +66,21 @@ struct FixMapTilesEvent final
{};

/**
* Event for opening the dialog for exporting the active map using a specific save format.
* Event for opening the dialog for exporting the active map as a Godot scene.
*/
struct ShowGodotExportDialogEvent final
{};

/**
* Event for saving the active map as a Godot scene.
*/
struct ShowExportMapDialogEvent final
struct ExportAsGodotSceneEvent final
{
SaveFormatId format_id;
/** The desired major Godot version. */
int version;

/** The base directory of the Godot project. */
std::filesystem::path project_dir;
};

} // namespace tactile
2 changes: 1 addition & 1 deletion source/core/inc/tactile/core/tile/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ auto make_tile(Registry& registry, TileIndex index) -> EntityID;
* Creates a tile from an intermediate representation.
*
* \param registry The associated registry.
* \param tile The intermediate tile representation.
* \param ir_tile The intermediate tile representation.
*
* \return
* A tile entity identifier if successful; an error code otherwise.
Expand Down
Loading

0 comments on commit a77dc7a

Please sign in to comment.