|
14 | 14 | #include <iostream>
|
15 | 15 | #include <sstream>
|
16 | 16 | #include <zlib.h>
|
| 17 | +#include <boost/filesystem.hpp> |
17 | 18 | #include "TileGenerator.h"
|
18 | 19 |
|
19 | 20 | using namespace std;
|
@@ -241,6 +242,9 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
241 | 242 | if (m_drawOrigin) {
|
242 | 243 | renderOrigin();
|
243 | 244 | }
|
| 245 | + if (m_drawPlayers) { |
| 246 | + renderPlayers(input); |
| 247 | + } |
244 | 248 | writeImage(output);
|
245 | 249 | }
|
246 | 250 |
|
@@ -540,6 +544,48 @@ void TileGenerator::renderOrigin()
|
540 | 544 | gdImageArc(m_image, imageX, imageY, 12, 12, 0, 360, rgb2int(m_originColor.r, m_originColor.g, m_originColor.b));
|
541 | 545 | }
|
542 | 546 |
|
| 547 | +void TileGenerator::renderPlayers(const std::string &inputPath) |
| 548 | +{ |
| 549 | + int color = rgb2int(m_playerColor.r, m_playerColor.g, m_playerColor.b); |
| 550 | + |
| 551 | + string playersPath = inputPath + "players"; |
| 552 | + boost::filesystem::path path(playersPath.c_str()); |
| 553 | + boost::filesystem::directory_iterator end_iter; |
| 554 | + boost::filesystem::directory_iterator iter(path); |
| 555 | + for (; iter != end_iter; ++iter) { |
| 556 | + if (!boost::filesystem::is_directory(iter->status())) { |
| 557 | + string path = iter->path().string(); |
| 558 | + |
| 559 | + ifstream in; |
| 560 | + in.open(path.c_str(), ifstream::in); |
| 561 | + string buffer; |
| 562 | + string name; |
| 563 | + string position; |
| 564 | + while (getline(in, buffer)) { |
| 565 | + if (buffer.find("name = ") == 0) { |
| 566 | + name = buffer.substr(7); |
| 567 | + } |
| 568 | + else if (buffer.find("position = ") == 0) { |
| 569 | + position = buffer.substr(12, buffer.length() - 13); |
| 570 | + } |
| 571 | + } |
| 572 | + double x, y, z; |
| 573 | + char comma; |
| 574 | + istringstream positionStream(position, istringstream::in); |
| 575 | + positionStream >> x; |
| 576 | + positionStream >> comma; |
| 577 | + positionStream >> y; |
| 578 | + positionStream >> comma; |
| 579 | + positionStream >> z; |
| 580 | + int imageX = x / 10 - m_xMin * 16 + m_border; |
| 581 | + int imageY = m_mapHeight - (z / 10 - m_zMin * 16) + m_border; |
| 582 | + |
| 583 | + gdImageArc(m_image, imageX, imageY, 5, 5, 0, 360, color); |
| 584 | + gdImageString(m_image, gdFontGetMediumBold(), imageX + 2, imageY + 2, reinterpret_cast<unsigned char *>(const_cast<char *>(name.c_str())), color); |
| 585 | + } |
| 586 | + } |
| 587 | +} |
| 588 | + |
543 | 589 | inline std::list<int> TileGenerator::getZValueList() const
|
544 | 590 | {
|
545 | 591 | std::list<int> zlist;
|
|
0 commit comments