Skip to content

Commit 046d998

Browse files
committed
put ConsoleData and ConsoleResource in their own file
1 parent fc41656 commit 046d998

File tree

7 files changed

+100
-40
lines changed

7 files changed

+100
-40
lines changed

include/gf2/core/Console.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,6 @@ namespace gf {
147147
return ar | buffer.raw();
148148
}
149149

150-
struct GF_CORE_API ConsoleResource {
151-
std::filesystem::path console_font;
152-
Vec2I size;
153-
};
154-
155-
template<typename Archive>
156-
Archive& operator|(Archive& ar, MaybeConst<ConsoleResource, Archive>& resource)
157-
{
158-
return ar | resource.console_font | resource.size;
159-
}
160-
161150
}
162151

163152
#endif // GF_CONSOLE_H

include/gf2/core/ConsoleData.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: Zlib
2+
// Copyright (c) 2023-2025 Julien Bernard
3+
#ifndef GF_CONSOLE_DATA_H
4+
#define GF_CONSOLE_DATA_H
5+
6+
#include <cstdint>
7+
8+
#include <filesystem>
9+
10+
#include "CoreApi.h"
11+
#include "TypeTraits.h"
12+
#include "Vec2.h"
13+
14+
namespace gf {
15+
16+
struct GF_CORE_API ConsoleFontFormat {
17+
enum Transparency : uint8_t {
18+
Alpha,
19+
Grayscale,
20+
ColorKey,
21+
};
22+
23+
Transparency transparency;
24+
25+
enum Layout : uint8_t {
26+
InColumn,
27+
InRow,
28+
};
29+
30+
Layout layout;
31+
32+
enum Mapping : uint8_t {
33+
CodePage437,
34+
ModifiedCodePage437,
35+
Special,
36+
Custom,
37+
};
38+
39+
Mapping mapping;
40+
};
41+
42+
inline constexpr ConsoleFontFormat LibtcodFormat = { ConsoleFontFormat::ColorKey, ConsoleFontFormat::InRow, ConsoleFontFormat::Special };
43+
inline constexpr ConsoleFontFormat DwarfFortressFormat = { ConsoleFontFormat::ColorKey, ConsoleFontFormat::InRow, ConsoleFontFormat::CodePage437 };
44+
45+
struct GF_CORE_API ConsoleData {
46+
ConsoleFontFormat font_format;
47+
Vec2I font_size = { 0, 0 };
48+
};
49+
50+
template<typename Archive>
51+
inline Archive& operator|(Archive& ar, MaybeConst<ConsoleData, Archive>& data)
52+
{
53+
return ar | data.font_format.transparency | data.font_format.layout | data.font_format.mapping | data.font_size;
54+
}
55+
56+
struct GF_CORE_API ConsoleResource {
57+
std::filesystem::path console_font;
58+
ConsoleData data;
59+
};
60+
61+
template<typename Archive>
62+
inline Archive& operator|(Archive& ar, MaybeConst<ConsoleResource, Archive>& resource)
63+
{
64+
return ar | resource.console_font | resource.data;
65+
}
66+
67+
}
68+
69+
#endif // GF_CONSOLE_FONT_DATA_H

