-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSelectTilemap.gd
103 lines (83 loc) · 3.21 KB
/
SelectTilemap.gd
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
extends TileMap
var GridXStart = Globals.GridXStart
var GridYStart = Globals.GridYStart
var GridSizeX = Globals.GridSizeX
var GridSizeY = Globals.GridSizeY
var TileRangeDic = {}
signal current_tile_signal(current_tile)
signal tile_in_diggable_limits(value)
var exploit_explore_label = ""
onready var tile_select_label = $"../LabelControl/TileSelectLabel"
var current_tile = Vector2.ZERO setget update_selected_tile
func update_selected_tile(value):
emit_signal("current_tile_signal", value)
#print("Current Tile Updated to " + str(value))
# Called when the node enters the scene tree for the first time.
func _ready():
for x in range(GridXStart, GridXStart + GridSizeX, 1):
for y in range(GridYStart, GridYStart + GridSizeY, 1):
TileRangeDic[str(Vector2(x, y))] = {
"Type": "Diggable"
}
set_cell(x, y , 0)
print(TileRangeDic)
func _process(delta):
# Don't really understand why I can't just set the first line
# to self.current_tile, but if I do, the label works but the
# highlighting of the selected tile stops working
# TODO: I feel like this is still firing the setter function
# more frequently than expected
if Globals.play_mode == "manual":
current_tile = world_to_map(get_global_mouse_position())
self.current_tile = current_tile
#print(current_tile)
# First turn off the TileSelect tile layer for all
for x in range(GridXStart, GridXStart + GridSizeX, 1):
for y in range(GridYStart, GridYStart + GridSizeY, 1):
set_cell(x, y, 0)
# Now check whether current tile is in the dict we
# set up at the beginning (so we don't set it for any old
# tile on the map
# If it is in the range of diggable tiles, then set the
# TileSelect outline to visible
if Globals.can_click:
if TileRangeDic.has(str(current_tile)):
emit_signal("tile_in_diggable_limits", true)
set_cell(current_tile[0], current_tile[1], 1)
else:
emit_signal("tile_in_diggable_limits", false)
func _on_Player_ai_selected_tile(current_tile):
# Flash up exploit/explore label
tile_select_label.visible = true
tile_select_label.text = exploit_explore_label
# change tile to orange border if it's the cell the AI
# has selected
for x in range(GridXStart, GridXStart + GridSizeX, 1):
for y in range(GridYStart, GridYStart + GridSizeY, 1):
#set_cell(x, y, 0)
#print(current_tile)
#print(Vector2(x,y))
if Vector2(x-GridXStart, y-GridYStart) == current_tile:
set_cell(x, y, 1)
#print("Bingo!")
else:
# otherwise set cell to have no orange border
set_cell(x, y, 0)
# Timer for keeping label and border on screen
yield(get_tree().create_timer(0.2), "timeout")
# get rid of border
for x in range(GridXStart, GridXStart + GridSizeX, 1):
for y in range(GridYStart, GridYStart + GridSizeY, 1):
set_cell(x, y, 0)
# keep label for a bit longer.
yield(get_tree().create_timer(0.2), "timeout")
if Globals.play_speed != 5:
tile_select_label.visible = false
# For selected tile, set the
# TileSelect outline to visible
#print("Current tile is " + str(current_tile))
#set_cell(current_tile[0]+GridXStart, current_tile[1]+GridYStart, 1)
#print(current_tile[0]+GridXStart)
#print(current_tile[1]+GridYStart)
func _on_Player_exploit_explore(value):
exploit_explore_label = value