8#include "../include/LevelParser.h"
9#include "../include/TiledLevelLoader.h"
10#include "../include/TiledStructures.h"
11#include "../../PrefabScanner.h"
12#include "../../PrefabFactory.h"
43 std::cout <<
"+======================================================================+ \n";
44 std::cout <<
"| PHASE 1: PARSING & VISUAL ANALYSIS | \n";
45 std::cout <<
"|======================================================================| \n";
46 std::cout <<
"| File: " <<
levelPath << std::string(std::max(0, 65 -
static_cast<int>(
levelPath.length())),
' ') <<
"| \n";
47 std::cout <<
"+======================================================================+ \n\n";
53 std::cout <<
"-> Loading Tiled map file...\n";
57 result.
errors.push_back(
"Failed to load Tiled map: " +
loader.GetLastError());
58 std::cout <<
"x Failed to load map: " <<
loader.GetLastError() <<
"\n";
61 std::cout <<
"-> Map loaded successfully\n\n";
62 std::cout <<
"Extracting metadata and analyzing contents...\n\n";
79 std::cout <<
"+======================================================================+ \n";
80 std::cout <<
"| MAP METADATA | \n";
81 std::cout <<
"|======================================================================| \n";
82 std::cout <<
"| Dimensions: " << result.
width <<
" x " << result.
height
85 << std::string(std::max(0, 19 -
static_cast<int>(std::to_string(result.
width).length() + std::to_string(result.
height).length())),
' ') <<
"| \n";
87 << std::string(std::max(0, 44 -
static_cast<int>(std::to_string(result.
tileWidth).length() + std::to_string(result.
tileHeight).length())),
' ') <<
"| \n";
88 std::cout <<
"| Orientation: " << result.
orientation
89 << std::string(54 - result.
orientation.length(),
' ') <<
"|\n";
90 std::cout <<
"| Infinite: " << (
tiledMap.infinite ?
"Yes" :
"No ")
91 << std::string(53,
' ') <<
"| \n";
92 std::cout <<
"+======================================================================+ \n\n";
95 std::cout <<
"-> Extracting visual resource manifest...\n";
98 std::cout <<
"+======================================================================+ \n";
99 std::cout <<
"| VISUAL RESOURCES | \n";
100 std::cout <<
"|======================================================================| \n";
107 std::cout <<
"+======================================================================+ \n\n";
110 std::cout <<
"-> Building object census...\n";
113 std::cout <<
"+======================================================================+ \n";
114 std::cout <<
"| OBJECT CENSUS | \n";
115 std::cout <<
"|======================================================================| \n";
123 std::cout <<
"| | \n";
124 std::cout <<
"| Type Breakdown: | \n";
127 std::string
line =
"| " +
kv.first +
": " + std::to_string(
kv.second);
128 std::cout <<
line << std::string(70 -
line.length(),
' ') <<
"| \n";
131 std::cout <<
"+======================================================================+ \n\n";
134 std::cout <<
"-> Extracting object references...\n";
139 std::cout <<
"-> Found " << result.
objectReferences.size() <<
" object reference(s)\n\n";
144 std::cout <<
"+======================================================================+ \n";
145 std::cout <<
"| PHASE 1 COMPLETE | \n";
146 std::cout <<
"|======================================================================| \n";
147 std::cout <<
"| Status: -> SUCCESS | \n";
149 << std::string(59 - std::to_string(result.
GetErrorCount()).length(),
' ') <<
"| \n";
151 << std::string(59 - std::to_string(result.
GetWarningCount()).length(),
' ') <<
"| \n";
152 std::cout <<
"+======================================================================+ \n\n";
160 for (
const auto& tileset :
map.tilesets)
164 ref.imageFile = tileset.image;
165 ref.firstGid = tileset.firstgid;
168 if (!tileset.tiles.empty() && tileset.image.empty())
170 ref.isCollection =
true;
171 for (
const auto&
tile : tileset.tiles)
173 if (!
tile.image.empty())
175 ref.individualImages.push_back(
tile.image);
180 else if (!tileset.image.empty())
182 ref.isCollection =
false;
183 manifest.allImagePaths.insert(tileset.image);
191 processLayer = [&](
const std::shared_ptr<TiledLayer>& layer)
197 manifest.parallaxLayers.push_back(layer->image);
198 manifest.allImagePaths.insert(layer->image);
211 for (
const auto& layer :
map.layers)
220 processLayer = [&](
const std::shared_ptr<TiledLayer>& layer)
226 for (
const auto&
obj : layer->objects)
228 std::string type =
obj.type;
229 if (type.empty()) type =
"undefined";
233 census.uniqueTypes.insert(type);
234 census.typeCounts[type]++;
237 auto it =
obj.properties.find(
"template");
240 census.templates[
obj.name] =
it->second.stringValue;
255 for (
const auto& layer :
map.layers)
264 processLayer = [&](
const std::shared_ptr<TiledLayer>& layer)
270 for (
const auto&
obj : layer->objects)
273 for (
const auto&
prop :
obj.properties)
275 if (
prop.first ==
"targetObject" ||
276 prop.first ==
"patrolPath" ||
277 prop.first ==
"linkedObject")
281 ref.sourceObjectName =
obj.name;
282 ref.referenceType =
prop.first;
286 ref.targetObjectId =
prop.second.intValue;
290 ref.targetObjectName =
prop.second.stringValue;
309 for (
const auto& layer :
map.layers)
317 size_t pos = filepath.find_last_of(
"/\\");
318 if (
pos != std::string::npos)
320 return filepath.substr(0,
pos);
ComponentTypeID GetComponentTypeID_Static()
void ExtractVisualResources(const TiledMap &map, VisualResourceManifest &manifest)
void BuildObjectCensus(const TiledMap &map, ObjectTypeCensus &census)
std::string ResolvePath(const std::string &baseDir, const std::string &relativePath)
std::string GetDirectory(const std::string &filepath)
LevelParseResult ParseAndAnalyze(const std::string &levelPath)
void ExtractObjectReferences(const TiledMap &map, std::vector< ObjectReference > &references)
static std::string GetPadding(int totalWidth, const std::string &content)
< Provides AssetID and INVALID_ASSET_ID
int GetWarningCount() const
std::vector< ObjectReference > objectReferences
VisualResourceManifest visualManifest
std::vector< std::string > errors
ObjectTypeCensus objectCensus
int GetErrorCount() const
int GetTotalObjectCount() const
std::map< std::string, int > typeCounts
int GetUniqueTypeCount() const
int GetParallaxLayerCount() const
int GetTilesetCount() const
int GetTotalImageCount() const