Rework the GUI so it uses SFMLBackend by moving the SoundQuip into SFMLBackend.

master
Zed A. Shaw 2 months ago
parent 1badbd5942
commit c0ad0c8d23
  1. 20
      gui.cpp
  2. 20
      gui.hpp
  3. 22
      sfmlbackend.cpp
  4. 15
      sfmlbackend.hpp

@ -8,7 +8,6 @@
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
#include <fstream>
#include "sfmlbackend.hpp"
#include "builder.hpp"
using std::string, std::vector;
@ -17,25 +16,6 @@ using namespace fmt;
using namespace nlohmann;
namespace fs = std::filesystem;
void SoundQuip::load(json &data, const char *file_key) {
auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<string>();
if(!buffer.loadFromFile(file_name)) {
println("Failed to load sound: {} with file {}", file_key, file_name);
}
sound.setBuffer(buffer);
}
void SoundQuip::play() {
sound.play();
}
void SoundQuip::stop() {
sound.stop();
}
GUI::GUI() {
std::ifstream infile(".tarpit.json");
json data = json::parse(infile);

@ -1,29 +1,13 @@
#pragma once
#include <efsw/efsw.hpp>
#include "game_engine.hpp"
#include <filesystem>
#include <string>
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
#include "game_engine.hpp"
#include "sfmlbackend.hpp"
using std::string;
class Builder;
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 {
std::vector<string> _lines;

@ -9,11 +9,33 @@
#include <SFML/Graphics/Text.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window/Event.hpp>
#include <nlohmann/json.hpp>
#include "sfmlbackend.hpp"
using namespace fmt;
using namespace nlohmann;
using namespace ImGui;
using std::string;
void SoundQuip::load(json &data, const char *file_key) {
auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<string>();
if(!buffer.loadFromFile(file_name)) {
println("Failed to load sound: {} with file {}", file_key, file_name);
}
sound.setBuffer(buffer);
}
void SoundQuip::play() {
sound.play();
}
void SoundQuip::stop() {
sound.stop();
}
void SFMLBackend::ImGui_setup() {
bool res = SFML::Init(window);
fmt::println("IMGUI returned {}", res);

@ -3,6 +3,8 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
#include "game_engine.hpp"
#include <string>
@ -15,6 +17,19 @@ constexpr int TEXT_SIZE = 48;
constexpr int Y_LINES = 23;
constexpr int X_ROWS = 48;
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 SFMLBackend {
sf::ContextSettings settings;
sf::RenderWindow window;

Loading…
Cancel
Save