Can now specify a background to render the sprite on.
This commit is contained in:
parent
fc01579232
commit
77643a4bcd
3 changed files with 85 additions and 10 deletions
|
|
@ -21,5 +21,28 @@
|
|||
"toggled": false,
|
||||
"looped": true
|
||||
}
|
||||
},
|
||||
"rat_king_meth": {
|
||||
"sheet": {
|
||||
"frames": 2,
|
||||
"frame_width": 720,
|
||||
"frame_height": 720
|
||||
},
|
||||
"sequence": {
|
||||
"frames": [0, 1],
|
||||
"durations": [33, 33]
|
||||
},
|
||||
"transform": {
|
||||
"min_x": 0.6,
|
||||
"min_y": 0.6,
|
||||
"max_x": 0.8,
|
||||
"max_y": 0.8,
|
||||
"simple": false,
|
||||
"flipped": false,
|
||||
"ease_rate": 5.0,
|
||||
"scaled": true,
|
||||
"toggled": false,
|
||||
"looped": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,16 @@
|
|||
#include "constants.hpp"
|
||||
#include "animate2.hpp"
|
||||
#include "tools/animator.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*
|
||||
* - Setting a background.
|
||||
* - Options parsing for that.
|
||||
* - Easing functions from strings in json.
|
||||
* - Map of animation forms.
|
||||
*/
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
|
@ -15,9 +25,11 @@ bool YES_SYNC=true;
|
|||
|
||||
namespace animator {
|
||||
|
||||
void FSM::init(const std::string &sprite_name) {
|
||||
void FSM::init(const std::string &sprite_name, const std::string &anim_name, const std::string &background) {
|
||||
$timer.start();
|
||||
$sprite_name = sprite_name;
|
||||
$anim_name = anim_name;
|
||||
$background = background;
|
||||
|
||||
// this loads the animation
|
||||
reload();
|
||||
|
|
@ -26,7 +38,7 @@ namespace animator {
|
|||
$window = sf::RenderWindow(sf::VideoMode(new_size), "Animation Crafting Tool");
|
||||
$window.setPosition({0,0});
|
||||
|
||||
$ui.init($sprite_name, new_size.x, new_size.y);
|
||||
$ui.init($sprite_name, $background, new_size.x, new_size.y);
|
||||
$sprite = $ui.get_sprite();
|
||||
|
||||
// need to keep these aroung
|
||||
|
|
@ -37,7 +49,6 @@ namespace animator {
|
|||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FSM::event(Event ev, std::any data) {
|
||||
|
|
@ -111,7 +122,7 @@ namespace animator {
|
|||
}
|
||||
|
||||
void FSM::reload() {
|
||||
$anim = animate2::load("assets/animate2.json", $sprite_name);
|
||||
$anim = animate2::load("assets/animate2.json", $anim_name);
|
||||
$anim.play();
|
||||
$last_mod_time = std::filesystem::last_write_time("assets/animate2.json");
|
||||
}
|
||||
|
|
@ -153,10 +164,16 @@ namespace animator {
|
|||
return !in_state(State::END);
|
||||
}
|
||||
|
||||
void UI::init(const std::string& sprite_name, int width, int height) {
|
||||
void UI::init(const std::string& sprite_name, const std::string& background, int width, int height) {
|
||||
$ui.position(0,0, width, height);
|
||||
$ui.layout("[=viewer]");
|
||||
|
||||
if(background != "") {
|
||||
$ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
|
||||
auto& bg = $ui.get<guecs::Background>($ui.MAIN);
|
||||
bg.set_sprite(background, true);
|
||||
}
|
||||
|
||||
auto viewer = $ui.entity("viewer");
|
||||
$ui.set<guecs::Sprite>(viewer, { sprite_name, 0, false});
|
||||
|
||||
|
|
@ -181,6 +198,11 @@ namespace animator {
|
|||
}
|
||||
}
|
||||
|
||||
int error() {
|
||||
fmt::println("USAGE: animator -h -b <background> -s <sprite> -a <animation>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
shaders::init();
|
||||
components::init();
|
||||
|
|
@ -189,14 +211,42 @@ int main(int argc, char* argv[]) {
|
|||
ai::init("ai");
|
||||
animation::init();
|
||||
|
||||
dbc::check(argc == 2, "USAGE: animator <sprite>");
|
||||
std::string sprite_name{argv[1]};
|
||||
std::string sprite_name;
|
||||
std::string background;
|
||||
std::string anim_name;
|
||||
int opt = 0;
|
||||
|
||||
while((opt = getopt(argc, argv, "hb:s:a:")) != -1) {
|
||||
switch(opt) {
|
||||
case 'b':
|
||||
background = optarg;
|
||||
break;
|
||||
case 's':
|
||||
sprite_name = optarg;
|
||||
break;
|
||||
case 'a':
|
||||
anim_name = optarg;
|
||||
break;
|
||||
case 'h': // fallthrough
|
||||
error();
|
||||
break;
|
||||
default:
|
||||
return error();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(sprite_name == "") {
|
||||
return error();
|
||||
} else if(anim_name == "") {
|
||||
anim_name = sprite_name; // default to the same
|
||||
}
|
||||
|
||||
sound::mute(true);
|
||||
sound::play("ambient_1", true);
|
||||
|
||||
animator::FSM main;
|
||||
main.init(sprite_name);
|
||||
main.init(sprite_name, anim_name, background);
|
||||
|
||||
while(main.active()) {
|
||||
main.tick();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace animator {
|
|||
guecs::UI $ui;
|
||||
|
||||
void button(const std::string& name, std::function<void(guecs::Modifiers mods)> cb);
|
||||
void init(const std::string& sprite_name, int width, int height);
|
||||
void init(const std::string& sprite_name, const std::string& background, int width, int height);
|
||||
void render(sf::RenderWindow& window, bool debug=false);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
std::shared_ptr<sf::Sprite> get_sprite();
|
||||
|
|
@ -40,10 +40,12 @@ namespace animator {
|
|||
std::shared_ptr<sf::Sprite> $sprite = nullptr;
|
||||
animate2::Animate2 $anim;
|
||||
std::string $sprite_name="";
|
||||
std::string $anim_name="";
|
||||
std::string $background="";
|
||||
std::filesystem::file_time_type $last_mod_time;
|
||||
sf::Clock $timer;
|
||||
|
||||
void init(const std::string &sprite_name);
|
||||
void init(const std::string &sprite_name, const std::string& background, const std::string &anim_name);
|
||||
void event(Event ev, std::any data={});
|
||||
void START(Event ev);
|
||||
void ANIMATE(Event ev);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue