about summary refs log tree commit diff stats
path: root/Archipelago/multiplayer.gd
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-09-20 21:29:42 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-09-20 21:29:42 -0400
commite92ae750012d37733ef803e882eb8191ad530e11 (patch)
tree6f92094b11232b0bbd555acf9e0e510e83131666 /Archipelago/multiplayer.gd
parented3247cd00cde86026379aebba200fee673cdba0 (diff)
downloadlingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.tar.gz
lingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.tar.bz2
lingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.zip
Added proximity chat
Diffstat (limited to 'Archipelago/multiplayer.gd')
-rw-r--r--Archipelago/multiplayer.gd55
1 files changed, 55 insertions, 0 deletions
diff --git a/Archipelago/multiplayer.gd b/Archipelago/multiplayer.gd index 0bc2241..c2d9875 100644 --- a/Archipelago/multiplayer.gd +++ b/Archipelago/multiplayer.gd
@@ -1,5 +1,8 @@
1extends "res://scripts/multiplayer.gd" 1extends "res://scripts/multiplayer.gd"
2 2
3var queued_messages = []
4var queued_messages_mutex = Mutex.new()
5
3 6
4func _request_lobby_list(): 7func _request_lobby_list():
5 var apclient = global.get_node("Archipelago") 8 var apclient = global.get_node("Archipelago")
@@ -41,3 +44,55 @@ func _update_lobby_members():
41 if member_id != player_steam_id and member_id in active_lobby_members: 44 if member_id != player_steam_id and member_id in active_lobby_members:
42 var slot_name = Steam.getLobbyMemberData(active_lobby_id, member_id, "slot_name") 45 var slot_name = Steam.getLobbyMemberData(active_lobby_id, member_id, "slot_name")
43 active_lobby_members[member_id].steam_name = slot_name 46 active_lobby_members[member_id].steam_name = slot_name
47
48
49func say(text):
50 queued_messages_mutex.lock()
51 queued_messages.append(text)
52 queued_messages_mutex.unlock()
53
54
55func _physics_process(_delta):
56 if queued_messages_mutex.try_lock() == OK:
57 if queued_messages.empty():
58 queued_messages_mutex.unlock()
59 else:
60 var messages = queued_messages.duplicate()
61 queued_messages = []
62 queued_messages_mutex.unlock()
63
64 var player = get_tree().get_root().get_node("Spatial/player")
65 var space_state = get_tree().get_root().get_world().direct_space_state
66 var nearby_members = []
67 for member_id in active_lobby_members.keys():
68 var other_member = active_lobby_members[member_id]
69 var ray = space_state.intersect_ray(
70 player.global_translation, other_member.global_translation, [player], 0b0101
71 )
72 if !("collider" in ray) or ray["collider"] == other_member:
73 # Visible!
74 nearby_members.append(member_id)
75
76 var apclient = global.get_node("Archipelago")
77 var player_name = apclient.get_player_name()
78 for member_id in nearby_members:
79 for msg in messages:
80 _send_p2p_packet(
81 {"solves": [{"say": msg, "from": player_name}]},
82 member_id,
83 Steam.P2P_SEND_RELIABLE,
84 true
85 )
86
87
88# I'm completely hijacking this callback, since we're in ghost mode and it won't be called normally.
89func _receive_solve(data):
90 if "say" in data:
91 get_tree().get_root().get_node("Spatial/AP_TextClient").parse_printjson(
92 "[LOCAL] [color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]]
93 )
94 messages.showMessage("[color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]])
95
96
97func _send_hi(_discard):
98 pass