diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-24 10:22:41 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-02-24 16:00:53 -0500 |
commit | bf39e32f2ec9008e48b0dd3ad53d640434e0738a (patch) | |
tree | 721afb1c5c442075fa698657cdad6082e302dda1 /src | |
parent | 135e71d650e5a414219729cd84a2c917a3e8f1fb (diff) | |
download | tanetane-bf39e32f2ec9008e48b0dd3ad53d640434e0738a.tar.gz tanetane-bf39e32f2ec9008e48b0dd3ad53d640434e0738a.tar.bz2 tanetane-bf39e32f2ec9008e48b0dd3ad53d640434e0738a.zip |
Added shorthand for repeated frames in animations
Diffstat (limited to 'src')
-rw-r--r-- | src/animation_system.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/animation_system.cpp b/src/animation_system.cpp index 2c2c6a5..b57816b 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp | |||
@@ -65,7 +65,7 @@ void AnimationSystem::initSprite(int spriteId, std::string_view filename) { | |||
65 | std::string animLine; | 65 | std::string animLine; |
66 | std::getline(datafile, animLine); // blank | 66 | std::getline(datafile, animLine); // blank |
67 | while (std::getline(datafile, animLine)) { | 67 | while (std::getline(datafile, animLine)) { |
68 | std::regex re(R"(([a-z!._]+)\[([a-z_]+)\]: ([0-9,]+))"); | 68 | std::regex re(R"(([a-z!._]+)\[([a-z_]+)\]: ([0-9,#]+))"); |
69 | std::smatch m; | 69 | std::smatch m; |
70 | std::regex_match(animLine, m, re); | 70 | std::regex_match(animLine, m, re); |
71 | 71 | ||
@@ -73,7 +73,15 @@ void AnimationSystem::initSprite(int spriteId, std::string_view filename) { | |||
73 | Animation anim; | 73 | Animation anim; |
74 | auto framestrs = splitStr<std::list<std::string>>(m[3], ","); | 74 | auto framestrs = splitStr<std::list<std::string>>(m[3], ","); |
75 | for (const std::string& f : framestrs) { | 75 | for (const std::string& f : framestrs) { |
76 | anim.frameIndices.push_back(std::stoi(f)); | 76 | int times = 1; |
77 | size_t repeat_it = f.find("#"); | ||
78 | if (repeat_it != std::string::npos) { | ||
79 | times = std::stoi(f.substr(repeat_it + 1)); | ||
80 | } | ||
81 | |||
82 | for (int i=0; i<times; i++) { | ||
83 | anim.frameIndices.push_back(std::stoi(f)); | ||
84 | } | ||
77 | } | 85 | } |
78 | 86 | ||
79 | if (animName.back() == '!') { | 87 | if (animName.back() == '!') { |