Skip to content

Commit b30aac2

Browse files
committed
move struct to utils
Signed-off-by: Wojciech Czerski <[email protected]>
1 parent 95b70d1 commit b30aac2

File tree

4 files changed

+89
-37
lines changed

4 files changed

+89
-37
lines changed

Gems/CsvSpawner/Code/Include/CsvSpawner/CsvSpawnerInterface.h

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,10 @@
1212
#pragma once
1313

1414
#include <CsvSpawner/CsvSpawnerUtils.h>
15-
1615
#include <AzCore/EBus/EBus.h>
17-
#include <AzCore/std/string/string.h>
1816

1917
namespace CsvSpawner
2018
{
21-
22-
/**
23-
* @brief Flags representing the status of an CsvSpawner::Spawn() operation.
24-
*
25-
* SpawnStatus provides various status indicators for entity spawning.
26-
* These flags help track whether spawning was successful, stopped, or failed.
27-
*/
28-
enum class SpawnStatus : uint8_t
29-
{
30-
Success = 0, ///< Operation succeeded.
31-
Fail = 1 << 0, ///< Generic failure.
32-
Stopped = 1 << 1, ///< Spawning was stopped prematurely but not necessarily a failure.
33-
Warning = 1 << 2, ///< An warning or error occurred during spawning (potentially recoverable).
34-
};
35-
36-
/// Enable bitwise operations for SpawnStatus.
37-
AZ_DEFINE_ENUM_BITWISE_OPERATORS(SpawnStatus);
38-
39-
/**
40-
* @brief Structure holding data related to CsvSpawner entity spawning.
41-
*
42-
* SpawnInfo contains information about the entities to be spawned, the physics scene
43-
* they belong to, and the parent entity responsible for the spawn operation.
44-
*/
45-
struct SpawnInfo
46-
{
47-
AZStd::vector<CsvSpawnerUtils::CsvSpawnableEntityInfo> m_entitiesToSpawn; ///< List of entities to spawn.
48-
AZStd::string m_physicsSceneName; ///< Name of the physics scene where entities will be spawned.
49-
AZ::EntityId m_spawnerParentEntityId; ///< Parent entity ID managing the spawn process.
50-
};
51-
5219
/**
5320
* @brief Interface for handling entity spawn events for Csv Spawner.
5421
*
@@ -58,13 +25,14 @@ namespace CsvSpawner
5825
class CsvSpawnerInterface : public AZ::EBusTraits
5926
{
6027
public:
28+
AZ_RTTI(CsvSpawnerInterface, CsvSpawnerInterfaceTypeId);
6129
virtual ~CsvSpawnerInterface() = default;
6230

6331
/**
6432
* @brief Called when entity spawning begins.
6533
* @param m_spawnInfo Struct holding information about entities to be spawned.
6634
*/
67-
virtual void OnEntitiesSpawnBegin(SpawnInfo& m_spawnInfo)
35+
virtual void OnEntitiesSpawnBegin(CsvSpawnerUtils::SpawnInfo& m_spawnInfo)
6836
{
6937
}
7038

@@ -73,7 +41,7 @@ namespace CsvSpawner
7341
* @param m_spawnInfo Struct holding information about entities to be spawned.
7442
* @param m_statusCode Status code indicating success, failure and warnings of the spawn.
7543
*/
76-
virtual void OnEntitiesSpawnFinished(SpawnInfo& m_spawnInfo, SpawnStatus& m_statusCode)
44+
virtual void OnEntitiesSpawnFinished(CsvSpawnerUtils::SpawnInfo& m_spawnInfo, CsvSpawnerUtils::SpawnStatus& m_statusCode)
7745
{
7846
}
7947

Gems/CsvSpawner/Code/Include/CsvSpawner/CsvSpawnerTypeIds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ namespace CsvSpawner
2121
inline constexpr const char* CsvSpawnerComponentTypeId = "{59b31372-1f3c-4733-b61b-0fe94b5a8f3e}";
2222

2323
// Interface TypeIds
24-
inline constexpr const char* CsvSpawnerRequestsTypeId = "{77ACBD4E-069E-4610-8154-E1AC28CEE05A}";
24+
inline constexpr const char* CsvSpawnerInterfaceTypeId = "{77ACBD4E-069E-4610-8154-E1AC28CEE05A}";
25+
inline constexpr const char* CsvSpawnerSpawnInfoTypeId = "{81E5A014-3232-4359-98F5-7F9D7152629E}";
2526
} // namespace CsvSpawner

Gems/CsvSpawner/Code/Source/CsvSpawner/CsvSpawnerUtils.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,54 @@ namespace CsvSpawner::CsvSpawnerUtils
317317
return tickets;
318318
}
319319

