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

ui features #146

Merged
merged 22 commits into from
Jan 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

hardcore-test:
name: Test Scenes
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions-rs/toolchain@v1
with:
Expand Down
35 changes: 27 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ world_ui = { path="crates/world_ui" }
collectibles = { path="crates/collectibles" }
social = { path="crates/social" }
imposters = { path="crates/imposters" }
system_bridge = { path="crates/system_bridge" }

bevy = { version = "0.14", default-features = false, features=[
"animation",
Expand Down Expand Up @@ -143,6 +144,7 @@ world_ui = { workspace = true }
collectibles = { workspace = true }
social = { workspace = true }
imposters = { workspace = true }
system_bridge = { workspace = true }

bevy = { workspace = true }
bevy_console = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion assets/ui/combo.dui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</define-template>

<define-template id="combo-popup">
<div style="position-type: absolute; top: '@top'; left: '@left'; height: '@height'; border: 1px; border-color: #88888888; background-color: '@background'" z-index="100">
<div style="position-type: absolute; top: '@top'; left: '@left'; height: '@height'; border: 1px; border-color: #88888888; background-color: '@background'" z-index="66667">
<div style="flex-direction: column; min-width: 100%; width: 100%; height: 100%">
<vscroll id="popup-scroll">
<div id="contents" style="width: 100%; min-width: 100%; flex-grow: 1; flex-direction: column; margin: 0px 2vmin 0px 0px;">
Expand Down
2 changes: 1 addition & 1 deletion assets/ui/fullscreen-block.dui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<define-template id="fullscreen-block">
<div focus="block" z-index="5" style="
<div focus="block" z-index="66666" style="
position-type: absolute;
width: 100%;
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion assets/ui/toast.dui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<define-template id="toaster">
<div style="position-type: absolute; left: 20%; right: 20%; top: 10%; max-width: 60%" z-index="1">
<div style="position-type: absolute; left: 20%; right: 20%; top: 10%; max-width: 60%" z-index="66668">
<space />
<div id="inner" style="flex-direction: column; justify-content: center;" />
<space />
Expand Down
1 change: 1 addition & 0 deletions crates/dcl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ common = { workspace = true }
dcl_component = { workspace = true }
ipfs = { workspace = true }
wallet = { workspace = true }
system_bridge = { workspace = true }

bevy = { workspace = true }
tokio = { workspace = true }
Expand Down
37 changes: 34 additions & 3 deletions crates/dcl/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use deno_core::{
include_js_files, op2, v8, Extension, JsRuntime, OpDecl, OpState, PollEventLoopOptions,
RuntimeOptions,
};
use system_bridge::SystemApi;
use tokio::sync::{mpsc::Receiver, Mutex};

use ipfs::{IpfsResource, SceneJsFile};
Expand Down Expand Up @@ -51,6 +52,7 @@ pub mod events;
#[cfg(feature = "inspect")]
pub mod inspector;
pub mod player;
pub mod system_api;
pub mod testing;
pub mod websocket;

Expand All @@ -59,7 +61,11 @@ pub struct ShuttingDown;

pub struct RendererStore(pub CrdtStore);

pub fn create_runtime(init: bool, inspect: bool) -> (JsRuntime, Option<InspectorServer>) {
pub fn create_runtime(
init: bool,
inspect: bool,
super_user: bool,
) -> (JsRuntime, Option<InspectorServer>) {
// add fetch stack
let net = deno_net::deno_net::init_ops_and_esm::<NP>(None, None);
let web = deno_web::deno_web::init_ops_and_esm::<TP>(
Expand All @@ -78,7 +84,7 @@ pub fn create_runtime(init: bool, inspect: bool) -> (JsRuntime, Option<Inspector

let mut ops = vec![op_require(), op_log(), op_error()];

let op_sets: [Vec<deno_core::OpDecl>; 12] = [
let op_sets: [Vec<deno_core::OpDecl>; 13] = [
engine::ops(),
restricted_actions::ops(),
runtime::ops(),
Expand All @@ -91,6 +97,7 @@ pub fn create_runtime(init: bool, inspect: bool) -> (JsRuntime, Option<Inspector
testing::ops(),
ethereum_controller::ops(),
adaption_layer_helper::ops(),
system_api::ops(super_user),
];

// add plugin registrations
Expand Down Expand Up @@ -176,6 +183,15 @@ pub fn create_runtime(init: bool, inspect: bool) -> (JsRuntime, Option<Inspector
// marker to notify that the scene/renderer interface functions were used
pub struct CommunicatedWithRenderer;

pub struct SuperUserScene(pub tokio::sync::mpsc::UnboundedSender<SystemApi>);
impl std::ops::Deref for SuperUserScene {
type Target = tokio::sync::mpsc::UnboundedSender<SystemApi>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

// main scene processing thread - constructs an isolate and runs the scene
#[allow(clippy::too_many_arguments)]
pub(crate) fn scene_thread(
Expand All @@ -191,9 +207,10 @@ pub(crate) fn scene_thread(
inspect: bool,
testing: bool,
preview: bool,
super_user: Option<tokio::sync::mpsc::UnboundedSender<SystemApi>>,
) {
let scene_context = CrdtContext::new(scene_id, scene_hash, testing, preview);
let (mut runtime, inspector) = create_runtime(false, inspect);
let (mut runtime, inspector) = create_runtime(false, inspect, super_user.is_some());

// store handle
let vm_handle = runtime.v8_isolate().thread_safe_handle();
Expand Down Expand Up @@ -235,6 +252,10 @@ pub(crate) fn scene_thread(
let span = info_span!("js startup").entered();
state.borrow_mut().put(span);

if let Some(super_user) = super_user {
state.borrow_mut().put(SuperUserScene(super_user));
}

// store kill handle
state
.borrow_mut()
Expand Down Expand Up @@ -429,6 +450,16 @@ fn op_require(
match module_spec.as_str() {
// user module load
"~scene.js" => Ok(state.borrow().borrow::<SceneJsFile>().0.as_ref().clone()),
// system api (only allowed for su scene)
"~system/BevyExplorerApi" => {
if state.borrow().try_borrow::<SuperUserScene>().is_some() {
Ok(include_str!("modules/SystemApi.js").to_owned())
} else {
Err(generic_error(format!(
"invalid module request `{module_spec}`"
)))
}
}
// core module load
"~system/CommunicationsController" => {
Ok(include_str!("modules/CommunicationsController.js").to_owned())
Expand Down
82 changes: 82 additions & 0 deletions crates/dcl/src/js/modules/SystemApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// system api module

const {
op_check_for_update, op_motd,
op_get_current_login, op_get_previous_login, op_login_previous, op_login_new_code, op_login_new_success, op_login_cancel, op_login_guest, op_logout,
op_settings, op_set_setting,
} = Deno.core.ops;

// (description: option<string>, url: option<string>)
module.exports.checkForUpdate = async function() {
const [description, url] = await op_check_for_update();
return {
description,
url
}
}

// (message: string)
module.exports.messageOfTheDay = async function() {
return {
message: await op_motd()
}
}

// (currentLogin: option<string>)
module.exports.getCurrentLogin = function() {
return {
current_login: op_get_current_login()
}
}

// (userId: option<string>)
module.exports.getPreviousLogin = async function() {
return {
userId: await op_get_previous_login()
}
}

// (success: bool, error: option<string>)
module.exports.loginPrevious = async function() {
return await op_login_previous()
}

// (code: Promise<option<string>>, success: Promise<(success: bool, error: option<string>)>)
module.exports.loginNew = function() {
return {
code: op_login_new_code(),
success: op_login_new_success(),
}
}

// nothing
module.exports.loginGuest = function() {
op_login_guest()
}

// nothing
module.exports.loginCancel = function() {
op_login_cancel()
}

// nothing
module.exports.logout = function() {
op_logout()
}

// array of {
// name: string,
// category: string,
// description: string,
// minValue: number,
// maxValue: number,
// namedVariants: [(variantName: string, variantDescription: string)]
// value: number,
// }
module.exports.getSettings = async function() {
return await op_settings();
}

module.exports.setSetting = async function(name, value) {
await op_set_setting(name, value);
}
Loading
Loading