raycaster/scene.hpp

60 lines
2 KiB
C++

#pragma once
#include <memory>
#include <unordered_map>
#include "components.hpp"
#include "textures.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <guecs/ui.hpp>
#include "camera.hpp"
namespace scene {
using std::shared_ptr;
using namespace textures;
struct Element {
std::string name;
textures::SpriteTexture st;
components::Animation anim;
std::string cell;
float scale_x = 1.0f;
float scale_y = 1.0f;
float x = 0;
float y = 0;
bool at_mid=false;
bool flipped=false;
std::shared_ptr<sf::Shader> effect = nullptr;
sf::Text text;
sf::Vector2f pos{0,0};
};
struct Engine {
guecs::UI $ui;
components::AnimatedScene& $scene;
std::string $layout;
std::unordered_map<std::string, int> $actor_name_ids;
std::vector<Element> $fixtures;
std::vector<Element> $actors;
cinematic::Camera $camera{{BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}};
Engine(components::AnimatedScene& scene);
void init();
void render(sf::RenderTexture& view);
bool mouse(float x, float y, guecs::Modifiers mods);
void attach_text(const std::string& actor, const std::string& text);
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped);
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
void move_actor(const std::string& actor, const std::string& cell_name);
void animate_actor(const std::string& actor);
void play_animations();
void apply_effect(const std::string& actor, const std::string& shader);
Element& actor_config(const std::string& actor);
void zoom(const std::string& actor, const std::string& style, float scale=0.9f);
void zoom(float mid_x, float mid_y, const std::string& style, float scale);
void reset(sf::RenderTexture& view);
std::pair<Element&, Element&> left_right(const std::string &actor, const std::string &target);
};
}