#include "camera.hpp" #include #include "animation.hpp" #include #include "components.hpp" #include "config.hpp" namespace cinematic { using components::Animation, std::string; struct CameraManager { std::unordered_map animations; }; static CameraManager MGR; static bool initialized = false; void init() { if(!initialized) { auto cameras = settings::get("cameras"); for(auto &[name, data] : cameras.json().items()) { auto anim = components::convert(data); MGR.animations.try_emplace(name, anim); } initialized = true; } } Camera::Camera() : anim(MGR.animations.at("pan")) { } void Camera::resize(sf::Vector2f to) { size = to; } void Camera::style(const std::string &name) { anim = MGR.animations.at(name); } void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) { sf::View zoom; anim.apply(zoom, pos, size); target.setView(zoom); } bool Camera::playing() { return anim.playing; } void Camera::play() { anim.play(); } }