Skip to content

Commit

Permalink
Merge branch 'main' into bump-to-godot-4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
leanmendoza authored Sep 26, 2024
2 parents 0f4b670 + f715990 commit 8308018
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

1. Ensure you are in the root folder first
2. You can run `cargo run -- run` to build the Rust library and execute the client.
- With adding `-r` it builds the library in release mode. Note: the Godot executable is an editor, so it's a `release_debug` build, see the Target section [here](https://docs.godotengine.org/en/stable/contributing/development/compiling/introduction_to_the_buildsystem.html) for more infromation.
- With adding `-r` it builds the library in release mode. Note: the Godot executable is an editor, so it's a `release_debug` build, see the Target section [here](https://docs.godotengine.org/en/stable/contributing/development/compiling/introduction_to_the_buildsystem.html) for more information.
- With adding `-e` it also builds the library, but the project edition is executed instead of the client.

## Docker Set up project with Docker (for Android and Linux)
Expand Down
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

0 comments on commit 8308018

Please sign in to comment.