Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changerealm and reload #451

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion godot/src/logic/realm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ func async_clear_realm():
Global.scene_runner.kill_all_scenes()


func async_set_realm(new_realm_string: String) -> void:
func async_set_realm(new_realm_string: String, search_new_pos: bool = false) -> void:
realm_string = new_realm_string
realm_url = Realm.ensure_ends_with_slash(Realm.resolve_realm_url(realm_string))
realm_url = Realm.ensure_starts_with_https(realm_url)

var promise: Promise = Global.http_requester.request_json(
realm_url + "about", HTTPClient.METHOD_GET, "", []
)
Expand Down Expand Up @@ -194,10 +195,43 @@ func async_set_realm(new_realm_string: String) -> void:
realm_about.get("content", {}).get("publicUrl")
)

if not realm_scene_urns.is_empty() and search_new_pos:
await async_request_set_position(realm_scene_urns.back())

Global.get_config().last_realm_joined = realm_url
Global.get_config().save_to_settings_file()

Global.metrics.update_realm(realm_url)

_has_realm = true
emit_signal("realm_changed")


func async_request_set_position(scene_urn):
prints(scene_urn)
var url = scene_urn.baseUrl + scene_urn.entityId

var promise: Promise = Global.http_requester.request_json(url, HTTPClient.METHOD_GET, "", [])

var res = await PromiseUtils.async_awaiter(promise)
if res is PromiseError:
printerr(
"Rejected request async_request_set_position: ",
scene_urn,
" error message: ",
res.get_error()
)
elif res is RequestResponse:
var response: RequestResponse = res
var json: Dictionary = response.get_string_response_as_json()
if json == null:
printerr("do_request_json failed because json_string is not a valid json")
return

var base_pos = json.get("metadata", {}).get("scene", {}).get("base", "0,0")
var coord = base_pos.split(",")
var x = int(coord[0])
var y = int(coord[1])
var explorer = Global.get_explorer()
if is_instance_valid(explorer):
explorer.teleport_to(Vector2i(x, y))
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func _ready():
return

# Disable some functions
#Global.realm.async_set_realm("null")
Global.scene_runner.set_pause(true)

Global.realm.content_base_url = profiles_to_process.base_url
Expand Down
5 changes: 3 additions & 2 deletions godot/src/ui/explorer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func _on_panel_chat_submit_message(message: String):
panel_chat.add_chat_message(
"[color=#ccc]> Trying to change to realm " + params[1] + "[/color]"
)
Global.realm.async_set_realm(params[1])
Global.realm.async_set_realm(params[1], true)
loading_ui.enable_loading_screen()
elif command_str == "/clear":
Global.realm.async_clear_realm()
Expand Down Expand Up @@ -353,8 +353,9 @@ func move_to(position: Vector3, skip_loading: bool):


func teleport_to(parcel: Vector2i, realm: String = ""):
if realm != Global.realm.get_realm_string():
if not realm.is_empty() && realm != Global.realm.get_realm_string():
Global.realm.async_set_realm(realm)

move_to(Vector3i(parcel.x * 16, 3, -parcel.y * 16), false)

Global.get_config().add_place_to_last_places(parcel, realm)
Expand Down
Loading