feat: some stuff
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "input-float"
|
||||
name = "float"
|
||||
version = "0.1.0"
|
||||
authors = ["Max Richter <jim-x@web.de>"]
|
||||
edition = "2018"
|
||||
@@ -7,11 +7,6 @@ pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_id() -> String {
|
||||
"float".to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
utils::set_panic_hook();
|
||||
@@ -8,16 +8,11 @@ pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_id() -> String {
|
||||
"math".to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
utils::set_panic_hook();
|
||||
r#"{
|
||||
"op_type": { "type": "select", "labels": ["add", "subtract", "multiply", "divide"], "internal": true, "value": 0 },
|
||||
"op_type": { "label": "type", "type": "select", "labels": ["add", "subtract", "multiply", "divide"], "internal": true, "value": 0 },
|
||||
"a": { "type": "float", "value": 2 },
|
||||
"b": { "type": "float", "value": 2 }
|
||||
}"#.to_string()
|
||||
@@ -44,7 +39,7 @@ pub fn execute(var_op_type: u8, var_a: JsValue, var_b: JsValue) -> String {
|
||||
|
||||
// Interpolate strings into JSON format
|
||||
let json_string = format!(
|
||||
r#"{{"parameter": "math", "op_type": {}, "a": {}, "b": {}}}"#,
|
||||
r#"{{"__type": "math", "op_type": {}, "a": {}, "b": {}}}"#,
|
||||
var_op_type, a, b
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ wasm-bindgen = "0.2.84"
|
||||
# code size when deploying.
|
||||
plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod utils;
|
||||
use plantarium::unwrap_string;
|
||||
use plantarium::evaluate_parameters;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// lifted from the `console_log` example
|
||||
@@ -14,11 +14,6 @@ pub fn get_outputs() -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_id() -> String {
|
||||
"float".to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
utils::set_panic_hook();
|
||||
@@ -27,14 +22,11 @@ pub fn get_input_types() -> String {
|
||||
}"#
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(var_value: JsValue) -> String {
|
||||
pub fn execute(var_value: JsValue) -> f64 {
|
||||
utils::set_panic_hook();
|
||||
|
||||
let str = unwrap_string(var_value);
|
||||
let res = evaluate_parameters(var_value);
|
||||
|
||||
log(&format!("str: {}", str));
|
||||
|
||||
return str;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
mod utils;
|
||||
use plantarium::{unwrap_int, unwrap_string};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// lifted from the `console_log` example
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_id() -> String {
|
||||
"random".to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
utils::set_panic_hook();
|
||||
@@ -23,13 +26,36 @@ pub fn get_input_types() -> String {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(var_min: String, var_max: String, var_seed: i32) -> String {
|
||||
pub fn execute(var_min: JsValue, var_max: JsValue, var_seed: JsValue) -> String {
|
||||
utils::set_panic_hook();
|
||||
|
||||
let min: String;
|
||||
if var_min.is_string() {
|
||||
min = unwrap_string(var_min);
|
||||
} else {
|
||||
min = unwrap_int(var_min).to_string();
|
||||
}
|
||||
|
||||
let max: String;
|
||||
if var_max.is_string() {
|
||||
max = unwrap_string(var_max);
|
||||
} else {
|
||||
max = unwrap_int(var_max).to_string();
|
||||
}
|
||||
|
||||
let seed: String;
|
||||
if var_seed.is_string() {
|
||||
seed = unwrap_string(var_seed);
|
||||
} else {
|
||||
seed = unwrap_int(var_seed).to_string();
|
||||
}
|
||||
|
||||
log(&format!("min: {}, max: {}, seed: {}", min, max, seed));
|
||||
|
||||
// Interpolate strings into JSON format
|
||||
let json_string = format!(
|
||||
r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#,
|
||||
var_min, var_max, var_seed
|
||||
r#"{{"__type": "random", "min": {}, "max": {}, "seed": {}}}"#,
|
||||
min, max, seed
|
||||
);
|
||||
|
||||
json_string
|
||||
|
||||
Reference in New Issue
Block a user