Skip to content

Commit f83ecc9

Browse files
authored
Merge pull request #93 from G-Epitech/rtp-90-document-existing-zygarde-components-and-systems
RTP-90 - Document existing zygarde components and systems
2 parents 9bf8eff + fe7544d commit f83ecc9

30 files changed

+980
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Core",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Archetypes",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
# Manager
5+
6+
7+
The `ArchetypeManager` in the `zygarde::core::archetypes` namespace manages the loading, invocation, and scheduling of archetypes in the game engine. Archetypes are JSON-based configurations that define sets of components for game entities, including properties, behavior scripts, and metadata.
8+
9+
```cpp
10+
namespace zygarde::core::archetypes {
11+
class ArchetypeManager final {
12+
// Member functions and members described below
13+
};
14+
} // namespace zygarde::core::archetypes
15+
```
16+
17+
### Overview
18+
The ArchetypeManager class is responsible for:
19+
20+
- Loading archetypes from specified directories.
21+
- Invoking archetypes to spawn entities based on archetype configurations.
22+
- Scheduling invocations to defer the spawning of entities to a later time.
23+
24+
Archetypes define the initial properties and behaviors of entities. Here is an example of an archetype configuration in JSON:
25+
26+
```json
27+
{
28+
"archetype_name": "enemy_pata_normal",
29+
"components": [
30+
{
31+
"name": "rigidbody2d",
32+
"data": {
33+
"isKinematic": false,
34+
"drag": 0
35+
}
36+
},
37+
{
38+
"name": "position"
39+
},
40+
{
41+
"name": "box_collider2d",
42+
"data": {
43+
"size": {
44+
"x": 52.5,
45+
"y": 60
46+
},
47+
"collisionLayers": [2],
48+
"includeLayers": [1, 8]
49+
}
50+
},
51+
{
52+
"name": "tags",
53+
"data": {
54+
"tags": ["enemy", "pata"]
55+
}
56+
},
57+
{
58+
"name": "script_pool",
59+
"data": [
60+
{
61+
"scriptName": "pataScript",
62+
"customValues": {
63+
"health": 30.0,
64+
"verticalSpeed": 20.0,
65+
"horizontalSpeed": 80.0,
66+
"upperLimitOffset": 30.0,
67+
"lowerLimitOffset": 30.0,
68+
"fireRate": 0.8,
69+
"bulletsType": 0,
70+
"scoreIncrease": 100
71+
}
72+
}
73+
]
74+
}
75+
]
76+
}
77+
```
78+
79+
### Usage
80+
81+
Here is a usage example for the archetype manager
82+
```cpp
83+
#include "archetype_manager.hpp"
84+
#include "registry.hpp"
85+
86+
int main() {
87+
using namespace zygarde::core::archetypes;
88+
89+
// Initialize ArchetypeManager and Registry
90+
ArchetypeManager archetypeManager;
91+
auto registry = std::make_shared<zygarde::Registry>();
92+
93+
// Load archetypes from a directory
94+
archetypeManager.LoadArchetypes("path/to/archetypes", scriptsRegistry);
95+
96+
// Directly invoke an archetype to create an entity
97+
zygarde::Entity enemy = archetypeManager.InvokeArchetype(registry, "enemy_pata_normal");
98+
99+
// Schedule an invocation
100+
ArchetypeManager::ScheduleInvocationParams params {
101+
.archetypeName = "enemy_pata_normal",
102+
.registryAttachCallback = [](const std::shared_ptr<zygarde::Registry>& reg, zygarde::Entity entity) {
103+
// Custom behavior after attaching entity to registry
104+
std::cout << "Entity created and attached to registry\n";
105+
}
106+
};
107+
archetypeManager.ScheduleInvocation(params);
108+
109+
// Execute scheduled invocations
110+
archetypeManager.ExecuteScheduledInvocations(registry);
111+
112+
return 0;
113+
}
114+
```
115+
116+
Generally prefer using the later invocation when inside the scripting loop and immediate invocation outside of it.
117+
118+
### See Also
119+
120+
- Registry
121+
- Entity
122+
- ArchetypeLoader
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Components",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Position
6+
7+
The `Position` component is part of the `zygarde::core::components` namespace and represents the spatial location and alignment of a 3D object within the system. It consists of a 3D point vector and an `Alignment` struct to handle horizontal and vertical alignment.
8+
9+
## Overview
10+
11+
The `Position` component allows for the specification of both a 3D position and customizable alignment options (horizontal and vertical), useful for positioning objects within a scene or UI.
12+
13+
```cpp
14+
namespace zygarde::core::components {
15+
16+
struct Position {
17+
core::types::Vector3f point; ///< Position point
18+
Alignment aligns; ///< Aligns
19+
};
20+
21+
} // namespace zygarde::core::components
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
# Tags
5+
6+
7+
The `Tags` component in the `zygarde::core::components` namespace is a utility for managing sets of tags, implemented as a wrapper around a `std::set` of strings. This class provides methods for adding, removing, and querying tags, making it ideal for tagging systems within the `zygarde` library.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
# Transform
5+
6+
The `Transform` component in the `zygarde::core::components` namespace represents the scale and rotation properties of a 3D object. This component uses two 3D vectors (`scale` and `rotation`) for defining an object's transformation attributes within the `zygarde` framework.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Physics",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Components",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
# BoxCollider2D
5+
6+
The `BoxCollider2D` class is part of the `zygarde::physics::components` namespace and is designed to represent a 2D box-shaped collider within the physics engine. It provides methods to manage collision detection and response for rectangular objects.
7+
8+
## Overview
9+
10+
`BoxCollider2D` is a final class that allows the definition and manipulation of a 2D box collider. It holds data about the size of the collider and supports specifying collision and inclusion layers to manage how collisions are detected with other objects.
11+
12+
## Properties
13+
- ``size``: A ``Vector2f`` representing the width and height of the box collider.
14+
- ``collision_layers``: A vector of integers specifying the collision layers the box collider is considered part of.
15+
- ``include_layers``: A vector of integers specifying the inclusion layers for the collider, these are the layers the collider will check against.
16+
17+
## Example Usage
18+
```cpp
19+
#include "box_collider_2_d.hpp"
20+
21+
using namespace zygarde::physics::components;
22+
23+
core::types::Vector2f boxSize(50.0f, 100.0f);
24+
std::vector<int> collisionLayers = {1, 2};
25+
std::vector<int> includeLayers = {1};
26+
27+
// Creating a BoxCollider2D with size and collision layers
28+
BoxCollider2D collider(boxSize, collisionLayers, includeLayers);
29+
30+
// Set a new size
31+
collider.SetSize(core::types::Vector2f(60.0f, 120.0f));
32+
33+
//> For the collider to be filled with collisions it needs to run through the collision system
34+
35+
// Check for collisions
36+
if (collider.HasCollision()) {
37+
auto collision = collider.GetNextCollision();
38+
// Process collision
39+
}
40+
```

0 commit comments

Comments
 (0)