diff options
Diffstat (limited to 'src/sprite.cpp')
-rw-r--r-- | src/sprite.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/sprite.cpp b/src/sprite.cpp index c52807a..b84f4ce 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp | |||
@@ -12,14 +12,53 @@ Sprite::Sprite(std::string_view filename, Renderer& renderer) { | |||
12 | } | 12 | } |
13 | 13 | ||
14 | char ch; | 14 | char ch; |
15 | std::string line; | ||
15 | 16 | ||
16 | std::string imagename; | 17 | std::string imagename; |
17 | datafile >> imagename; | 18 | datafile >> imagename; |
18 | textureId_ = renderer.loadImageFromFile(imagename); | 19 | textureId_ = renderer.loadImageFromFile(imagename); |
19 | 20 | ||
20 | datafile >> size_.w(); | 21 | std::string framefilename; |
21 | datafile >> ch; //, | 22 | datafile >> framefilename; |
22 | datafile >> size_.h(); | 23 | |
24 | std::ifstream framefile(framefilename); | ||
25 | if (!framefile.is_open()) { | ||
26 | throw std::invalid_argument("Could not find frame datafile: " + framefilename); | ||
27 | } | ||
28 | |||
29 | vec2i cellSize; | ||
30 | framefile >> cellSize.w(); | ||
31 | framefile >> ch; //, | ||
32 | framefile >> cellSize.h(); | ||
33 | std::getline(framefile, line); // cell size | ||
34 | |||
35 | int framesPerRow; | ||
36 | framefile >> framesPerRow; | ||
37 | std::getline(framefile, line); // frames per row | ||
38 | |||
39 | int numFrames; | ||
40 | framefile >> numFrames; | ||
41 | std::getline(framefile, line); // frames | ||
42 | std::getline(framefile, line); // blank | ||
43 | |||
44 | for (int i=0; i<numFrames; i++) { | ||
45 | SpriteFrame f; | ||
46 | framefile >> f.size.w(); | ||
47 | framefile >> ch; //, | ||
48 | framefile >> f.size.h(); | ||
49 | framefile >> ch; //, | ||
50 | framefile >> f.center.x(); | ||
51 | framefile >> ch; //, | ||
52 | framefile >> f.center.y(); | ||
53 | std::getline(framefile, line); // blank | ||
54 | |||
55 | f.srcRect.x = (i % framesPerRow) * cellSize.w(); | ||
56 | f.srcRect.y = (i / framesPerRow) * cellSize.h(); | ||
57 | f.srcRect.w = f.size.w(); | ||
58 | f.srcRect.h = f.size.h(); | ||
59 | |||
60 | frames_.push_back(std::move(f)); | ||
61 | } | ||
23 | 62 | ||
24 | std::string animLine; | 63 | std::string animLine; |
25 | std::getline(datafile, animLine); // blank | 64 | std::getline(datafile, animLine); // blank |