320+
void SpawnInfo::Reflect(AZ::ReflectContext* context)
321+
{
322+
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
323+
{
324+
// Reflect SpawnStatus enum
325+
serializeContext->Enum<SpawnStatus>()
326+
->Version(0)
327+
->Value("Success", SpawnStatus::Success)
328+
->Value("Fail", SpawnStatus::Fail)
329+
->Value("Stopped", SpawnStatus::Stopped)
330+
->Value("Warning", SpawnStatus::Warning);
331+
332+
// Reflect SpawnInfo struct
333+
serializeContext->Class<SpawnInfo>()
334+
->Version(0)
335+
->Field("EntitiesToSpawn", &SpawnInfo::m_entitiesToSpawn)
336+
->Field("PhysicsSceneName", &SpawnInfo::m_physicsSceneName)
337+
->Field("SpawnerParentEntityId", &SpawnInfo::m_spawnerParentEntityId);
338+
339+
if (auto* editContext = serializeContext->GetEditContext())
340+
{
341+
editContext->Class<SpawnInfo>("Spawn Info", "Information about entities being spawned")
342+
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
343+
->DataElement(
344+
AZ::Edit::UIHandlers::Default,
345+
&SpawnInfo::m_entitiesToSpawn,
346+
"Entities to Spawn",
347+
"List of entities to be spawned.")
348+
->DataElement(
349+
AZ::Edit::UIHandlers::Default,
350+
&SpawnInfo::m_physicsSceneName,
351+
"Physics Scene",
352+
"Name of the physics scene where entities will be spawned.")
353+
->DataElement(
354+
AZ::Edit::UIHandlers::Default,
355+
&SpawnInfo::m_spawnerParentEntityId,
356+
"Parent Entity",
357+
"Parent entity ID responsible for spawning.");
358+
}
359+
}
360+
361+
if (auto* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
362+
{
363+
behaviorContext->Class<SpawnInfo>("SpawnInfo")
364+
->Constructor()
365+
->Property("m_entitiesToSpawn", BehaviorValueProperty(&SpawnInfo::m_entitiesToSpawn))
366+
->Property("m_physicsSceneName", BehaviorValueProperty(&SpawnInfo::m_physicsSceneName))
367+
->Property("m_spawnerParentEntityId", BehaviorValueProperty(&SpawnInfo::m_spawnerParentEntityId));
368+
}
369+
}
320370
} // namespace CsvSpawner::CsvSpawnerUtils

Gems/CsvSpawner/Code/Source/CsvSpawner/CsvSpawnerUtils.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,37 @@ namespace CsvSpawner::CsvSpawnerUtils
9999
const AZStd::string& physicsSceneName = AZStd::string(),
100100
AZ::EntityId parentId = AZ::EntityId());
101101

102-
}; // namespace CsvSpawner::CsvSpawnerUtils
102+
/**
103+
* @brief Flags representing the status of an CsvSpawner::Spawn() operation.
104+
*
105+
* SpawnStatus provides various status indicators for entity spawning.
106+
* These flags help track whether spawning was successful, stopped, or failed.
107+
*/
108+
enum class SpawnStatus : uint8_t
109+
{
110+
Success = 0, ///< Operation succeeded.
111+
Fail = 1 << 0, ///< Generic failure.
112+
Stopped = 1 << 1, ///< Spawning was stopped prematurely but not necessarily a failure.
113+
Warning = 1 << 2, ///< An warning or error occurred during spawning (potentially recoverable).
114+
};
115+
116+
/// Enable bitwise operations for SpawnStatus.
117+
AZ_DEFINE_ENUM_BITWISE_OPERATORS(SpawnStatus);
118+
119+
/**
120+
* @brief Structure holding data related to CsvSpawner entity spawning.
121+
*
122+
* SpawnInfo contains information about the entities to be spawned, the physics scene
123+
* they belong to, and the parent entity responsible for the spawn operation.
124+
*/
125+
struct SpawnInfo
126+
{
127+
AZ_TYPE_INFO(SpawnInfo, CsvSpawnerSpawnInfoTypeId);
128+
static void Reflect(AZ::ReflectContext* context);
129+
130+
AZStd::vector<CsvSpawnableEntityInfo> m_entitiesToSpawn; ///< List of entities to spawn.
131+
AZStd::string m_physicsSceneName; ///< Name of the physics scene where entities will be spawned.
132+
AZ::EntityId m_spawnerParentEntityId; ///< Parent entity ID managing the spawn process.
133+
};
134+
135+
} // namespace CsvSpawner::CsvSpawnerUtils

0 commit comments

Comments
 (0)