-
Notifications
You must be signed in to change notification settings - Fork 2
feat: adicionado classes iniciais de jogo que utilizara a classe mapsc… #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bba2b13
a8186d5
562c9e3
2cb481e
6176254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; |
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.
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://doeo50prutum0 |
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."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sugestão (risco_de_bug): Considere lançar exceções para falhas de inicialização em vez de apenas registrar erros Quando o gerenciador não pode ser inicializado corretamente (instância duplicada ou TileMaps necessários ausentes), o tratamento de erro atual permite que continue em um estado inválido. Isso pode levar a exceções de referência nula posteriormente. Implementação sugerida: public class TileMapManagerInitializationException : Exception
{
public TileMapManagerInitializationException(string message) : base(message) { }
}
public partial class TileMapManager : Node2D
{
public static TileMapManager? Instance { get; private set; } if (Instance is not null)
{
throw new TileMapManagerInitializationException("Já existe uma instância de TileMapManager na cena.");
}
Instance = this; O desenvolvedor precisará:
Original comment in Englishsuggestion (bug_risk): Consider throwing exceptions for initialization failures instead of just logging errors When the manager can't be properly initialized (duplicate instance or missing required TileMaps), the current error handling allows it to continue in an invalid state. This could lead to null reference exceptions later. Suggested implementation: public class TileMapManagerInitializationException : Exception
{
public TileMapManagerInitializationException(string message) : base(message) { }
}
public partial class TileMapManager : Node2D
{
public static TileMapManager? Instance { get; private set; } if (Instance is not null)
{
throw new TileMapManagerInitializationException("There is already an instance of TileMapManager in the scene.");
}
Instance = this; The developer will need to:
|
||
} | ||
|
||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://bt46ejg3cyafl |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://di6j7dxqlb03e |
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://c2q15i1u3gl3y |
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; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.