-
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.
- Loading branch information
1 parent
b1748a3
commit 6b8b07c
Showing
5 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
37 changes: 34 additions & 3 deletions
37
rust/decentraland-godot-lib/src/dcl/js/js_modules/Testing.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,3 +1,34 @@ | ||
module.exports.logTestResult = async function (body) { return {} } | ||
module.exports.plan = async function (body) { return {} } | ||
module.exports.setCameraTransform = async function (body) { return {} } | ||
const env = require('env') | ||
|
||
const testingEnabled = env['testing_enable'] | ||
|
||
function emptyTesting() { | ||
return { | ||
logTestResult: async function (body) { return {} }, | ||
plan: async function (body) { return {} }, | ||
setCameraTransform: async function (body) { return {} }, | ||
} | ||
} | ||
|
||
function testingModule() { | ||
function takeAndCompareSnapshot(body) { | ||
const { id, cameraPosition, cameraTarget, snapshotFrameSize, tolerance } = body | ||
|
||
return Deno.core.ops.op_take_and_compare_snapshot( | ||
id, | ||
[cameraPosition.x, cameraPosition.y, cameraPosition.z], | ||
[cameraTarget.x, cameraTarget.y, cameraTarget.z], | ||
[snapshotFrameSize.x, snapshotFrameSize.y], | ||
tolerance | ||
); | ||
} | ||
|
||
return { | ||
logTestResult: async function (body) { return {} }, | ||
plan: async function (body) { return {} }, | ||
setCameraTransform: async function (body) { return {} }, | ||
takeAndCompareSnapshot | ||
} | ||
} | ||
|
||
module.exports = testingEnabled ? testingModule() : emptyTesting() |
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,59 @@ | ||
use deno_core::{ | ||
anyhow::{self, anyhow}, | ||
error::AnyError, | ||
op, Op, OpDecl, OpState, | ||
}; | ||
use godot::builtin::{Vector2, Vector3}; | ||
|
||
use crate::dcl::{SceneResponse, TakeAndCompareSnapshotResponse}; | ||
|
||
use super::SceneEnv; | ||
|
||
pub fn ops() -> Vec<OpDecl> { | ||
vec![op_take_and_compare_snapshot::DECL] | ||
} | ||
|
||
#[op] | ||
fn op_take_and_compare_snapshot( | ||
state: &mut OpState, | ||
id: String, | ||
camera_position: [f32; 3], | ||
camera_target: [f32; 3], | ||
snapshot_frame_size: [f32; 2], | ||
tolerance: f32, | ||
) -> Result<TakeAndCompareSnapshotResponse, AnyError> { | ||
let scene_env = state.borrow::<SceneEnv>(); | ||
if !scene_env.testing_enable { | ||
return Err(anyhow::anyhow!("Testing mode not available")); | ||
} | ||
|
||
let (sx, rx) = | ||
tokio::sync::oneshot::channel::<Result<TakeAndCompareSnapshotResponse, String>>(); | ||
|
||
let sender = state.borrow_mut::<std::sync::mpsc::SyncSender<SceneResponse>>(); | ||
sender | ||
.send(SceneResponse::TakeSnapshot { | ||
id, | ||
camera_position: Vector3 { | ||
x: camera_position[0], | ||
y: camera_position[1], | ||
z: camera_position[2], | ||
}, | ||
camera_target: Vector3 { | ||
x: camera_target[0], | ||
y: camera_target[1], | ||
z: camera_target[2], | ||
}, | ||
snapshot_frame_size: Vector2 { | ||
x: snapshot_frame_size[0], | ||
y: snapshot_frame_size[1], | ||
}, | ||
tolerance, | ||
response: sx.into(), | ||
}) | ||
.expect("error sending scene response!!"); | ||
|
||
rx.blocking_recv() | ||
.map_err(|e| anyhow::anyhow!(e))? | ||
.map_err(|e| anyhow!(e)) | ||
} |
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