Skip to content

Commit

Permalink
Register defines for new tilesets
Browse files Browse the repository at this point in the history
  • Loading branch information
nerudaj committed Dec 22, 2023
1 parent 803af34 commit efb30c4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/lib-defines/include/Configs/Strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ namespace Strings

namespace Level
{
RAWSTRING THEME_COUNTRY = "Countryside";
RAWSTRING THEME_DAWNTIME = "Dawntime";
RAWSTRING THEME_SPACE = "Nightsky";
RAWSTRING THEME_ALPHA = "AlphaVersion";
RAWSTRING SKYBOX_COUNTRY = "Countryside";
RAWSTRING SKYBOX_DAWNTIME = "Dawntime";
RAWSTRING SKYBOX_SPACE = "Nightsky";
RAWSTRING TEXTURES_ALPHA = "AlphaVersion";
RAWSTRING TEXTURES_SPACE = "Space station";
RAWSTRING TEXTURES_COUNTRY = "Countryside";
RAWSTRING TEXTURES_NEON = "Neon";
} // namespace Level
} // namespace Strings

Expand Down
5 changes: 4 additions & 1 deletion src/lib-defines/include/LevelTheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class SkyboxThemeUtils

enum class [[nodiscard]] TexturePack
{
AlphaVersion
AlphaVersion,
SpaceStation,
CountrySide,
Neon
};

class TexturePackUtils
Expand Down
32 changes: 24 additions & 8 deletions src/lib-defines/src/LevelTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

SkyboxTheme SkyboxThemeUtils::fromString(const std::string& str)
{
if (str == Strings::Level::THEME_DAWNTIME)
if (str == Strings::Level::SKYBOX_DAWNTIME)
return SkyboxTheme::Dawntime;
else if (str == Strings::Level::THEME_SPACE)
else if (str == Strings::Level::SKYBOX_SPACE)
return SkyboxTheme::Nightsky;

// Default to countryside if there is anything wrong
Expand All @@ -19,11 +19,11 @@ std::string SkyboxThemeUtils::toString(SkyboxTheme skyboxTheme)
{
using enum SkyboxTheme;
case Countryside:
return Strings::Level::THEME_COUNTRY;
return Strings::Level::SKYBOX_COUNTRY;
case Dawntime:
return Strings::Level::THEME_DAWNTIME;
return Strings::Level::SKYBOX_DAWNTIME;
case Nightsky:
return Strings::Level::THEME_SPACE;
return Strings::Level::SKYBOX_SPACE;
}
}

Expand All @@ -34,8 +34,15 @@ std::vector<std::string> SkyboxThemeUtils::getAllNames()
toString(SkyboxTheme::Nightsky) };
}

TexturePack TexturePackUtils::fromString(const std::string&)
TexturePack TexturePackUtils::fromString(const std::string& str)
{
if (str == Strings::Level::TEXTURES_SPACE)
return TexturePack::SpaceStation;
else if (str == Strings::Level::TEXTURES_COUNTRY)
return TexturePack::CountrySide;
else if (str == Strings::Level::TEXTURES_NEON)
return TexturePack::Neon;

// Default to alpha if there is anything wrong
return TexturePack::AlphaVersion;
}
Expand All @@ -46,11 +53,20 @@ std::string TexturePackUtils::toString(TexturePack levelTheme)
{
using enum TexturePack;
case AlphaVersion:
return Strings::Level::THEME_ALPHA;
return Strings::Level::TEXTURES_ALPHA;
case SpaceStation:
return Strings::Level::TEXTURES_SPACE;
case CountrySide:
return Strings::Level::TEXTURES_COUNTRY;
case Neon:
return Strings::Level::TEXTURES_NEON;
}
}

std::vector<std::string> TexturePackUtils::getAllNames()
{
return std::vector<std::string> { toString(TexturePack::AlphaVersion) };
return std::vector<std::string> { toString(TexturePack::AlphaVersion),
toString(TexturePack::SpaceStation),
toString(TexturePack::CountrySide),
toString(TexturePack::Neon) };
}
8 changes: 7 additions & 1 deletion src/lib-game/src/engine/RenderingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ranges>
#include <utils/MathHelpers.hpp>

import TexturePath;

[[nodiscard]] static std::pair<std::uint8_t, bool> getRotatedSpriteClipId(
const sf::Vector2f& cameraDir,
const sf::Vector2f& thingDir,
Expand Down Expand Up @@ -40,7 +42,11 @@ RenderingEngine::RenderingEngine(
Scene& scene)
: settings(settings)
, scene(scene)
, tileset { .texture = resmgr.get<sf::Texture>("tileset.png").value().get(),
, tileset { .texture = resmgr
.get<sf::Texture>(TexturePath::getTilesetName(
scene.level.texturePack))
.value()
.get(),
.clipping =
resmgr.get<dgm::Clip>("tileset.png.clip").value().get() }
, spritesheet { .texture =
Expand Down
2 changes: 2 additions & 0 deletions src/lib-resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ glob_modules ( SRCS )

add_library ( ${PROJECT_NAME} ${SRCS} )

target_link_libraries ( ${PROJECT_NAME} lib-defines )

autoset_target_compile_options ( ${PROJECT_NAME} FALSE )
34 changes: 34 additions & 0 deletions src/lib-resources/src/TexturePath.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module;

#include <LevelTheme.hpp>
#include <stdexcept>
#include <string>

export module TexturePath;

export class TexturePath final
{
public:
static [[nodiscard]] std::string getTilesetName(TexturePack packId)
{
switch (packId)
{
using enum TexturePack;

case AlphaVersion:
return "tileset.png";

case SpaceStation:
return "space_station_tileset.png";

case CountrySide:
return "countryside_tileset.png";

case Neon:
return "neon_tileset.png";
}

throw std::runtime_error(
"Programmer error: TexturePack id without assigned texture");
}
};

0 comments on commit efb30c4

Please sign in to comment.