Last active
July 16, 2016 08:51
-
-
Save musou1500/0d613792c6d472e3d6d812068a06ba3f to your computer and use it in GitHub Desktop.
spritesheet packer( https://spritesheetpacker.codeplex.com ) が吐き出すテキストの処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 = 0 0 160 160 | |
1 = 163 0 160 160 | |
10 = 326 0 160 160 | |
11 = 0 163 160 160 | |
12 = 163 163 160 160 | |
13 = 0 326 160 160 | |
14 = 163 326 160 160 | |
15 = 326 163 160 160 | |
16 = 326 326 160 160 | |
17 = 489 0 160 160 | |
18 = 489 163 160 160 | |
19 = 652 0 160 160 | |
2 = 489 326 160 160 | |
20 = 652 163 160 160 | |
21 = 652 326 160 160 | |
22 = 0 489 160 160 | |
23 = 0 652 160 160 | |
24 = 163 489 160 160 | |
3 = 163 652 160 160 | |
4 = 326 489 160 160 | |
5 = 326 652 160 160 | |
6 = 489 489 160 160 | |
7 = 652 489 160 160 | |
8 = 489 652 160 160 | |
9 = 652 652 160 160 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <vector> | |
#include <array> | |
#include <sstream> | |
#include <algorithm> | |
using namespace std; | |
typedef struct { | |
string name; | |
int x, y, width, height; | |
} Frame; | |
int main(int argc, char* argv[]) { | |
if (argc != 2) { | |
cout << "Usage: " << string(argv[0]) << " ./filename" << endl; | |
} | |
vector<Frame> frames; | |
string line; | |
ifstream ifs(argv[1]); | |
while(ifs && getline(ifs, line)) { | |
stringstream lineStream(line); | |
string left, right; | |
getline(lineStream, left, '='); | |
getline(lineStream, right, '='); | |
Frame frame; | |
frame.name = left; | |
string param; | |
array<int, 4> params; | |
stringstream rightstream(right); | |
int i = 0; | |
while(i < 4 && getline(rightstream, param, ' ')) { | |
bool isnum = all_of(param.begin(), param.end(), isdigit); | |
if (isnum && param.size() > 0) { | |
params[i] = stoi(param); | |
i++; | |
} | |
} | |
frame.x = params[0]; | |
frame.y = params[1]; | |
frame.width = params[2]; | |
frame.height = params[3]; | |
frames.push_back(frame); | |
} | |
for(auto frame : frames) { | |
cout << frame.name << endl; | |
cout << frame.x << endl; | |
cout << frame.y << endl; | |
cout << frame.width << endl; | |
cout << frame.height << endl; | |
cout << "---" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment