-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Coding-in-community/feat/adicionar-escanea…
…mento-de-mapa feat: adicionado classes iniciais de jogo que utilizara a classe mapsc…
- Loading branch information
Showing
16 changed files
with
210 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://doeo50prutum0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://bt46ejg3cyafl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://di6j7dxqlb03e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://c2q15i1u3gl3y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters