| 726 | } |
| 727 | |
| 728 | void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os, Image* textureImage) |
| 729 | { |
| 730 | std::string frames_begin; |
| 731 | std::string frames_end; |
| 732 | bool filename_as_key = false; |
| 733 | bool filename_as_attr = false; |
| 734 | |
| 735 | // TODO we should use some string templates system here |
| 736 | switch (m_dataFormat) { |
| 737 | case JsonHashDataFormat: |
| 738 | frames_begin = "{"; |
| 739 | frames_end = "}"; |
| 740 | filename_as_key = true; |
| 741 | filename_as_attr = false; |
| 742 | break; |
| 743 | case JsonArrayDataFormat: |
| 744 | frames_begin = "["; |
| 745 | frames_end = "]"; |
| 746 | filename_as_key = false; |
| 747 | filename_as_attr = true; |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | os << "{ \"frames\": " << frames_begin << "\n"; |
| 752 | for (Samples::const_iterator |
| 753 | it = samples.begin(), |
| 754 | end = samples.end(); it != end; ) { |
| 755 | const Sample& sample = *it; |
| 756 | gfx::Size srcSize = sample.originalSize(); |
| 757 | gfx::Rect spriteSourceBounds = sample.trimmedBounds(); |
| 758 | gfx::Rect frameBounds = sample.inTextureBounds(); |
| 759 | |
| 760 | if (filename_as_key) |
| 761 | os << " \"" << escape_for_json(sample.filename()) << "\": {\n"; |
| 762 | else if (filename_as_attr) |
| 763 | os << " {\n" |
| 764 | << " \"filename\": \"" << escape_for_json(sample.filename()) << "\",\n"; |
| 765 | |
| 766 | os << " \"frame\": { " |
| 767 | << "\"x\": " << frameBounds.x << ", " |
| 768 | << "\"y\": " << frameBounds.y << ", " |
| 769 | << "\"w\": " << frameBounds.w << ", " |
| 770 | << "\"h\": " << frameBounds.h << " },\n" |
| 771 | << " \"rotated\": false,\n" |
| 772 | << " \"trimmed\": " << (sample.trimmed() ? "true": "false") << ",\n" |
| 773 | << " \"spriteSourceSize\": { " |
| 774 | << "\"x\": " << spriteSourceBounds.x << ", " |
| 775 | << "\"y\": " << spriteSourceBounds.y << ", " |
| 776 | << "\"w\": " << spriteSourceBounds.w << ", " |
| 777 | << "\"h\": " << spriteSourceBounds.h << " },\n" |
| 778 | << " \"sourceSize\": { " |
| 779 | << "\"w\": " << srcSize.w << ", " |
| 780 | << "\"h\": " << srcSize.h << " },\n" |
| 781 | << " \"duration\": " << sample.sprite()->frameDuration(sample.frame()) << "\n" |
| 782 | << " }"; |
| 783 | |
| 784 | if (++it != samples.end()) |
| 785 | os << ",\n"; |
nothing calls this directly
no test coverage detected