Skip to content

Commit

Permalink
Merge pull request #8 from Coding-in-community/feat/adicionar-escanea…
Browse files Browse the repository at this point in the history
…mento-de-mapa

feat: adicionado classes iniciais de jogo que utilizara a classe mapsc…
  • Loading branch information
LeonardoCruzx authored Jan 25, 2025
2 parents 1bd23f2 + 6176254 commit 9f3609e
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 18 deletions.
2 changes: 1 addition & 1 deletion GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
global using Godot;
global using DungeonRoyale.Shared.Scripts;
global using DungeonRoyale.Shared.Scripts.Extensions;
8 changes: 8 additions & 0 deletions Modules/Game/Resources/mapSettings.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cslplb3s5se2m"]

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

[resource]
script = ExtResource("1_bcgwb")
Width = 1500
Height = 1500
40 changes: 29 additions & 11 deletions Modules/Game/Scenes/Game.tscn

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Modules/Game/Scripts/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using DungeonRoyale.Modules.GameManagers.Scripts;
using DungeonRoyale.Modules.Map.Scripts;

namespace DungeonRoyale.Modules.Game.Scripts;

public partial class Game : Node2D
{
private static TilesManager _tilesManager => TilesManager.Instance!;

[Export] public MapSettingsResource MapSettings { get; private set; } = new MapSettingsResource();

private bool MapIsLoading { get; set; } = true;

public override void _Ready()
{
_tilesManager.SetUpTiles(MapSettings.Width, MapSettings.Height);

if (FindChild(nameof(MapScanner), true) is not MapScanner mapScanner)
{
GD.PrintErr("MapScanner node not found.");
return;
}

mapScanner.MapScanned += OnMapScanned;
mapScanner.Scan(MapSettings.Width, MapSettings.Height);
}

public void OnMapScanned()
{
MapIsLoading = false;

// Do something with the scanned map
}

public void OnMapGenerated()
{
MapIsLoading = false;

// Do something with the generated map
}
}
1 change: 1 addition & 0 deletions Modules/Game/Scripts/Game.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://doeo50prutum0
36 changes: 36 additions & 0 deletions Modules/GameManagers/Scripts/TileMapManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace DungeonRoyale.Modules.GameManagers.Scripts;

public partial class TileMapManager : Node2D
{
public static TileMapManager? Instance { get; private set; }

public TileMapLayer GroundTileMap { get; private set; } = null!;
public TileMapLayer SpawnTileMap { get; private set; } = null!;

public override void _Ready()
{
if (Instance is null)
{
Instance = this;
}
else
{
GD.PrintErr("There is already an instance of TileMapManager in the scene.");
}

if (GetTree().CurrentScene.FindChild(nameof(GroundTileMap), true) is not TileMapLayer groundTileMap)
{
GD.PrintErr("GroundTileMap node not found.");
return;
}

if (GetTree().CurrentScene.FindChild(nameof(SpawnTileMap), true) is not TileMapLayer spawnTileMap)
{
GD.PrintErr("SpawnTileMap node not found.");
return;
}

GroundTileMap = groundTileMap;
SpawnTileMap = spawnTileMap;
}
}
1 change: 1 addition & 0 deletions Modules/GameManagers/Scripts/TileMapManager.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bt46ejg3cyafl
6 changes: 6 additions & 0 deletions Modules/GameManagers/Scripts/TilesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void SetUpTiles(int width, int height)
_height = height;

Tiles = new DRTileData[_width, _height];

for (int x = 0; x < _width; x++)
for (int y = 0; y < _height; y++)
{
Tiles[x, y] = new DRTileData(x, y);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
39 changes: 39 additions & 0 deletions Modules/Map/Scripts/MapScanner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using DungeonRoyale.Modules.GameManagers.Scripts;

namespace DungeonRoyale.Modules.Map.Scripts;

public partial class MapScanner : Node2D
{
private TileMapManager _tileMapManager => TileMapManager.Instance!;
private TilesManager _tilesManager => TilesManager.Instance!;

[Signal] public delegate void MapScannedEventHandler();

public void Scan(int width, int height)
{
GD.Print("Scanning map...");
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
var groundTile = _tileMapManager.GroundTileMap.GetCellTileData(new Vector2I(x, y));

if (groundTile is null)
continue;

if (!_tilesManager.TryGetTileAt(x, y, out var tileData))
continue;

tileData.IsWalkable = groundTile.GetCustomData("IsWalkable").AsBool();

var spawnTile = _tileMapManager.SpawnTileMap.GetCellTileData(new Vector2I(x, y));

if (spawnTile is null)
continue;

tileData.IsSpawnPoint = true;
}

GD.Print("Map scanned.");
EmitSignal(SignalName.MapScanned);
}
}
1 change: 1 addition & 0 deletions Modules/Map/Scripts/MapScanner.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://di6j7dxqlb03e
7 changes: 7 additions & 0 deletions Modules/Map/Scripts/MapSettingsResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DungeonRoyale.Modules.Map.Scripts;

