Skip to content

Commit

Permalink
- Added tests for lack of grid colliders on GridSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoDeAndrade committed Jan 2, 2025
1 parent 985f7cb commit 4482d1b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
52 changes: 33 additions & 19 deletions Assets/OkapiKit/Scripts/Systems/GridSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ protected override void CheckErrors()
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "No grid in object", "Grid system need to be on an object with a Grid component!"));
}

if ((gridcolliders != null) && (gridcolliders.Length > 0))
{
for (int i = 0; i < gridcolliders.Length; i++)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, $"Invalid grid collider at index {i}", "There's a collider entry, but the object is invalid!"));
}
}
}

protected void Start()
Expand All @@ -126,13 +134,14 @@ void UpdateColliders()

if ((gridcolliders != null) && (gridcolliders.Length > 0))
{
bounds = gridcolliders[0].bounds;
bool init = false;

for (int i = 1; i < gridcolliders.Length; i++)
for (int i = 0; i < gridcolliders.Length; i++)
{
if (gridcolliders[i] == null) continue;

bounds.Encapsulate(gridcolliders[i].bounds);

if (!init) { bounds = gridcolliders[i].bounds; init = true; }
else bounds.Encapsulate(gridcolliders[i].bounds);
}
}

Expand All @@ -144,28 +153,33 @@ void UpdateColliders()
mapsByLayer.Clear();

// Compute collision masks
foreach (var collider in gridcolliders)
if ((gridcolliders != null) && (gridcolliders.Length > 0))
{
var map = GetMapByLayer(collider.gameObject.layer);
int idx;
foreach (var collider in gridcolliders)
{
if (collider == null) continue;

Vector2 worldPos = new Vector2(bounds.min.x + grid.cellSize.x * 0.5f, bounds.min.y + grid.cellSize.y * 0.5f);
var map = GetMapByLayer(collider.gameObject.layer);
int idx;

for (int y = 0; y < mapSizeY; y++)
{
for (int x = 0; x < mapSizeX; x++)
Vector2 worldPos = new Vector2(bounds.min.x + grid.cellSize.x * 0.5f, bounds.min.y + grid.cellSize.y * 0.5f);

for (int y = 0; y < mapSizeY; y++)
{
if (collider.OverlapPoint(worldPos))
for (int x = 0; x < mapSizeX; x++)
{
idx = y * stride + x / 8;
map[idx] |= (byte)(1 << (x % 8));

Debug.DrawLine(worldPos, worldPos + new Vector2(5.0f, 5.0f), Color.red, 5.0f);
if (collider.OverlapPoint(worldPos))
{
idx = y * stride + x / 8;
map[idx] |= (byte)(1 << (x % 8));

Debug.DrawLine(worldPos, worldPos + new Vector2(5.0f, 5.0f), Color.red, 5.0f);
}
worldPos.x += grid.cellSize.x;
}
worldPos.x += grid.cellSize.x;
worldPos.x = bounds.min.x + grid.cellSize.x * 0.5f;
worldPos.y += grid.cellSize.y;
}
worldPos.x = bounds.min.x + grid.cellSize.x * 0.5f;
worldPos.y += grid.cellSize.y;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/OkapiKit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.videojogoslusofona.okapikit",
"displayName": "OkapiKit",
"version": "1.17.1",
"version": "1.17.2",
"unity": "6000.0",
"description": "OkapiKit is a toolkit for creation of simple games without code.",
"keywords": [ "kit" ],
Expand Down
4 changes: 2 additions & 2 deletions Assets/OkapiKitSamples/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "com.videojogoslusofona.okapikit.samples",
"displayName": "OkapiKit Samples",
"version": "1.17.1",
"version": "1.17.2",
"unity": "6000.0",
"description": "OkapiKit is a toolkit for creation of simple games without code. This package is just the samples for OkapiKit, they are not required to use Okapi Kit, and requires the Okapi Kit package.",
"keywords": [ "okapi", "samples" ],
"category": "samples",
"dependencies": {},
"relatedPackages": {
"com.videojogoslusofona.okapikit": "1.17.1"
"com.videojogoslusofona.okapikit": "1.17.2"
},
"author": {
"name": "Videojogos ULHT",
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## V1.17.2

- Added tests for lack of grid colliders on GridSystem

## V1.17.1

- Fixed issues with builds (auto-added using clauses that stopped compilation in release mode)
Expand Down

0 comments on commit 4482d1b

Please sign in to comment.