R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
scoreboard.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <cstddef>
5#include <cstdint>
6#include <filesystem>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace rtype {
13
15struct ScoreEntry {
17 std::string name;
19 std::uint32_t score = 0;
20
23 bool operator==(const ScoreEntry&) const = default;
24};
25
35public:
37 static constexpr std::size_t max_entries = 10;
38
41 explicit Scoreboard(std::filesystem::path file);
42
48 bool record(std::string_view name, std::uint32_t score);
49
52 [[nodiscard]] const std::vector<ScoreEntry>& best() const noexcept;
53
56 [[nodiscard]] const std::optional<std::string>& load_error() const noexcept;
57
60 [[nodiscard]] const std::filesystem::path& file() const noexcept;
61
62private:
63 void load();
64 void save() const;
65
66 std::filesystem::path file_;
67 std::vector<ScoreEntry> best_;
68 std::optional<std::string> load_error_;
69};
70
71} // namespace rtype
The max_entries best scores, best first, kept in a JSON file.
Definition scoreboard.hpp:34
Scoreboard(std::filesystem::path file)
Reads the board of a file.
const std::optional< std::string > & load_error() const noexcept
Why the file could not be read at start.
const std::filesystem::path & file() const noexcept
Where the board is kept.
static constexpr std::size_t max_entries
Most scores kept.
Definition scoreboard.hpp:37
bool record(std::string_view name, std::uint32_t score)
Adds a score, if it is among the best.
const std::vector< ScoreEntry > & best() const noexcept
The best scores.
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
One score of the board.
Definition scoreboard.hpp:15
std::string name
Name of the player, as valid_player_name() accepts it.
Definition scoreboard.hpp:17
bool operator==(const ScoreEntry &) const =default
Field-by-field equality.
std::uint32_t score
Points at the end of its game.
Definition scoreboard.hpp:19