diff options
Diffstat (limited to 'client/Archipelago/manager.gd')
| -rw-r--r-- | client/Archipelago/manager.gd | 303 |
1 files changed, 0 insertions, 303 deletions
| diff --git a/client/Archipelago/manager.gd b/client/Archipelago/manager.gd deleted file mode 100644 index 10c4096..0000000 --- a/client/Archipelago/manager.gd +++ /dev/null | |||
| @@ -1,303 +0,0 @@ | |||
| 1 | extends Node | ||
| 2 | |||
| 3 | const my_version = "0.1.0" | ||
| 4 | |||
| 5 | var SCRIPT_client | ||
| 6 | var SCRIPT_locationListener | ||
| 7 | var SCRIPT_uuid | ||
| 8 | |||
| 9 | var ap_server = "" | ||
| 10 | var ap_user = "" | ||
| 11 | var ap_pass = "" | ||
| 12 | var connection_history = [] | ||
| 13 | |||
| 14 | var client | ||
| 15 | |||
| 16 | var _localdata_file = "" | ||
| 17 | var _received_indexes = [] | ||
| 18 | var _last_new_item = -1 | ||
| 19 | |||
| 20 | signal could_not_connect | ||
| 21 | signal connect_status | ||
| 22 | signal ap_connected | ||
| 23 | |||
| 24 | |||
| 25 | func _init(): | ||
| 26 | # Read AP settings from file, if there are any | ||
| 27 | if FileAccess.file_exists("user://ap_settings"): | ||
| 28 | var file = FileAccess.open("user://ap_settings", FileAccess.READ) | ||
| 29 | var data = file.get_var(true) | ||
| 30 | file.close() | ||
| 31 | |||
| 32 | if typeof(data) != TYPE_ARRAY: | ||
| 33 | global._print("AP settings file is corrupted") | ||
| 34 | data = [] | ||
| 35 | |||
| 36 | if data.size() > 0: | ||
| 37 | ap_server = data[0] | ||
| 38 | |||
| 39 | if data.size() > 1: | ||
| 40 | ap_user = data[1] | ||
| 41 | |||
| 42 | if data.size() > 2: | ||
| 43 | ap_pass = data[2] | ||
| 44 | |||
| 45 | if data.size() > 3: | ||
| 46 | connection_history = data[3] | ||
| 47 | |||
| 48 | |||
| 49 | func _ready(): | ||
| 50 | client = SCRIPT_client.new() | ||
| 51 | client.SCRIPT_uuid = SCRIPT_uuid | ||
| 52 | |||
| 53 | client.connect("item_received", _process_item) | ||
| 54 | client.connect("message_received", _process_message) | ||
| 55 | client.connect("could_not_connect", _client_could_not_connect) | ||
| 56 | client.connect("connect_status", _client_connect_status) | ||
| 57 | client.connect("client_connected", _client_connected) | ||
| 58 | |||
| 59 | add_child(client) | ||
| 60 | |||
| 61 | |||
| 62 | func saveSettings(): | ||
| 63 | # Save the AP settings to disk. | ||
| 64 | var path = "user://ap_settings" | ||
| 65 | var file = FileAccess.open(path, FileAccess.WRITE) | ||
| 66 | |||
| 67 | var data = [ | ||
| 68 | ap_server, | ||
| 69 | ap_user, | ||
| 70 | ap_pass, | ||
| 71 | connection_history, | ||
| 72 | ] | ||
| 73 | file.store_var(data, true) | ||
| 74 | file.close() | ||
| 75 | |||
| 76 | |||
| 77 | func saveLocaldata(): | ||
| 78 | # Save the MW/slot specific settings to disk. | ||
| 79 | var dir = DirAccess.open("user://") | ||
| 80 | var folder = "archipelago_data" | ||
| 81 | if not dir.dir_exists(folder): | ||
| 82 | dir.make_dir(folder) | ||
| 83 | |||
| 84 | var file = FileAccess.open(_localdata_file, FileAccess.WRITE) | ||
| 85 | |||
| 86 | var data = [ | ||
| 87 | _last_new_item, | ||
| 88 | ] | ||
| 89 | file.store_var(data, true) | ||
| 90 | file.close() | ||
| 91 | |||
| 92 | |||
| 93 | func connectToServer(): | ||
| 94 | _received_indexes = [] | ||
| 95 | _last_new_item = -1 | ||
| 96 | |||
| 97 | client.connectToServer(ap_server, ap_user, ap_pass) | ||
| 98 | |||
| 99 | |||
| 100 | func getSaveFileName(): | ||
| 101 | return "zzAP_%s_%d" % [client._seed, client._slot] | ||
| 102 | |||
| 103 | |||
| 104 | func disconnect_from_ap(): | ||
| 105 | client.disconnect_from_ap() | ||
| 106 | |||
| 107 | |||
| 108 | func get_item_id_for_door(door_id): | ||
| 109 | var gamedata = global.get_node("Gamedata") | ||
| 110 | var door = gamedata.objects.get_doors()[door_id] | ||
| 111 | if ( | ||
| 112 | door.get_type() == gamedata.SCRIPT_proto.DoorType.EVENT | ||
| 113 | or door.get_type() == gamedata.SCRIPT_proto.DoorType.LOCATION_ONLY | ||
| 114 | or door.get_type() == gamedata.SCRIPT_proto.DoorType.CONTROL_CENTER_COLOR | ||
| 115 | ): | ||
| 116 | return null | ||
| 117 | return gamedata.get_door_ap_id(door_id) | ||
| 118 | |||
| 119 | |||
| 120 | func has_item(item_id): | ||
| 121 | return client.hasItem(item_id) | ||
| 122 | |||
| 123 | |||
| 124 | func _process_item(item, index, from, flags): | ||
| 125 | if index != null: | ||
| 126 | if _received_indexes.has(index): | ||
| 127 | # Do not re-process items. | ||
| 128 | return | ||
| 129 | |||
| 130 | _received_indexes.append(index) | ||
| 131 | |||
| 132 | var item_name = "Unknown" | ||
| 133 | if client._item_id_to_name["Lingo 2"].has(item): | ||
| 134 | item_name = client._item_id_to_name["Lingo 2"][item] | ||
| 135 | |||
| 136 | var gamedata = global.get_node("Gamedata") | ||
| 137 | var door_id = gamedata.door_id_by_ap_id.get(item, null) | ||
| 138 | if door_id != null and gamedata.get_door_map_name(door_id) == global.map: | ||
| 139 | var receivers = gamedata.get_door_receivers(door_id) | ||
| 140 | var scene = get_tree().get_root().get_node_or_null("scene") | ||
| 141 | if scene != null: | ||
| 142 | for receiver in receivers: | ||
| 143 | var rnode = scene.get_node_or_null(receiver) | ||
| 144 | if rnode != null: | ||
| 145 | rnode.handleTriggered() | ||
| 146 | #for painting_id in gamedata.objects.get_doors()[door_id].get_move_paintings(): | ||
| 147 | # var painting = gamedata.objects.get_paintings()[painting_id] | ||
| 148 | # var pnode = scene.get_node_or_null(painting.get_path() + "/teleportListener") | ||
| 149 | # if pnode != null: | ||
| 150 | # pnode.handleTriggered() | ||
| 151 | |||
| 152 | # Show a message about the item if it's new. | ||
| 153 | if index != null and index > _last_new_item: | ||
| 154 | _last_new_item = index | ||
| 155 | saveLocaldata() | ||
| 156 | |||
| 157 | var player_name = "Unknown" | ||
| 158 | if client._player_name_by_slot.has(from): | ||
| 159 | player_name = client._player_name_by_slot[from] | ||
| 160 | |||
| 161 | var item_color = colorForItemType(flags) | ||
| 162 | |||
| 163 | var message | ||
| 164 | if from == client._slot: | ||
| 165 | message = "Found [color=%s]%s[/color]" % [item_color, item_name] | ||
| 166 | else: | ||
| 167 | message = "Received [color=%s]%s[/color] from %s" % [item_color, item_name, player_name] | ||
| 168 | |||
| 169 | global._print(message) | ||
| 170 | |||
| 171 | global.get_node("Messages").showMessage(message) | ||
| 172 | |||
| 173 | |||
| 174 | func _process_message(message): | ||
| 175 | parse_printjson_for_textclient(message) | ||
| 176 | |||
| 177 | if ( | ||
| 178 | !message.has("receiving") | ||
| 179 | or !message.has("item") | ||
| 180 | or message["item"]["player"] != client._slot | ||
| 181 | ): | ||
| 182 | return | ||
| 183 | |||
| 184 | var item_name = "Unknown" | ||
| 185 | var item_player_game = client._game_by_player[message["receiving"]] | ||
| 186 | if client._item_id_to_name[item_player_game].has(message["item"]["item"]): | ||
| 187 | item_name = client._item_id_to_name[item_player_game][message["item"]["item"]] | ||
| 188 | |||
| 189 | var location_name = "Unknown" | ||
| 190 | var location_player_game = client._game_by_player[message["item"]["player"]] | ||
| 191 | if client._location_id_to_name[location_player_game].has(message["item"]["location"]): | ||
| 192 | location_name = ( | ||
| 193 | client._location_id_to_name[location_player_game][message["item"]["location"]] | ||
| 194 | ) | ||
| 195 | |||
| 196 | var player_name = "Unknown" | ||
| 197 | if client._player_name_by_slot.has(message["receiving"]): | ||
| 198 | player_name = client._player_name_by_slot[message["receiving"]] | ||
| 199 | |||
| 200 | var item_color = colorForItemType(message["item"]["flags"]) | ||
| 201 | |||
| 202 | if message["type"] == "Hint": | ||
| 203 | var is_for = "" | ||
| 204 | if message["receiving"] != client._slot: | ||
| 205 | is_for = " for %s" % player_name | ||
| 206 | if !message.has("found") || !message["found"]: | ||
| 207 | global.get_node("Messages").showMessage( | ||
| 208 | ( | ||
| 209 | "Hint: [color=%s]%s[/color]%s is on %s" | ||
| 210 | % [item_color, item_name, is_for, location_name] | ||
| 211 | ) | ||
| 212 | ) | ||
| 213 | else: | ||
| 214 | if message["receiving"] != client._slot: | ||
| 215 | var sentMsg = "Sent [color=%s]%s[/color] to %s" % [item_color, item_name, player_name] | ||
| 216 | #if _hinted_locations.has(message["item"]["location"]): | ||
| 217 | # sentMsg += " ([color=#fafad2]Hinted![/color])" | ||
| 218 | global.get_node("Messages").showMessage(sentMsg) | ||
| 219 | |||
| 220 | |||
| 221 | func parse_printjson_for_textclient(message): | ||
| 222 | var parts = [] | ||
| 223 | for message_part in message["data"]: | ||
| 224 | if !message_part.has("type") and message_part.has("text"): | ||
| 225 | parts.append(message_part["text"]) | ||
| 226 | elif message_part["type"] == "player_id": | ||
| 227 | if int(message_part["text"]) == client._slot: | ||
| 228 | parts.append( | ||
| 229 | "[color=#ee00ee]%s[/color]" % client._player_name_by_slot[client._slot] | ||
| 230 | ) | ||
| 231 | else: | ||
| 232 | var from = float(message_part["text"]) | ||
| 233 | parts.append("[color=#fafad2]%s[/color]" % client._player_name_by_slot[from]) | ||
| 234 | elif message_part["type"] == "item_id": | ||
| 235 | var item_name = "Unknown" | ||
| 236 | var item_player_game = client._game_by_player[message_part["player"]] | ||
| 237 | if client._item_id_to_name[item_player_game].has(int(message_part["text"])): | ||
| 238 | item_name = client._item_id_to_name[item_player_game][int(message_part["text"])] | ||
| 239 | |||
| 240 | parts.append( | ||
| 241 | "[color=%s]%s[/color]" % [colorForItemType(message_part["flags"]), item_name] | ||
| 242 | ) | ||
| 243 | elif message_part["type"] == "location_id": | ||
| 244 | var location_name = "Unknown" | ||
| 245 | var location_player_game = client._game_by_player[message_part["player"]] | ||
| 246 | if client._location_id_to_name[location_player_game].has(int(message_part["text"])): | ||
| 247 | location_name = client._location_id_to_name[location_player_game][int( | ||
| 248 | message_part["text"] | ||
| 249 | )] | ||
| 250 | |||
| 251 | parts.append("[color=#00ff7f]%s[/color]" % location_name) | ||
| 252 | elif message_part.has("text"): | ||
| 253 | parts.append(message_part["text"]) | ||
| 254 | |||
| 255 | var textclient_node = global.get_node("Textclient") | ||
| 256 | if textclient_node != null: | ||
| 257 | textclient_node.parse_printjson("".join(parts)) | ||
| 258 | |||
| 259 | |||
| 260 | func _client_could_not_connect(): | ||
| 261 | emit_signal("could_not_connect") | ||
| 262 | |||
| 263 | |||
| 264 | func _client_connect_status(message): | ||
| 265 | emit_signal("connect_status", message) | ||
| 266 | |||
| 267 | |||
| 268 | func _client_connected(): | ||
| 269 | _localdata_file = "user://archipelago_data/%s_%d" % [client._seed, client._slot] | ||
| 270 | _last_new_item = -1 | ||
| 271 | |||
| 272 | if FileAccess.file_exists(_localdata_file): | ||
| 273 | var ap_file = FileAccess.open(_localdata_file, FileAccess.READ) | ||
| 274 | var localdata = ap_file.get_var(true) | ||
| 275 | ap_file.close() | ||
| 276 | |||
| 277 | if typeof(localdata) != TYPE_ARRAY: | ||
| 278 | print("AP localdata file is corrupted") | ||
| 279 | localdata = [] | ||
| 280 | |||
| 281 | if localdata.size() > 0: | ||
| 282 | _last_new_item = localdata[0] | ||
| 283 | |||
| 284 | emit_signal("ap_connected") | ||
| 285 | |||
| 286 | |||
| 287 | func send_location(loc_id): | ||
| 288 | client.sendLocation(loc_id) | ||
| 289 | |||
| 290 | |||
| 291 | func colorForItemType(flags): | ||
| 292 | var int_flags = int(flags) | ||
| 293 | if int_flags & 1: # progression | ||
| 294 | if int_flags & 2: # proguseful | ||
| 295 | return "#f0d200" | ||
| 296 | else: | ||
| 297 | return "#bc51e0" | ||
| 298 | elif int_flags & 2: # useful | ||
| 299 | return "#2b67ff" | ||
| 300 | elif int_flags & 4: # trap | ||
| 301 | return "#d63a22" | ||
| 302 | else: # filler | ||
| 303 | return "#14de9e" | ||
