I can now load a json config file name .tarpit.json to configure everything. It now works to configure the sounds used.

master
Zed A. Shaw 4 months ago
parent 268d8abf52
commit 90f4f727ba
  1. 9
      .tarpit.json
  2. 2
      escape_turings_tarpit.cpp
  3. 36
      gui.cpp
  4. 26
      gui.hpp
  5. 27
      jsontest.cpp
  6. 6
      meson.build
  7. 1
      scripts/reset_build.ps1
  8. 1
      scripts/reset_build.sh

@ -0,0 +1,9 @@
{
"audio": {
"you_died": "./assets/you_died.wav",
"build_works": "./assets/build_works.wav",
"build_failed": "./assets/build_failed.wav",
"building": "./assets/building.wav"
},
"build_cmd": "meson compile -C builddir"
}

@ -4,7 +4,7 @@
int main(int argc, char *argv[])
{
if(argc != 3) {
fmt::println("USAGE: watchgit PATH BUILD_CMD");
fmt::println("USAGE: escape_turings_tarpit PATH BUILD_CMD");
return 1;
} else {
const char *git_path = argv[1];

@ -14,25 +14,47 @@
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include <vector>
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
#include <fstream>
using namespace ftxui;
using namespace std;
using namespace fmt;
using namespace nlohmann;
namespace fs = std::filesystem;
void load_sound(sf::Sound &sound, sf::SoundBuffer &buffer, const char *in_file) {
if(!buffer.loadFromFile(in_file)) {
fmt::println("Failed to load {}", in_file);
SoundQuip::SoundQuip() {
};
void SoundQuip::load(json &data, const char *file_key) {
auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<std::string>();
if(!buffer.loadFromFile(file_name)) {
cout << "Failed to load sound: " << file_key << " with file " << file_name << "\n";
}
sound.setBuffer(buffer);
}
void SoundQuip::play() {
sound.play();
}
void SoundQuip::stop() {
sound.stop();
}
GUI::GUI() {
load_sound(you_died_sound, you_died_buffer, "./assets/you_died.wav");
load_sound(build_works_sound, build_works_buffer, "./assets/build_works.wav");
load_sound(build_failed_sound, build_failed_buffer, "./assets/build_failed.wav");
load_sound(building_sound, building_buffer, "./assets/building.wav");
ifstream infile(".tarpit.json");
json data = json::parse(infile);
// json load the config file
you_died_sound.load(data, "you_died");
build_works_sound.load(data, "build_works");
build_failed_sound.load(data, "build_failed");
building_sound.load(data, "building");
}
void GUI::output(const string &msg) {

@ -5,18 +5,28 @@
#include <filesystem>
#include <string>
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
class SoundQuip {
public:
sf::Sound sound;
sf::SoundBuffer buffer;
bool initialized;
SoundQuip();
void load(nlohmann::json &data, const char *in_file);
void play();
void stop();
};
class GUI {
vector<string> lines;
sf::Sound you_died_sound;
sf::Sound build_works_sound;
sf::Sound build_failed_sound;
sf::Sound building_sound;
sf::SoundBuffer you_died_buffer;
sf::SoundBuffer build_works_buffer;
sf::SoundBuffer build_failed_buffer;
sf::SoundBuffer building_buffer;
SoundQuip you_died_sound;
SoundQuip build_works_sound;
SoundQuip build_failed_sound;
SoundQuip building_sound;
public:

@ -0,0 +1,27 @@
#include <iostream>
#include <fstream>
#include <fmt/core.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace fmt;
using namespace std;
int main(int argc, char *argv[]) {
if(argc != 2) {
println("USAGE: jsontest [jsonfile]");
return 0;
}
ifstream infile(argv[1]);
json data = json::parse(infile);
json::string_t s2 = data["happy"].template get<std::string>();
for(auto &el : data.items()) {
cout << el.key() << "=" << el.value() << "\n";
}
println("DATA HAPPY {}", s2);
return 0;
}

@ -20,11 +20,12 @@ ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component')
catch2 = dependency('catch2-with-main')
sfml = dependency('sfml')
json = dependency('nlohmann_json')
dependencies = [
fmt, libgit2package_dep, efsw_dep,
ftxui_screen, ftxui_dom, ftxui_component,
sfml
sfml, json
]
executable('escape_turings_tarpit',
@ -47,6 +48,9 @@ executable('ftx_thread_test', 'ftx_thread_test.cpp',
executable('audiotest', 'audiotest.cpp',
dependencies: dependencies)
executable('jsontest', 'jsontest.cpp',
dependencies: dependencies)
runtests = executable('runtests', [
'game_engine.cpp',
'tests/game_engine.cpp'],

@ -16,6 +16,7 @@ meson wrap install flac
meson wrap install freetype2
meson wrap install openal-soft
meson wrap install sfml
meson wrap install nlohmann_json
# $env:CC="clang"
# $env:CXX="clang++"
meson setup --default-library=static --prefer-static builddir

@ -19,4 +19,5 @@ meson wrap install flac
meson wrap install freetype2
meson wrap install openal-soft
meson wrap install sfml
meson wrap install nlohmann_json
meson setup builddir

Loading…
Cancel
Save