about summary refs log tree commit diff stats
path: root/Archipelago
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-09-02 11:49:12 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-09-02 11:49:12 -0400
commit400ad1ed74166d3f01adf6d97f07a16ec391f2a9 (patch)
tree74daf09a579867f1e8715d70a2797bd18025062e /Archipelago
parent6b5b85f96fc855810ac21e96e1aeb9cbde0fe88e (diff)
downloadlingo-archipelago-400ad1ed74166d3f01adf6d97f07a16ec391f2a9.tar.gz
lingo-archipelago-400ad1ed74166d3f01adf6d97f07a16ec391f2a9.tar.bz2
lingo-archipelago-400ad1ed74166d3f01adf6d97f07a16ec391f2a9.zip
Added text client
Diffstat (limited to 'Archipelago')
-rw-r--r--Archipelago/client.gd44
-rw-r--r--Archipelago/load.gd6
-rw-r--r--Archipelago/pause_menu.gd5
-rw-r--r--Archipelago/settings_screen.gd1
-rw-r--r--Archipelago/textclient.gd88
5 files changed, 144 insertions, 0 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index aa50069..f58b3d6 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd
@@ -8,6 +8,7 @@ var SCRIPT_mypainting
8var SCRIPT_notifier 8var SCRIPT_notifier
9var SCRIPT_panel 9var SCRIPT_panel
10var SCRIPT_pilgrimage_terminator 10var SCRIPT_pilgrimage_terminator
11var SCRIPT_textclient
11var SCRIPT_uuid 12var SCRIPT_uuid
12 13
13var ap_server = "" 14var ap_server = ""
@@ -451,6 +452,8 @@ func _on_data():
451 i += 1 452 i += 1
452 453
453 elif cmd == "PrintJSON": 454 elif cmd == "PrintJSON":
455 parse_printjson(message)
456
454 if ( 457 if (
455 !message.has("receiving") 458 !message.has("receiving")
456 or !message.has("item") 459 or !message.has("item")
@@ -684,6 +687,10 @@ func setValue(key, value, operation = "replace"):
684 ) 687 )
685 688
686 689
690func say(textdata):
691 sendMessage([{"cmd": "Say", "text": textdata}])
692
693
687func completedGoal(): 694func completedGoal():
688 sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL 695 sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL
689 696
@@ -855,6 +862,43 @@ func colorForItemType(flags):
855 return "#14de9e" 862 return "#14de9e"
856 863
857 864
865func parse_printjson(message):
866 var parts = []
867 for message_part in message["data"]:
868 if !message_part.has("type") and message_part.has("text"):
869 parts.append(message_part["text"])
870 elif message_part["type"] == "player_id":
871 if int(message_part["text"]) == _slot:
872 parts.append("[color=#ee00ee]%s[/color]" % _player_name_by_slot[_slot])
873 else:
874 var from = float(message_part["text"])
875 parts.append("[color=#fafad2]%s[/color]" % _player_name_by_slot[from])
876 elif message_part["type"] == "item_id":
877 var item_name = "Unknown"
878 var item_player_game = _game_by_player[message_part["player"]]
879 if _item_id_to_name[item_player_game].has(float(message_part["text"])):
880 item_name = _item_id_to_name[item_player_game][float(message_part["text"])]
881
882 parts.append(
883 "[color=%s]%s[/color]" % [colorForItemType(message_part["flags"]), item_name]
884 )
885 elif message_part["type"] == "location_id":
886 var location_name = "Unknown"
887 var location_player_game = _game_by_player[message_part["player"]]
888 if _location_id_to_name[location_player_game].has(float(message_part["text"])):
889 location_name = _location_id_to_name[location_player_game][float(
890 message_part["text"]
891 )]
892
893 parts.append("[color=#00ff7f]%s[/color]" % location_name)
894 elif message_part.has("text"):
895 parts.append(message_part["text"])
896
897 var textclient_node = get_tree().get_root().get_node_or_null("Spatial/AP_TextClient")
898 if textclient_node != null:
899 textclient_node.parse_printjson("".join(parts))
900
901
858func compareVersion(lhs, rhs): 902func compareVersion(lhs, rhs):
859 if lhs["major"] == rhs["major"]: 903 if lhs["major"] == rhs["major"]:
860 if lhs["minor"] == rhs["minor"]: 904 if lhs["minor"] == rhs["minor"]:
diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 931dfde..c35525b 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd
@@ -663,6 +663,12 @@ func _load():
663 effects.set_name("AP_Effects") 663 effects.set_name("AP_Effects")
664 self.add_child(effects) 664 self.add_child(effects)
665 665
666 # Create the textclient node.
667 var textclient_script = apclient.SCRIPT_textclient
668 var textclient = textclient_script.new()
669 textclient.set_name("AP_TextClient")
670 self.add_child(textclient)
671
666 # Create the multiplayer node, if needed. 672 # Create the multiplayer node, if needed.
667 if apclient.enable_multiplayer: 673 if apclient.enable_multiplayer:
668 var multiplayer_node = apclient.SCRIPT_multiplayer.new() 674 var multiplayer_node = apclient.SCRIPT_multiplayer.new()
diff --git a/Archipelago/pause_menu.gd b/Archipelago/pause_menu.gd index 40994d9..62ba6c3 100644 --- a/Archipelago/pause_menu.gd +++ b/Archipelago/pause_menu.gd
@@ -6,3 +6,8 @@ func _main_menu():
6 apclient.disconnect_from_ap() 6 apclient.disconnect_from_ap()
7 7
8 ._main_menu() 8 ._main_menu()
9
10
11func _pause_game():
12 get_tree().get_root().get_node("Spatial/AP_TextClient").dismiss()
13 ._pause_game()
diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 6c64b15..2ed8594 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd
@@ -32,6 +32,7 @@ func _ready():
32 apclient_instance.SCRIPT_panel = load("user://maps/Archipelago/panel.gd") 32 apclient_instance.SCRIPT_panel = load("user://maps/Archipelago/panel.gd")
33 var pilg_term = load("user://maps/Archipelago/pilgrimage_terminator.gd") 33 var pilg_term = load("user://maps/Archipelago/pilgrimage_terminator.gd")
34 apclient_instance.SCRIPT_pilgrimage_terminator = pilg_term 34 apclient_instance.SCRIPT_pilgrimage_terminator = pilg_term
35 apclient_instance.SCRIPT_textclient = load("user://maps/Archipelago/textclient.gd")
35 apclient_instance.SCRIPT_uuid = load("user://maps/Archipelago/vendor/uuid.gd") 36 apclient_instance.SCRIPT_uuid = load("user://maps/Archipelago/vendor/uuid.gd")
36 37
37 var apdata = ResourceLoader.load("user://maps/Archipelago/gamedata.gd") 38 var apdata = ResourceLoader.load("user://maps/Archipelago/gamedata.gd")
diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd new file mode 100644 index 0000000..7bddf38 --- /dev/null +++ b/Archipelago/textclient.gd
@@ -0,0 +1,88 @@
1extends Node
2
3var panel
4var label
5var entry
6var is_open = false
7
8
9func _ready():
10 pause_mode = PAUSE_MODE_PROCESS
11
12 panel = Panel.new()
13 panel.set_name("Panel")
14 panel.margin_left = 100
15 panel.margin_right = 1820
16 panel.margin_top = 100
17 panel.margin_bottom = 980
18 panel.visible = false
19 add_child(panel)
20
21 label = RichTextLabel.new()
22 label.set_name("Label")
23 label.margin_left = 80
24 label.margin_right = 1640
25 label.margin_top = 80
26 label.margin_bottom = 720
27 label.scroll_following = true
28 panel.add_child(label)
29
30 var dynamic_font = DynamicFont.new()
31 dynamic_font.font_data = load("res://fonts/Lingo.ttf")
32 dynamic_font.size = 36
33 label.push_font(dynamic_font)
34
35 var entry_style = StyleBoxFlat.new()
36 entry_style.bg_color = Color(0.9, 0.9, 0.9, 1)
37
38 entry = LineEdit.new()
39 entry.set_name("Entry")
40 entry.margin_left = 80
41 entry.margin_right = 1640
42 entry.margin_top = 760
43 entry.margin_bottom = 840
44 entry.add_font_override("font", dynamic_font)
45 entry.add_color_override("font_color", Color(0, 0, 0, 1))
46 entry.add_color_override("cursor_color", Color(0, 0, 0, 1))
47 entry.add_stylebox_override("focus", entry_style)
48 panel.add_child(entry)
49 entry.connect("text_entered", self, "text_entered")
50
51
52func _input(event):
53 if event is InputEventKey and event.pressed:
54 if event.scancode == KEY_TAB:
55 if !get_tree().paused:
56 is_open = true
57 get_tree().paused = true
58 Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
59 panel.visible = true
60 entry.grab_focus()
61 get_tree().set_input_as_handled()
62 else:
63 dismiss()
64 elif event.scancode == KEY_ESCAPE:
65 if is_open:
66 dismiss()
67 get_tree().set_input_as_handled()
68
69
70func dismiss():
71 if is_open:
72 get_tree().paused = false
73 Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
74 panel.visible = false
75 is_open = false
76
77
78func parse_printjson(text):
79 if !label.text.empty():
80 label.append_bbcode("\n")
81
82 label.append_bbcode(text)
83
84
85func text_entered(text):
86 var apclient = global.get_node("Archipelago")
87 apclient.say(text.trim_suffix("\n"))
88 entry.text = ""