I can now load a json config file name .tarpit.json to configure everything. It now works to configure the sounds used.
This commit is contained in:
parent
268d8abf52
commit
90f4f727ba
8 changed files with 91 additions and 17 deletions
9
.tarpit.json
Normal file
9
.tarpit.json
Normal file
|
@ -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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if(argc != 3) {
|
if(argc != 3) {
|
||||||
fmt::println("USAGE: watchgit PATH BUILD_CMD");
|
fmt::println("USAGE: escape_turings_tarpit PATH BUILD_CMD");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
const char *git_path = argv[1];
|
const char *git_path = argv[1];
|
||||||
|
|
36
gui.cpp
36
gui.cpp
|
@ -14,25 +14,47 @@
|
||||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
using namespace nlohmann;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
void load_sound(sf::Sound &sound, sf::SoundBuffer &buffer, const char *in_file) {
|
SoundQuip::SoundQuip() {
|
||||||
if(!buffer.loadFromFile(in_file)) {
|
|
||||||
fmt::println("Failed to load {}", in_file);
|
};
|
||||||
|
|
||||||
|
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);
|
sound.setBuffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundQuip::play() {
|
||||||
|
sound.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundQuip::stop() {
|
||||||
|
sound.stop();
|
||||||
|
}
|
||||||
|
|
||||||
GUI::GUI() {
|
GUI::GUI() {
|
||||||
load_sound(you_died_sound, you_died_buffer, "./assets/you_died.wav");
|
ifstream infile(".tarpit.json");
|
||||||
load_sound(build_works_sound, build_works_buffer, "./assets/build_works.wav");
|
json data = json::parse(infile);
|
||||||
load_sound(build_failed_sound, build_failed_buffer, "./assets/build_failed.wav");
|
|
||||||
load_sound(building_sound, building_buffer, "./assets/building.wav");
|
// 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) {
|
void GUI::output(const string &msg) {
|
||||||
|
|
26
gui.hpp
26
gui.hpp
|
@ -5,18 +5,28 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <SFML/Audio.hpp>
|
#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 {
|
class GUI {
|
||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
|
|
||||||
sf::Sound you_died_sound;
|
SoundQuip you_died_sound;
|
||||||
sf::Sound build_works_sound;
|
SoundQuip build_works_sound;
|
||||||
sf::Sound build_failed_sound;
|
SoundQuip build_failed_sound;
|
||||||
sf::Sound building_sound;
|
SoundQuip building_sound;
|
||||||
sf::SoundBuffer you_died_buffer;
|
|
||||||
sf::SoundBuffer build_works_buffer;
|
|
||||||
sf::SoundBuffer build_failed_buffer;
|
|
||||||
sf::SoundBuffer building_buffer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
27
jsontest.cpp
Normal file
27
jsontest.cpp
Normal file
|
@ -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')
|
ftxui_component = dependency('ftxui-component')
|
||||||
catch2 = dependency('catch2-with-main')
|
catch2 = dependency('catch2-with-main')
|
||||||
sfml = dependency('sfml')
|
sfml = dependency('sfml')
|
||||||
|
json = dependency('nlohmann_json')
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
fmt, libgit2package_dep, efsw_dep,
|
fmt, libgit2package_dep, efsw_dep,
|
||||||
ftxui_screen, ftxui_dom, ftxui_component,
|
ftxui_screen, ftxui_dom, ftxui_component,
|
||||||
sfml
|
sfml, json
|
||||||
]
|
]
|
||||||
|
|
||||||
executable('escape_turings_tarpit',
|
executable('escape_turings_tarpit',
|
||||||
|
@ -47,6 +48,9 @@ executable('ftx_thread_test', 'ftx_thread_test.cpp',
|
||||||
executable('audiotest', 'audiotest.cpp',
|
executable('audiotest', 'audiotest.cpp',
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
|
executable('jsontest', 'jsontest.cpp',
|
||||||
|
dependencies: dependencies)
|
||||||
|
|
||||||
runtests = executable('runtests', [
|
runtests = executable('runtests', [
|
||||||
'game_engine.cpp',
|
'game_engine.cpp',
|
||||||
'tests/game_engine.cpp'],
|
'tests/game_engine.cpp'],
|
||||||
|
|
|
@ -16,6 +16,7 @@ meson wrap install flac
|
||||||
meson wrap install freetype2
|
meson wrap install freetype2
|
||||||
meson wrap install openal-soft
|
meson wrap install openal-soft
|
||||||
meson wrap install sfml
|
meson wrap install sfml
|
||||||
|
meson wrap install nlohmann_json
|
||||||
# $env:CC="clang"
|
# $env:CC="clang"
|
||||||
# $env:CXX="clang++"
|
# $env:CXX="clang++"
|
||||||
meson setup --default-library=static --prefer-static builddir
|
meson setup --default-library=static --prefer-static builddir
|
||||||
|
|
|
@ -19,4 +19,5 @@ meson wrap install flac
|
||||||
meson wrap install freetype2
|
meson wrap install freetype2
|
||||||
meson wrap install openal-soft
|
meson wrap install openal-soft
|
||||||
meson wrap install sfml
|
meson wrap install sfml
|
||||||
|
meson wrap install nlohmann_json
|
||||||
meson setup builddir
|
meson setup builddir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue