70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
#include "camera.hpp"
|
|
#include <fmt/core.h>
|
|
#include "animation.hpp"
|
|
#include <unordered_map>
|
|
#include "components.hpp"
|
|
#include "config.hpp"
|
|
|
|
namespace cinematic {
|
|
using components::Animation, std::string;
|
|
|
|
struct CameraManager {
|
|
std::unordered_map<string, Animation> 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<Animation>(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::focus(float x, float y) {
|
|
position.x = x;
|
|
position.y = y;
|
|
}
|
|
|
|
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
|
sf::View zoom;
|
|
|
|
// BUG: annoying special case
|
|
if(anim.motion == ease::SLIDE) {
|
|
anim.min_x = position.x;
|
|
anim.min_y = position.y;
|
|
anim.max_x = pos.x;
|
|
anim.max_y = pos.y;
|
|
}
|
|
|
|
anim.apply(zoom, pos, size);
|
|
target.setView(zoom);
|
|
}
|
|
|
|
bool Camera::playing() {
|
|
return anim.playing;
|
|
}
|
|
|
|
void Camera::play() {
|
|
anim.play();
|
|
}
|
|
}
|