Skip to content

Commit 562c9e3

Browse files
committed
feat: Implementa escaneamento de mapa, adiciona gerenciador de camadas dos blocos e adiciona extensao para buscar recursivamente nos de um tipo
1 parent a8186d5 commit 562c9e3

File tree

11 files changed

+134
-23
lines changed

11 files changed

+134
-23
lines changed

GlobalUsings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
global using Godot;
2-
global using DungeonRoyale.Shared.Scripts;
2+
global using DungeonRoyale.Shared.Scripts.Extensions;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cslplb3s5se2m"]
22

3-
[ext_resource type="Script" path="res://Modules/Map/Scripts/MapSettingsResource.cs" id="1_bcgwb"]
3+
[ext_resource type="Script" uid="uid://c2q15i1u3gl3y" path="res://Modules/Map/Scripts/MapSettingsResource.cs" id="1_bcgwb"]
44

55
[resource]
66
script = ExtResource("1_bcgwb")
7-
Width = 100
8-
Height = 100
7+
Width = 500
8+
Height = 500

Modules/Game/Scenes/Game.tscn

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

Modules/Game/Scripts/Game.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ public partial class Game : Node2D
1414
public override void _Ready()
1515
{
1616
_tilesManager.SetUpTiles(MapSettings.Width, MapSettings.Height);
17+
18+
if (FindChild(nameof(MapScanner), true) is not MapScanner mapScanner)
19+
{
20+
GD.PrintErr("MapScanner node not found.");
21+
return;
22+
}
23+
24+
mapScanner.MapScanned += OnMapScanned;
25+
mapScanner.Scan(MapSettings.Width, MapSettings.Height);
1726
}
1827

1928
public void OnMapScanned()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace DungeonRoyale.Modules.GameManagers.Scripts;
2+
3+
public partial class TileMapManager : Node2D
4+
{
5+
public static TileMapManager? Instance { get; private set; }
6+
7+
public TileMapLayer GroundTileMap { get; private set; } = null!;
8+
public TileMapLayer SpawnTileMap { get; private set; } = null!;
9+
10+
public override void _Ready()
11+
{
12+
if (Instance is null)
13+
{
14+
Instance = this;
15+
}
16+
else
17+
{
18+
GD.PrintErr("There is already an instance of TileMapManager in the scene.");
19+
}
20+
21+
var tileMapLayers = this.GetRecursivelyNodesOfType<TileMapLayer>();
22+
23+
foreach (var tileMapLayer in tileMapLayers)
24+
{
25+
if (tileMapLayer.Name == nameof(GroundTileMap))
26+
{
27+
GroundTileMap = tileMapLayer;
28+
}
29+
else if (tileMapLayer.Name == nameof(SpawnTileMap))
30+
{
31+
SpawnTileMap = tileMapLayer;
32+
}
33+
}
34+
35+
if (GroundTileMap is null || SpawnTileMap is null)
36+
{
37+
GD.PrintErr("TileMapLayers not found.");
38+
}
39+
}
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bt46ejg3cyafl

Modules/GameManagers/Scripts/TilesManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public void SetUpTiles(int width, int height)
3838
_height = height;
3939

4040
Tiles = new DRTileData[_width, _height];
41+
42+
for (int x = 0; x < _width; x++)
43+
for (int y = 0; y < _height; y++)
44+
{
45+
Tiles[x, y] = new DRTileData(x, y);
46+
}
4147
}
4248

4349
[MethodImpl(MethodImplOptions.AggressiveInlining)]

Modules/Map/Scripts/MapScanner.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
using DungeonRoyale.Modules.GameManagers.Scripts;
2+
13
namespace DungeonRoyale.Modules.Map.Scripts;
24

35
public partial class MapScanner : Node2D
46
{
7+
private TileMapManager _tileMapManager => TileMapManager.Instance!;
8+
private TilesManager _tilesManager => TilesManager.Instance!;
9+
510
[Signal] public delegate void MapScannedEventHandler();
611

7-
public override void _Ready()
12+
public void Scan(int width, int height)
813
{
14+
GD.Print("Scanning map...");
15+
for (int x = 0; x < width; x++)
16+
for (int y = 0; y < height; y++)
17+
{
18+
var groundTile = _tileMapManager.GroundTileMap.GetCellTileData(new Vector2I(x, y));
19+
20+
if (groundTile is null)
21+
continue;
22+
23+
if (!_tilesManager.TryGetTileAt(x, y, out var tileData))
24+
continue;
25+
26+
tileData.IsWalkable = groundTile.GetCustomData("IsWalkable").AsBool();
27+
28+
var spawnTile = _tileMapManager.SpawnTileMap.GetCellTileData(new Vector2I(x, y));
29+
30+
if (spawnTile is null)
31+
continue;
32+
33+
tileData.IsSpawnPoint = true;
34+
}
35+
36+
GD.Print("Map scanned.");
937
EmitSignal(SignalName.MapScanned);
1038
}
1139
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://c2q15i1u3gl3y

Modules/Tiles/Scripts/DRTileData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ public partial class DRTileData
55
public int X { get; private set; }
66
public int Y { get; private set; }
77

8-
public bool IsWalkable { get; private set; }
8+
public bool IsWalkable { get; set; }
99

10-
public bool IsSpawnPoint { get; private set; }
10+
public bool IsSpawnPoint { get; set; }
1111

1212
public DRTileData()
1313
{

0 commit comments

Comments
 (0)