-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scenes rpcs thought tokio oneshot channels and change realm…
… for restricted action api (#62) * fix overlapping bug, when the camera mode area is removed (scene unload), now it triggers the overlapping correctly * add rpcs and change_realm restricted action * format * add confirmation dialog to move realm * format * Update rust/decentraland-godot-lib/src/dcl/js/js_modules/RestrictedActions.js Co-authored-by: Lean Mendoza <[email protected]> Signed-off-by: Mateo Miccino <[email protected]> --------- Signed-off-by: Mateo Miccino <[email protected]>
- Loading branch information
Showing
21 changed files
with
462 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extends DclConfirmDialog | ||
|
||
|
||
func _on_visibility_changed(): | ||
if is_visible(): | ||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://rffmwq3dxlaq"] | ||
|
||
[ext_resource type="FontFile" uid="uid://cmc7ku5u0efdy" path="res://assets/themes/fonts/lato_family/Lato-Bold.ttf" id="1_exitm"] | ||
[ext_resource type="Script" path="res://src/ui/confirm_dialog/confirm_dialog.gd" id="1_yn6j0"] | ||
|
||
[node name="ConfirmDialog" type="DclConfirmDialog"] | ||
custom_minimum_size = Vector2(360, 280) | ||
anchors_preset = 8 | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = -160.0 | ||
offset_top = -90.0 | ||
offset_right = 80.0 | ||
offset_bottom = 90.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
size_flags_horizontal = 4 | ||
size_flags_vertical = 4 | ||
script = ExtResource("1_yn6j0") | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="."] | ||
layout_mode = 1 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
offset_left = 10.0 | ||
offset_top = 10.0 | ||
offset_right = -10.0 | ||
offset_bottom = -10.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="Title" type="Label" parent="VBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
size_flags_vertical = 1 | ||
theme_override_fonts/font = ExtResource("1_exitm") | ||
theme_override_font_sizes/font_size = 22 | ||
text = "Title" | ||
horizontal_alignment = 1 | ||
clip_text = true | ||
|
||
[node name="Description" type="Label" parent="VBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
size_flags_vertical = 3 | ||
text = "Description" | ||
horizontal_alignment = 1 | ||
autowrap_mode = 2 | ||
clip_text = true | ||
|
||
[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"] | ||
layout_mode = 2 | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/CenterContainer"] | ||
layout_mode = 2 | ||
|
||
[node name="OkButton" type="Button" parent="VBoxContainer/CenterContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Yes" | ||
|
||
[node name="RejectButton" type="Button" parent="VBoxContainer/CenterContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "No" | ||
|
||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod rpc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::sync::{Arc, RwLock}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RpcResultSender<T>(Arc<RwLock<Option<tokio::sync::oneshot::Sender<T>>>>); | ||
|
||
impl<T: 'static> RpcResultSender<T> { | ||
pub fn new(sender: tokio::sync::oneshot::Sender<T>) -> Self { | ||
Self(Arc::new(RwLock::new(Some(sender)))) | ||
} | ||
|
||
pub fn send(&self, result: T) { | ||
if let Ok(mut guard) = self.0.write() { | ||
if let Some(response) = guard.take() { | ||
let _ = response.send(result); | ||
} | ||
} | ||
} | ||
|
||
pub fn take(&self) -> tokio::sync::oneshot::Sender<T> { | ||
self.0 | ||
.write() | ||
.ok() | ||
.and_then(|mut guard| guard.take()) | ||
.take() | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl<T: 'static> From<tokio::sync::oneshot::Sender<T>> for RpcResultSender<T> { | ||
fn from(value: tokio::sync::oneshot::Sender<T>) -> Self { | ||
RpcResultSender::new(value) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum RpcCall { | ||
ChangeRealm { | ||
to: String, | ||
message: Option<String>, | ||
response: RpcResultSender<Result<(), String>>, | ||
}, | ||
} | ||
|
||
pub type RpcCalls = Vec<RpcCall>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
rust/decentraland-godot-lib/src/dcl/js/js_modules/RestrictedActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
module.exports.movePlayerTo = async function (body) { return {} } | ||
module.exports.teleportTo = async function (body) { return {} } | ||
module.exports.triggerEmote = async function (body) { return {} } | ||
module.exports.changeRealm = async function (body) { return {} } | ||
module.exports.changeRealm = async function (body) { | ||
const response = await Deno.core.ops.op_change_realm(body.realm, body.message) | ||
return response | ||
} | ||
module.exports.openExternalUrl = async function (body) { return {} } | ||
module.exports.openNftDialog = async function (body) { return {} } | ||
module.exports.setCommunicationsAdapter = async function (body) { return {} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
rust/decentraland-godot-lib/src/dcl/js/restricted_actions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::{cell::RefCell, rc::Rc}; | ||
|
||
use deno_core::{op, Op, OpDecl, OpState}; | ||
|
||
use crate::common::rpc::{RpcCall, RpcCalls}; | ||
|
||
pub fn ops() -> Vec<OpDecl> { | ||
vec![op_change_realm::DECL] | ||
} | ||
|
||
#[op] | ||
async fn op_change_realm( | ||
op_state: Rc<RefCell<OpState>>, | ||
realm: String, | ||
message: Option<String>, | ||
) -> bool { | ||
let (sx, rx) = tokio::sync::oneshot::channel::<Result<(), String>>(); | ||
|
||
op_state | ||
.borrow_mut() | ||
.borrow_mut::<RpcCalls>() | ||
.push(RpcCall::ChangeRealm { | ||
to: realm, | ||
message, | ||
response: sx.into(), | ||
}); | ||
|
||
matches!(rx.await, Ok(Ok(_))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.