Compare commits
No commits in common. "383f839fdf447b53ffc1101aec2f391064097ba4" and "fc015792328992f9bf852374ba1807de61921bd2" have entirely different histories.
383f839fdf
...
fc01579232
4 changed files with 11 additions and 86 deletions
2
Makefile
2
Makefile
|
|
@ -78,4 +78,4 @@ story:
|
||||||
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/storyboard
|
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/storyboard
|
||||||
|
|
||||||
animator:
|
animator:
|
||||||
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/animator.exe -s "rat_king_boss" -a "rat_king_boss" -b "test_background"
|
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/animator "rat_king_boss"
|
||||||
|
|
|
||||||
|
|
@ -21,28 +21,5 @@
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true
|
"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,16 +8,6 @@
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "animate2.hpp"
|
#include "animate2.hpp"
|
||||||
#include "tools/animator.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;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
|
@ -25,11 +15,9 @@ bool YES_SYNC=true;
|
||||||
|
|
||||||
namespace animator {
|
namespace animator {
|
||||||
|
|
||||||
void FSM::init(const std::string &sprite_name, const std::string &anim_name, const std::string &background) {
|
void FSM::init(const std::string &sprite_name) {
|
||||||
$timer.start();
|
$timer.start();
|
||||||
$sprite_name = sprite_name;
|
$sprite_name = sprite_name;
|
||||||
$anim_name = anim_name;
|
|
||||||
$background = background;
|
|
||||||
|
|
||||||
// this loads the animation
|
// this loads the animation
|
||||||
reload();
|
reload();
|
||||||
|
|
@ -38,7 +26,7 @@ namespace animator {
|
||||||
$window = sf::RenderWindow(sf::VideoMode(new_size), "Animation Crafting Tool");
|
$window = sf::RenderWindow(sf::VideoMode(new_size), "Animation Crafting Tool");
|
||||||
$window.setPosition({0,0});
|
$window.setPosition({0,0});
|
||||||
|
|
||||||
$ui.init($sprite_name, $background, new_size.x, new_size.y);
|
$ui.init($sprite_name, new_size.x, new_size.y);
|
||||||
$sprite = $ui.get_sprite();
|
$sprite = $ui.get_sprite();
|
||||||
|
|
||||||
// need to keep these aroung
|
// need to keep these aroung
|
||||||
|
|
@ -49,6 +37,7 @@ namespace animator {
|
||||||
$window.setVerticalSyncEnabled(VSYNC);
|
$window.setVerticalSyncEnabled(VSYNC);
|
||||||
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
|
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::event(Event ev, std::any data) {
|
void FSM::event(Event ev, std::any data) {
|
||||||
|
|
@ -122,7 +111,7 @@ namespace animator {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::reload() {
|
void FSM::reload() {
|
||||||
$anim = animate2::load("assets/animate2.json", $anim_name);
|
$anim = animate2::load("assets/animate2.json", $sprite_name);
|
||||||
$anim.play();
|
$anim.play();
|
||||||
$last_mod_time = std::filesystem::last_write_time("assets/animate2.json");
|
$last_mod_time = std::filesystem::last_write_time("assets/animate2.json");
|
||||||
}
|
}
|
||||||
|
|
@ -164,16 +153,10 @@ namespace animator {
|
||||||
return !in_state(State::END);
|
return !in_state(State::END);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::init(const std::string& sprite_name, const std::string& background, int width, int height) {
|
void UI::init(const std::string& sprite_name, int width, int height) {
|
||||||
$ui.position(0,0, width, height);
|
$ui.position(0,0, width, height);
|
||||||
$ui.layout("[=viewer]");
|
$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");
|
auto viewer = $ui.entity("viewer");
|
||||||
$ui.set<guecs::Sprite>(viewer, { sprite_name, 0, false});
|
$ui.set<guecs::Sprite>(viewer, { sprite_name, 0, false});
|
||||||
|
|
||||||
|
|
@ -198,11 +181,6 @@ namespace animator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int error() {
|
|
||||||
fmt::println("USAGE: animator -h -b <background> -s <sprite> -a <animation>");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
shaders::init();
|
shaders::init();
|
||||||
components::init();
|
components::init();
|
||||||
|
|
@ -211,42 +189,14 @@ int main(int argc, char* argv[]) {
|
||||||
ai::init("ai");
|
ai::init("ai");
|
||||||
animation::init();
|
animation::init();
|
||||||
|
|
||||||
std::string sprite_name;
|
dbc::check(argc == 2, "USAGE: animator <sprite>");
|
||||||
std::string background;
|
std::string sprite_name{argv[1]};
|
||||||
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::mute(true);
|
||||||
sound::play("ambient_1", true);
|
sound::play("ambient_1", true);
|
||||||
|
|
||||||
animator::FSM main;
|
animator::FSM main;
|
||||||
main.init(sprite_name, anim_name, background);
|
main.init(sprite_name);
|
||||||
|
|
||||||
while(main.active()) {
|
while(main.active()) {
|
||||||
main.tick();
|
main.tick();
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace animator {
|
||||||
guecs::UI $ui;
|
guecs::UI $ui;
|
||||||
|
|
||||||
void button(const std::string& name, std::function<void(guecs::Modifiers mods)> cb);
|
void button(const std::string& name, std::function<void(guecs::Modifiers mods)> cb);
|
||||||
void init(const std::string& sprite_name, const std::string& background, int width, int height);
|
void init(const std::string& sprite_name, int width, int height);
|
||||||
void render(sf::RenderWindow& window, bool debug=false);
|
void render(sf::RenderWindow& window, bool debug=false);
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||||
std::shared_ptr<sf::Sprite> get_sprite();
|
std::shared_ptr<sf::Sprite> get_sprite();
|
||||||
|
|
@ -40,12 +40,10 @@ namespace animator {
|
||||||
std::shared_ptr<sf::Sprite> $sprite = nullptr;
|
std::shared_ptr<sf::Sprite> $sprite = nullptr;
|
||||||
animate2::Animate2 $anim;
|
animate2::Animate2 $anim;
|
||||||
std::string $sprite_name="";
|
std::string $sprite_name="";
|
||||||
std::string $anim_name="";
|
|
||||||
std::string $background="";
|
|
||||||
std::filesystem::file_time_type $last_mod_time;
|
std::filesystem::file_time_type $last_mod_time;
|
||||||
sf::Clock $timer;
|
sf::Clock $timer;
|
||||||
|
|
||||||
void init(const std::string &sprite_name, const std::string& background, const std::string &anim_name);
|
void init(const std::string &sprite_name);
|
||||||
void event(Event ev, std::any data={});
|
void event(Event ev, std::any data={});
|
||||||
void START(Event ev);
|
void START(Event ev);
|
||||||
void ANIMATE(Event ev);
|
void ANIMATE(Event ev);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue