online multiplayer chess game (note server currently down)
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
|
extends ConfirmButton
class_name UndoButton, "res://assets/ui/undo.png"
export(NodePath) onready var status = get_node(status) as StatusLabel
func _ready():
if Globals.network:
Globals.network.connect("undo", self, "undo_recieved")
func _pressed():
if Globals.spectating:
return
if waiting_on_answer:
_confirmed(true)
else:
if Utils.moves_list.size() == 0:
status.set_text("No moves to undo!")
return
elif Globals.turn == Globals.team:
status.set_text("It is your turn!")
return
Globals.network.send_packet({gamecode = Globals.network.game_code, question = ""}, Network.HEADERS.undo)
status.set_text("Undo request sent")
func undo_recieved(sig: Dictionary) -> void:
if "question" in sig:
confirm()
else:
if sig.accepted:
undo()
else:
Globals.chat.server("Undo request declined")
func _confirmed(what: bool) -> void:
._confirmed(what)
Globals.network.send_packet({gamecode = Globals.network.game_code, accepted = what}, Network.HEADERS.undo)
if what:
undo()
func undo():
var mov = Utils.pop_move()
Globals.chat.server("Move %s undone" % mov)
Globals.grid.undo(mov)
status.set_text("")
|