Skip to content

Commit 65e238b

Browse files
committed
Add suggested changes to PR
1 parent 8c1b8a5 commit 65e238b

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

src/anim.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace anim
1414
{
15-
std::vector<std::string> gen_healthbar(models::Pokemon& pkmn)
15+
std::vector<std::string> gen_healthbar(const models::Pokemon& pkmn)
1616
{
1717
/*
1818
* bulbasaur :L30 // label
@@ -41,10 +41,10 @@ std::vector<std::string> gen_healthbar(models::Pokemon& pkmn)
4141

4242
void print_splash_screen(const std::filesystem::path& assets_dir)
4343
{
44-
auto logo = utils::read_file(assets_dir / std::filesystem::path("splashscreen.txt"));
44+
auto logo = utils::read_file(assets_dir / "splashscreen.txt");
4545
std::cout << utils::style(std::accumulate(logo.begin(), logo.end(), std::string("")), utils::Color::YELLOW) << '\n';
4646

47-
std::cout << '\n' << std::string(19, ' ');
47+
std::cout << '\n' << std::setfill(' ') << std::setw(19);
4848

4949
for (const char& c : "copyright (c) 2021 cpp-gamedev")
5050
{
@@ -81,7 +81,7 @@ std::vector<models::Pokemon> load_main_menu(utils::Manifest manifest)
8181
return {player, pkmns.size() > 1 ? utils::random_choice(pkmns) : pkmns[0]};
8282
}
8383

84-
void print_frame(models::Pokemon& pkmn1, models::Pokemon& pkmn2)
84+
void print_frame(const models::Pokemon& pkmn1, const models::Pokemon& pkmn2)
8585
{
8686
std::string healthbars{};
8787
std::string sprites{};

src/anim.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace anim
99
{
10-
std::vector<std::string> gen_healthbar(models::Pokemon& pkmn);
10+
std::vector<std::string> gen_healthbar(const models::Pokemon& pkmn);
1111

1212
void print_splash_screen(const std::filesystem::path& assets_dir);
1313

1414
std::vector<models::Pokemon> load_main_menu(utils::Manifest manifest);
1515

16-
void print_frame(models::Pokemon& pkmn1, models::Pokemon& pkmn2);
16+
void print_frame(const models::Pokemon& pkmn1, const models::Pokemon& pkmn2);
1717
} // namespace anim

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace utils;
1515
int main()
1616
{
1717
const auto assets_dir = find_upwards("assets");
18-
Manifest manifest = check_manifest(assets_dir.parent_path() / std::filesystem::path("manifest.json"));
18+
Manifest manifest = check_manifest(assets_dir.parent_path() / "manifest.json");
1919

2020
if (std::filesystem::exists(assets_dir) && manifest.game_ready)
2121
{
@@ -36,7 +36,7 @@ int main()
3636
}
3737
else
3838
{
39-
std::cerr << "Error!" << '\n';
39+
std::cerr << "Error: The assets directory is in an invalid state. Consult the README for further instructions." << '\n';
4040
return EXIT_FAILURE;
4141
}
4242
}

src/models.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace models
1313
{
1414
std::vector<std::string> Pokemon::read_asset(std::string ext)
1515
{
16-
std::filesystem::path ext_dir = (ext == "txt") ? std::filesystem::path("textures") : std::filesystem::path("data");
17-
return utils::read_file(assets_dir / ext_dir / std::filesystem::path(kt::format_str("{}.{}", std::to_string(this->id), ext)));
16+
return utils::read_file(assets_dir / ((ext == "txt") ? "textures" : "data") / kt::format_str("{}.{}", std::to_string(this->id), ext));
1817
}
1918

2019
void Pokemon::configure_move_set()

src/utils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ std::string style(std::string text, Color fore, Color back)
3838
return ansi_text.append(kt::format_str("{}\033[0m", text));
3939
}
4040

41-
std::string upper(std::string& str)
41+
void upper(std::string& str)
4242
{
4343
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return toupper(c); });
44-
return str;
4544
}
4645

47-
std::string lower(std::string& str)
46+
void lower(std::string& str)
4847
{
4948
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return tolower(c); });
50-
return str;
5149
}
5250

5351
std::filesystem::path find_upwards(std::string dir_name, int max_depth)
5452
{
55-
auto path = std::filesystem::current_path() / std::filesystem::path(dir_name);
53+
auto path = std::filesystem::current_path() / dir_name;
5654

5755
while (!std::filesystem::exists(path) && max_depth > 0)
5856
{
@@ -99,16 +97,18 @@ void print_enum_table(std::vector<std::string> table, std::string header)
9997
std::string horizontal_line = utils::style(std::string("+").append(std::string(width - 2, '-')).append("+"), border_color);
10098

10199
std::cout << horizontal_line << '\n';
102-
std::cout << border << kt::format_str(" {}{}", upper(header), std::string(width - 3 - header.length(), ' ')) << border << '\n';
100+
upper(header);
101+
std::cout << border << kt::format_str(" {}{}", header, std::string(width - 3 - header.length(), ' ')) << border << '\n';
103102

104103
// clang-format off
105104
auto padded_string = [](int i, std::string str, std::string limits) {
106-
return kt::format_str("{} {}. {}{}{}", limits, i, lower(str), std::string(54 - str.length(), ' '), limits);
105+
return kt::format_str("{} {}. {}{}{}", limits, i, str, std::string(54 - str.length(), ' '), limits);
107106
};
108107
// clang-format on
109108

110109
for (std::size_t i = 0; i < table.size(); ++i)
111110
{
111+
lower(table[i]);
112112
std::cout << padded_string(i + 1, table[i], border) << '\n';
113113
}
114114

src/utils.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ T random_range(T min, T max)
3232
///
3333
/// \brief Return k random values in range of [min, max] (with repitition)
3434
///
35-
template <typename T>
36-
std::vector<T> random_ranges(T min, T max, std::size_t k)
35+
template <typename T, typename U>
36+
std::vector<T> random_ranges(T min, T max, U k)
3737
{
3838
std::vector<T> vector(k);
3939
std::generate(vector.begin(), vector.end(), [min, max]() { return random_range(min, max); });
@@ -52,8 +52,8 @@ T random_choice(const std::vector<T>& vector)
5252
///
5353
/// \brief Return k random elements from vector (with repitition)
5454
///
55-
template <typename T>
56-
std::vector<T> random_choices(const std::vector<T>& vector, std::size_t k)
55+
template <typename T, typename U>
56+
std::vector<T> random_choices(const std::vector<T>& vector, U k)
5757
{
5858
std::vector<T> choices(k);
5959
std::generate(choices.begin(), choices.end(), [&]() { return random_choice(vector); });
@@ -87,9 +87,9 @@ enum class Color
8787

8888
std::string style(std::string text, Color fore, Color back = Color::BLACK);
8989

90-
std::string upper(std::string& str);
90+
void upper(std::string& str);
9191

92-
std::string lower(std::string& str);
92+
void lower(std::string& str);
9393

9494
std::filesystem::path find_upwards(std::string dir_name, int max_depth = 10);
9595

0 commit comments

Comments
 (0)