include/gf2/framework/BundleBuilder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace gf {
1818
struct AnimationResource;
1919
struct AnimationGroupResource;
2020
struct AudioSourceResource;
21+
struct ConsoleResource;
22+
struct ConsoleData;
2123
struct NinePatchResource;
2224
struct RichMapResource;
2325
struct RichTextResource;
@@ -38,12 +40,16 @@ namespace gf {
3840
void add_in_bundle(const SpriteResource& resource);
3941
void add_in_bundle(const TextResource& resource);
4042

43+
void add_in_bundle(const ConsoleResource& resource);
44+
4145
void add_raw_texture(const std::filesystem::path& path);
4246
void add_raw_font(const std::filesystem::path& path);
4347
void add_raw_map(const std::filesystem::path& path);
4448
void add_raw_sound(const std::filesystem::path& path);
4549
void add_raw_music(const std::filesystem::path& path);
4650

51+
void add_raw_console_font(const std::filesystem::path& path, const ConsoleData& data);
52+
4753
ResourceBundle make_bundle() const;
4854

4955
private:
@@ -56,6 +62,8 @@ namespace gf {
5662
std::vector<std::filesystem::path> m_maps;
5763
std::vector<std::filesystem::path> m_sounds;
5864
std::vector<std::filesystem::path> m_musics;
65+
66+
std::vector<ConsoleResource> m_console_fonts;
5967
};
6068

6169
}

include/gf2/graphics/ConsoleFont.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,14 @@
77

88
#include <filesystem>
99

10+
#include <gf2/core/ConsoleData.h>
1011
#include <gf2/core/Span.h>
1112

1213
#include "GraphicsApi.h"
1314
#include "Texture.h"
1415

1516
namespace gf {
1617

17-
struct GF_GRAPHICS_API ConsoleFontFormat {
18-
enum Transparency : uint8_t {
19-
Alpha,
20-
Grayscale,
21-
ColorKey,
22-
};
23-
24-
Transparency transparency;
25-
26-
enum Layout : uint8_t {
27-
InColumn,
28-
InRow,
29-
};
30-
31-
Layout layout;
32-
33-
enum Mapping : uint8_t {
34-
CodePage437,
35-
ModifiedCodePage437,
36-
Special,
37-
Custom,
38-
};
39-
40-
Mapping mapping;
41-
};
42-
43-
inline constexpr ConsoleFontFormat LibtcodFormat = { ConsoleFontFormat::ColorKey, ConsoleFontFormat::InRow, ConsoleFontFormat::Special };
44-
inline constexpr ConsoleFontFormat DwarfFortressFormat = { ConsoleFontFormat::ColorKey, ConsoleFontFormat::InRow, ConsoleFontFormat::CodePage437 };
45-
4618
struct GF_GRAPHICS_API ConsoleFontElement {
4719
char16_t character = '\0';
4820
uint8_t index = 0;

include/gf2/graphics/ConsoleGraphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define GF_CONSOLE_GRAPHICS_H
55

66
#include <gf2/core/Console.h>
7+
#include <gf2/core/ConsoleData.h>
78

89
#include "ConsoleFont.h"
910
#include "DynamicBuffer.h"

library/core/ConsoleData.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// SPDX-License-Identifier: Zlib
2+
// Copyright (c) 2023-2025 Julien Bernard
3+
4+
#include <gf2/core/ConsoleData.h>

library/framework/BundleBuilder.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <gf2/core/AnimationData.h>
77
#include <gf2/core/AudioSourceData.h>
8+
#include <gf2/core/ConsoleData.h>
89
#include <gf2/core/FontFace.h>
910
#include <gf2/core/NinePatchData.h>
1011
#include <gf2/core/RichMapResource.h>
@@ -58,6 +59,11 @@ namespace gf {
5859
}
5960
}
6061

62+
void BundleBuilder::add_in_bundle(const ConsoleResource& resource)
63+
{
64+
add_raw_console_font(resource.console_font, resource.data);
65+
}
66+
6167
void BundleBuilder::add_in_bundle(const NinePatchResource& resource)
6268
{
6369
add_raw_texture(resource.texture);
@@ -111,6 +117,12 @@ namespace gf {
111117
m_musics.push_back(path);
112118
}
113119

120+
void BundleBuilder::add_raw_console_font(const std::filesystem::path& path, const ConsoleData& data)
121+
{
122+
m_console_fonts.push_back({ path, data });
123+
}
124+
125+
114126
ResourceBundle BundleBuilder::make_bundle() const
115127
{
116128
// capture 'this' by copy in case the bundle builder is a local variable
@@ -134,6 +146,11 @@ namespace gf {
134146
for (const std::filesystem::path& music : m_musics) {
135147
bundle->handle<Music>(music, m_audio_manager, resource_manager, action);
136148
}
149+
150+
for (const ConsoleResource& console_resource : m_console_fonts) {
151+
bundle->handle<ConsoleFont>(console_resource.console_font, { console_resource.data.font_format, console_resource.data.font_size, m_render_manager }, resource_manager, action);
152+
}
153+
137154
});
138155

139156
return bundle;

0 commit comments

Comments
 (0)