public partial class MapSettingsResource : Resource
{
[Export] public int Width { get; private set; } = 100;
[Export] public int Height { get; private set; } = 100;
}
1 change: 1 addition & 0 deletions Modules/Map/Scripts/MapSettingsResource.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c2q15i1u3gl3y
11 changes: 11 additions & 0 deletions Modules/TileMaps/Resources/groundTileSet.tres
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ texture = ExtResource("1_e6sjf")
2:2/0/terrains_peering_bit/top_side = 0
2:2/0/terrains_peering_bit/top_right_corner = 0
2:2/0/custom_data_0 = true
2:2/0/custom_data_1 = true
3:2/0 = 0
3:2/0/terrain_set = 0
3:2/0/terrain = 0
Expand All @@ -74,6 +75,7 @@ texture = ExtResource("1_e6sjf")
3:2/0/terrains_peering_bit/top_side = 0
3:2/0/terrains_peering_bit/top_right_corner = 0
3:2/0/custom_data_0 = true
3:2/0/custom_data_1 = true
4:2/0 = 0
4:2/0/terrain_set = 0
4:2/0/terrain = 0
Expand All @@ -86,6 +88,7 @@ texture = ExtResource("1_e6sjf")
4:2/0/terrains_peering_bit/top_side = 0
4:2/0/terrains_peering_bit/top_right_corner = 0
4:2/0/custom_data_0 = true
4:2/0/custom_data_1 = true
5:2/0 = 0
5:2/0/terrain_set = 0
5:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
Expand Down Expand Up @@ -117,6 +120,7 @@ texture = ExtResource("1_e6sjf")
2:3/0/terrains_peering_bit/top_side = 0
2:3/0/terrains_peering_bit/top_right_corner = 0
2:3/0/custom_data_0 = true
2:3/0/custom_data_1 = true
3:3/0 = 0
3:3/0/terrain_set = 0
3:3/0/terrain = 0
Expand All @@ -129,6 +133,7 @@ texture = ExtResource("1_e6sjf")
3:3/0/terrains_peering_bit/top_side = 0
3:3/0/terrains_peering_bit/top_right_corner = 0
3:3/0/custom_data_0 = true
3:3/0/custom_data_1 = true
4:3/0 = 0
4:3/0/terrain_set = 0
4:3/0/terrain = 0
Expand All @@ -141,6 +146,7 @@ texture = ExtResource("1_e6sjf")
4:3/0/terrains_peering_bit/top_side = 0
4:3/0/terrains_peering_bit/top_right_corner = 0
4:3/0/custom_data_0 = true
4:3/0/custom_data_1 = true
5:3/0 = 0
5:3/0/terrain_set = 0
5:3/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
Expand Down Expand Up @@ -169,6 +175,7 @@ texture = ExtResource("1_e6sjf")
2:4/0/terrains_peering_bit/top_side = 0
2:4/0/terrains_peering_bit/top_right_corner = 0
2:4/0/custom_data_0 = true
2:4/0/custom_data_1 = true
3:4/0 = 0
3:4/0/terrain_set = 0
3:4/0/terrain = 0
Expand All @@ -181,6 +188,7 @@ texture = ExtResource("1_e6sjf")
3:4/0/terrains_peering_bit/top_side = 0
3:4/0/terrains_peering_bit/top_right_corner = 0
3:4/0/custom_data_0 = true
3:4/0/custom_data_1 = true
4:4/0 = 0
4:4/0/terrain_set = 0
4:4/0/terrain = 0
Expand All @@ -193,6 +201,7 @@ texture = ExtResource("1_e6sjf")
4:4/0/terrains_peering_bit/top_side = 0
4:4/0/terrains_peering_bit/top_right_corner = 0
4:4/0/custom_data_0 = true
4:4/0/custom_data_1 = true
5:4/0 = 0
5:4/0/terrain_set = 0
5:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
Expand Down Expand Up @@ -282,4 +291,6 @@ terrain_set_0/terrain_0/name = "Ground"
terrain_set_0/terrain_0/color = Color(0.5, 0.34375, 0.25, 1)
custom_data_layer_0/name = "CanSpawnBox"
custom_data_layer_0/type = 1
custom_data_layer_1/name = "IsWalkable"
custom_data_layer_1/type = 1
sources/0 = SubResource("TileSetAtlasSource_a18vg")
4 changes: 2 additions & 2 deletions Modules/Tiles/Scripts/DRTileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ public partial class DRTileData
public int X { get; private set; }
public int Y { get; private set; }

public bool IsWalkable { get; private set; }
public bool IsWalkable { get; set; }

public bool IsSpawnPoint { get; private set; }
public bool IsSpawnPoint { get; set; }

public DRTileData()
{
Expand Down
26 changes: 26 additions & 0 deletions Shared/Scripts/Extensions/NodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace DungeonRoyale.Shared.Scripts.Extensions;

public static class NodeExtensions
{
public static List<T> GetRecursivelyNodesOfType<T>(this Node node, List<T>? nodesList = null) where T : Node
{
nodesList ??= [];

foreach (Node child in node.GetChildren())
{
if (child is T t)
{
nodesList.Add(t);
}

if (child.GetChildCount() > 0)
{
child.GetRecursivelyNodesOfType(nodesList);
}
}

return nodesList;
}
}
4 changes: 0 additions & 4 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ run/main_scene="res://Modules/Game/Scenes/Game.tscn"
config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
config/icon="res://icon.svg"

[autoload]

TilesManager="*res://Modules/GameManagers/Scripts/TilesManager.cs"

[dotnet]

project/assembly_name="DungeonRoyale"
Expand Down

0 comments on commit 9f3609e

Please sign in to comment.