summaryrefslogtreecommitdiff
path: root/scripts/map/Map.cs
blob: 52ff588d6da2f079ad67f8ad1d1d3c3f7b4d687d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Godot;
using System;

public partial class Map : Node2D
{
	public MapData Map_Data { get; private set; }

	[Export]
	private int fovRadius = 12;

	private DungeonGenerator generator;

	FieldOfView fieldOfView;

	private Node2D tilesNode;
	private Node2D actorsNode;

	public override void _Ready()
	{
		base._Ready();

		generator = GetNode<DungeonGenerator>("Generator");
		fieldOfView = GetNode<FieldOfView>("FieldOfView");
		tilesNode = GetNode<Node2D>("Tiles");
		actorsNode = GetNode<Node2D>("Actors");
	}

	private void PlaceTiles() {
		foreach (Tile tile in Map_Data.Tiles) {
			tilesNode.AddChild(tile);
		}
	}

	private void PlaceActors() {
		foreach (Actor actor in Map_Data.Actors) {
			actorsNode.AddChild(actor);
		}
	}

	public void Generate(Player player)
	{
		Map_Data = generator.GenerateDungeon(player);

		player.Map_Data = Map_Data;

		PlaceTiles();
		PlaceActors();
	}

	public void UpdateFOV(Vector2I pos) {
		fieldOfView.UpdateFOV(Map_Data, pos, fovRadius);
	}
}