15#include "absl/status/statusor.h"
16#include "absl/strings/str_cat.h"
33constexpr std::array<const char*, 7> kGroundNames = {
34 "grass",
"sand",
"rock",
"snow",
"ash",
"stone",
"water"};
37 std::vector<Entry> entries;
42 {absl::StrCat(
"Step on ", kGroundNames[
static_cast<int>(ground)]),
43 [ground](uint32_t seed) {
return nanommo::Step(ground, seed); }});
45 for (
const auto& [
id, skill] : skills.
by_id) {
46 const nanommo::skills::Look look = skill.look();
48 entries.push_back({skill.name(), [look](uint32_t seed) {
52 entries.push_back({
"Going through a gate",
54 for (
int land = 0; land < static_cast<int>(
nanommo::kLands.size()); ++land) {
64 DrawRectangleLinesEx(box, 1.0f, DARKGRAY);
65 const float middle = box.y + box.height / 2.0f;
66 DrawLineV({box.x, middle}, {box.x + box.width, middle}, DARKGRAY);
67 if (samples.empty()) {
70 const int columns =
static_cast<int>(box.width);
71 for (
int x = 0; x < columns; ++x) {
72 const std::size_t from = samples.size() * x / columns;
73 const std::size_t to =
74 std::max(samples.size() * (x + 1) / columns, from + 1);
77 for (std::size_t i = from; i < to && i < samples.size(); ++i) {
78 low = std::min(low, samples[i]);
79 high = std::max(high, samples[i]);
81 DrawLineV({box.x + x, middle - high * box.height / 2.0f},
82 {box.x + x, middle - low * box.height / 2.0f}, color);
89 const absl::StatusOr<nanommo::Content> content =
92 std::cerr <<
"nanommo sounds: " << content.status() <<
"\n";
95 absl::StatusOr<std::unique_ptr<nanommo::Window>> window =
98 std::cerr <<
"nanommo sounds: " << window.status() <<
"\n";
101 absl::StatusOr<std::unique_ptr<nanommo::AudioDevice>> audio =
104 std::cerr <<
"nanommo sounds: " << audio.status() <<
"\n";
107 const std::vector<Entry> entries = Entries(content->skills);
111 std::unique_ptr<nanommo::Clip> playing;
112 while (!(*window)->ShouldClose()) {
113 if (IsKeyPressed(KEY_DOWN)) {
114 picked = (picked + 1) %
static_cast<int>(entries.size());
116 if (IsKeyPressed(KEY_UP)) {
117 picked = (picked +
static_cast<int>(entries.size()) - 1) %
118 static_cast<int>(entries.size());
121 if (IsKeyPressed(KEY_SPACE)) {
122 shown = entries[picked].make(++seed);
125 playing->Play(1.0f, 0.0f, 1.0f);
130 ClearBackground({18, 20, 26, 255});
131 for (std::size_t i = 0; i < entries.size(); ++i) {
132 const int y = 20 + 22 *
static_cast<int>(i);
133 const bool here =
static_cast<int>(i) == picked;
135 DrawRectangle(12, y - 3, 300, 22, {179, 18, 42, 255});
137 DrawText(entries[i].name.c_str(), 20, y, 18, here ? WHITE : LIGHTGRAY);
139 DrawWave(shown, {340.0f, 60.0f, 600.0f, 420.0f}, {255, 140, 90, 255});
140 DrawText(absl::StrCat(entries[picked].name,
", take ", seed).c_str(), 340,
142 DrawText(absl::StrCat(
static_cast<float>(shown.size()) /
nanommo::kRate,
static absl::StatusOr< std::unique_ptr< AudioDevice > > Create()
static std::unique_ptr< Clip > Load(const AudioDevice &device, const Samples &samples, int voices)
static absl::StatusOr< std::unique_ptr< Window > > Create(const std::string &title, int width, int height, Visibility visibility=Visibility::kShown)
std::vector< float > Samples
One channel of sound, at kRate.
Samples SkillSound(const skills::Look &look, uint32_t seed, bool target)
Place Arrival(const Gate &gate, float yaw)
constexpr std::array< Land, 3 > kLands
Ground
What a foot comes down on, which is how the step sounds.
Samples Step(Ground ground, uint32_t seed)
std::string ContentFolder()
constexpr std::array< Ground, 7 > kGrounds
Samples Departure(uint32_t seed)
Going through a gate: a rush up, as the screen covers the world.
absl::StatusOr< Content > ReadContent(const std::string &folder)
Reads each file in the folder, or says which file is wrong, and where.
std::map< uint32_t, skills::Skill > by_id