Rework the GUI so it uses SFMLBackend by moving the SoundQuip into SFMLBackend.
This commit is contained in:
parent
1badbd5942
commit
c0ad0c8d23
4 changed files with 39 additions and 38 deletions
20
gui.cpp
20
gui.cpp
|
@ -8,7 +8,6 @@
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "sfmlbackend.hpp"
|
|
||||||
#include "builder.hpp"
|
#include "builder.hpp"
|
||||||
|
|
||||||
using std::string, std::vector;
|
using std::string, std::vector;
|
||||||
|
@ -17,25 +16,6 @@ using namespace fmt;
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
namespace fs = std::filesystem;
|
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() {
|
GUI::GUI() {
|
||||||
std::ifstream infile(".tarpit.json");
|
std::ifstream infile(".tarpit.json");
|
||||||
json data = json::parse(infile);
|
json data = json::parse(infile);
|
||||||
|
|
20
gui.hpp
20
gui.hpp
|
@ -1,29 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <efsw/efsw.hpp>
|
|
||||||
#include "game_engine.hpp"
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <SFML/Audio.hpp>
|
#include "game_engine.hpp"
|
||||||
#include <nlohmann/json.hpp>
|
#include "sfmlbackend.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class Builder;
|
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 {
|
class GUI {
|
||||||
std::vector<string> _lines;
|
std::vector<string> _lines;
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,33 @@
|
||||||
#include <SFML/Graphics/Text.hpp>
|
#include <SFML/Graphics/Text.hpp>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include "sfmlbackend.hpp"
|
#include "sfmlbackend.hpp"
|
||||||
|
|
||||||
|
using namespace fmt;
|
||||||
|
using namespace nlohmann;
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
using std::string;
|
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() {
|
void SFMLBackend::ImGui_setup() {
|
||||||
bool res = SFML::Init(window);
|
bool res = SFML::Init(window);
|
||||||
fmt::println("IMGUI returned {}", res);
|
fmt::println("IMGUI returned {}", res);
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
#include <SFML/Graphics/Font.hpp>
|
#include <SFML/Graphics/Font.hpp>
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include "game_engine.hpp"
|
#include "game_engine.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -15,6 +17,19 @@ constexpr int TEXT_SIZE = 48;
|
||||||
constexpr int Y_LINES = 23;
|
constexpr int Y_LINES = 23;
|
||||||
constexpr int X_ROWS = 48;
|
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 {
|
class SFMLBackend {
|
||||||
sf::ContextSettings settings;
|
sf::ContextSettings settings;
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue