diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-09-20 21:29:42 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-09-20 21:29:42 -0400 |
commit | e92ae750012d37733ef803e882eb8191ad530e11 (patch) | |
tree | 6f92094b11232b0bbd555acf9e0e510e83131666 | |
parent | ed3247cd00cde86026379aebba200fee673cdba0 (diff) | |
download | lingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.tar.gz lingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.tar.bz2 lingo-archipelago-e92ae750012d37733ef803e882eb8191ad530e11.zip |
Added proximity chat
-rw-r--r-- | Archipelago/client.gd | 4 | ||||
-rw-r--r-- | Archipelago/load.gd | 1 | ||||
-rw-r--r-- | Archipelago/multiplayer.gd | 55 | ||||
-rw-r--r-- | Archipelago/textclient.gd | 13 |
4 files changed, 72 insertions, 1 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 6621194..a636bec 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd | |||
@@ -912,6 +912,10 @@ func parse_printjson(message): | |||
912 | textclient_node.parse_printjson("".join(parts)) | 912 | textclient_node.parse_printjson("".join(parts)) |
913 | 913 | ||
914 | 914 | ||
915 | func get_player_name(): | ||
916 | return _player_name_by_slot[_slot] | ||
917 | |||
918 | |||
915 | func compareVersion(lhs, rhs): | 919 | func compareVersion(lhs, rhs): |
916 | if lhs["major"] == rhs["major"]: | 920 | if lhs["major"] == rhs["major"]: |
917 | if lhs["minor"] == rhs["minor"]: | 921 | if lhs["minor"] == rhs["minor"]: |
diff --git a/Archipelago/load.gd b/Archipelago/load.gd index c35525b..09aaee2 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd | |||
@@ -672,6 +672,7 @@ func _load(): | |||
672 | # Create the multiplayer node, if needed. | 672 | # Create the multiplayer node, if needed. |
673 | if apclient.enable_multiplayer: | 673 | if apclient.enable_multiplayer: |
674 | var multiplayer_node = apclient.SCRIPT_multiplayer.new() | 674 | var multiplayer_node = apclient.SCRIPT_multiplayer.new() |
675 | multiplayer_node.name = "Multiplayer" | ||
675 | multiplayer_node.ghost_mode = true | 676 | multiplayer_node.ghost_mode = true |
676 | add_child(multiplayer_node) | 677 | add_child(multiplayer_node) |
677 | 678 | ||
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 @@ | |||
1 | extends "res://scripts/multiplayer.gd" | 1 | extends "res://scripts/multiplayer.gd" |
2 | 2 | ||
3 | var queued_messages = [] | ||
4 | var queued_messages_mutex = Mutex.new() | ||
5 | |||
3 | 6 | ||
4 | func _request_lobby_list(): | 7 | func _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 | |||
49 | func say(text): | ||
50 | queued_messages_mutex.lock() | ||
51 | queued_messages.append(text) | ||
52 | queued_messages_mutex.unlock() | ||
53 | |||
54 | |||
55 | func _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. | ||
89 | func _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 | |||
97 | func _send_hi(_discard): | ||
98 | pass | ||
diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd index 7bddf38..f100776 100644 --- a/Archipelago/textclient.gd +++ b/Archipelago/textclient.gd | |||
@@ -84,5 +84,16 @@ func parse_printjson(text): | |||
84 | 84 | ||
85 | func text_entered(text): | 85 | func text_entered(text): |
86 | var apclient = global.get_node("Archipelago") | 86 | var apclient = global.get_node("Archipelago") |
87 | apclient.say(text.trim_suffix("\n")) | 87 | var cmd = text.trim_suffix("\n") |
88 | if cmd.begins_with("/say "): | ||
89 | if apclient.enable_multiplayer: | ||
90 | var msg = cmd.trim_prefix("/say ") | ||
91 | parse_printjson( | ||
92 | "[LOCAL] [color=#ee00ee]%s[/color]: %s" % [apclient.get_player_name(), msg] | ||
93 | ) | ||
94 | get_tree().get_root().get_node("Spatial/Multiplayer").say(msg) | ||
95 | else: | ||
96 | parse_printjson("Multiplayer must be enabled to use /say") | ||
97 | else: | ||
98 | apclient.say(cmd) | ||
88 | entry.text = "" | 99 | entry.text = "" |