Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
/Cargo.lock
/node_modules
index.node
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cSpell.words": [
"Devs",
"faber",
"forgic",
"libic",
"minecraft",
"minreq",
"vanel",
"xmltojson"
]
}
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
description = "Blank Description"
edition = "2021"
license = "GPL-3.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our API wrappers will be MIT+Apache2

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we can change the license.

name = "ludic"
version = "0.1.0"

[dependencies]
either = {version = "1.6.1", features = ["serde"]}
faber = {version = "0.1.0", path = "../faber"}
forgic = {version = "0.1.0", path = "../forgic"}
futures = "0.3"
libic = {version = "0.1.0", path = "../libic"}
quantum-mc = {version = "0.1.0", path = "../quantum"}
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
vanel = {version = "0.1.0", path = "../vanel"}
neon = {version = "0.10.1", default-features = false, features = ["napi-6", "channel-api", "promise-api"]}
tokio = {version = "1", features = ["rt-multi-thread"]}
once_cell = "1"
1,348 changes: 674 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/converters/faber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use neon::{prelude::{FunctionContext, JsResult, Context, JsPromise}, result::NeonResult};
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
use crate::util::convert_array;

fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> {
static RUNTIME: OnceCell<Runtime> = OnceCell::new();

return RUNTIME.get_or_try_init(|| Runtime::new().or_else(|err| cx.throw_error(err.to_string())));
}

pub fn get_fabric_versions(mut ctx: FunctionContext) -> JsResult<JsPromise> {
let rt = runtime(&mut ctx)?;
let channel = ctx.channel();
let (def, pro) = ctx.promise();

rt.spawn(async move {
let raw = faber::get_fabric_versions().await;

def.settle_with(&channel, move |mut ctx| {
let conv = convert_array(&mut ctx, raw);
let res = conv.or_else(|err| ctx.throw_error(err.to_string()))?;

match Option::from(res) {
Some(res) => Ok(res),
None => ctx.throw_error("Could not get fabric releases!"),
}
});
});

return Ok(pro);
}
2 changes: 2 additions & 0 deletions src/converters/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod faber;
pub mod vanel;
1 change: 1 addition & 0 deletions src/converters/vanel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pub use faber::*;
pub use forgic::*;
pub use quantum_mc::*;
pub use vanel::*;

pub mod converters;
pub mod util;

pub mod tests {
#[test]
fn test_faber() {
let run = faber::get_fabric_versions();
let out = futures::executor::block_on(run);
println!("{:?}", out);
}

#[test]
fn test_forgic() {
let run = forgic::get_forge_versions();
let out = futures::executor::block_on(run);
println!("{:?}", out);
}

#[test]
fn test_quantum() {
let run = quantum_mc::get_quilt_versions();
let out = futures::executor::block_on(run);
println!("{:?}", out);
}

#[test]
fn test_vanel() {
let run = vanel::get_minecraft_versions();
let out = futures::executor::block_on(run);
println!("{:?}", out);
}
}
19 changes: 19 additions & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pub struct ModLoader {
/// The mod loader's name. Will be "vanilla," "forge," "quilt," or "fabric".
pub name: String,

/// The mod loader's version.
pub version: String,

/// The mod loader's download URL.
pub url: String,

/// The mod loader's download file name.
pub file_name: String,

/// The mod loader's download file size.
pub file_size: String,

/// The mod loader's launch command.
pub launch_command: Vec<String>,
}
12 changes: 12 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use neon::prelude::{Context, JsArray, JsResult, Object};

pub fn convert_array<'a, C: Context<'a>>(ctx: &mut C, vec: Vec<String>) -> JsResult<'a, JsArray> {
let arr = JsArray::new(ctx, vec.len() as u32);

for (i, s) in vec.iter().enumerate() {
let val = ctx.string(s);
arr.set(ctx, i as u32, val)?;
}

return Ok(arr);
}