Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
LevelParser.h
Go to the documentation of this file.
1/*
2 * LevelParser.h - Phase 1: Parsing & Visual Analysis for Level Loading
3 *
4 * Responsible for parsing .tmj files and extracting:
5 * - Visual resource manifests (tilesets, image layers, sprites)
6 * - Object census (object types, counts, templates)
7 * - Object references (patrol paths, trigger zones, etc.)
8 *
9 * Part of the 3-Phase Level Loading System:
10 * Phase 1: Parsing & Visual Analysis (this file)
11 * Phase 2: Prefab Discovery & Preloading
12 * Phase 3: Instantiation Pipeline
13 */
14
15#pragma once
16
17#include <string>
18#include <vector>
19#include <map>
20#include <set>
21
22namespace Olympe {
23namespace Tiled {
24
25 // Forward declarations
26 struct TiledMap;
27
28 // Visual resource manifest extracted from level
30 {
32 {
33 std::string sourceFile; // .tsj file path
34 std::string imageFile; // Main tileset image
35 std::vector<std::string> individualImages; // For collection tilesets
38
40 };
41
42 std::vector<TilesetRef> tilesets;
43 std::vector<std::string> parallaxLayers; // Image layer paths
44 std::set<std::string> allImagePaths; // Deduplicated set of all images
45
46 int GetTotalImageCount() const { return static_cast<int>(allImagePaths.size()); }
47 int GetTilesetCount() const { return static_cast<int>(tilesets.size()); }
48 int GetParallaxLayerCount() const { return static_cast<int>(parallaxLayers.size()); }
49 };
50
51 // Census of objects in the level (for prefab discovery)
53 {
54 std::map<std::string, int> typeCounts; // type -> count
55 std::set<std::string> uniqueTypes; // All unique types
56 std::map<std::string, std::string> templates; // template name -> template path
57
59 {
60 int total = 0;
61 for (const auto& kv : typeCounts) total += kv.second;
62 return total;
63 }
64
65 int GetUniqueTypeCount() const { return static_cast<int>(uniqueTypes.size()); }
66
67 bool HasType(const std::string& type) const
68 {
69 return uniqueTypes.find(type) != uniqueTypes.end();
70 }
71 };
72
73 // Object reference (for patrol paths, triggers, etc.)
75 {
76 int sourceObjectId; // ID of object referencing another
77 std::string sourceObjectName;
78 int targetObjectId; // ID of referenced object
79 std::string targetObjectName;
80 std::string referenceType; // "patrol", "trigger", "target", etc.
81
84 };
85
86 // Result of parsing and analysis
88 {
89 bool success;
90 std::vector<std::string> errors;
91 std::vector<std::string> warnings;
92
93 // Map metadata
94 std::string orientation; // "orthogonal", "isometric", etc.
95 int width;
96 int height;
99
100 // Extracted manifests
103 std::vector<ObjectReference> objectReferences;
104
107
108 bool IsSuccess() const { return success && errors.empty(); }
109 bool HasWarnings() const { return !warnings.empty(); }
110 int GetErrorCount() const { return static_cast<int>(errors.size()); }
111 int GetWarningCount() const { return static_cast<int>(warnings.size()); }
112 };
113
114 // LevelParser: Phase 1 of level loading
116 {
117 public:
118 LevelParser();
119 ~LevelParser();
120
121 // Main entry point: Parse and analyze a Tiled map file
122 LevelParseResult ParseAndAnalyze(const std::string& levelPath);
123
124 private:
125 // Extract visual resources from map
127
128 // Build object census from all object layers
130
131 // Extract object references (patrol paths, etc.)
132 void ExtractObjectReferences(const TiledMap& map, std::vector<ObjectReference>& references);
133
134 // Helper: Get directory from file path
135 std::string GetDirectory(const std::string& filepath);
136
137 // Helper: Resolve relative path
138 std::string ResolvePath(const std::string& baseDir, const std::string& relativePath);
139 };
140
141} // namespace Tiled
142} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
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)
std::vector< ObjectReference > objectReferences
VisualResourceManifest visualManifest
std::vector< std::string > warnings
Definition LevelParser.h:91
std::vector< std::string > errors
Definition LevelParser.h:90
std::map< std::string, int > typeCounts
Definition LevelParser.h:54
std::map< std::string, std::string > templates
Definition LevelParser.h:56
std::set< std::string > uniqueTypes
Definition LevelParser.h:55
bool HasType(const std::string &type) const
Definition LevelParser.h:67
std::vector< std::string > parallaxLayers
Definition LevelParser.h:43
std::vector< TilesetRef > tilesets
Definition LevelParser.h:42
std::set< std::string > allImagePaths
Definition LevelParser.h:44