Release 0.1.5: Update dependencies and reworked argument parsing

This commit is contained in:
Kyan Wanschers 2024-09-22 18:54:08 +02:00
parent be66e2cad3
commit 9c6c423e16
7 changed files with 150 additions and 71 deletions

82
Cargo.lock generated
View file

@ -4,15 +4,16 @@ version = 3
[[package]]
name = "ELApse"
version = "0.1.4"
version = "0.1.5"
dependencies = [
"clap",
"image",
"piston",
"piston2d-graphics",
"piston2d-graphics 0.45.0",
"piston_window",
"rand",
"unreal_asset",
"url",
]
[[package]]
@ -623,6 +624,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
[[package]]
name = "funty"
version = "2.0.0"
@ -809,6 +819,16 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "idna"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "image"
version = "0.25.2"
@ -1413,7 +1433,7 @@ dependencies = [
"gfx",
"piston-gfx_texture",
"piston-shaders_graphics2d",
"piston2d-graphics",
"piston2d-graphics 0.44.0",
"shader_version",
]
@ -1432,6 +1452,19 @@ dependencies = [
"vecmath",
]
[[package]]
name = "piston2d-graphics"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efa81d40c7b656d270fdbfeef8c531cc04493a001937f5a7d0c5cdb3db2b1469"
dependencies = [
"interpolation",
"piston-texture",
"piston-viewport",
"read_color",
"vecmath",
]
[[package]]
name = "piston_window"
version = "0.132.0"
@ -1443,7 +1476,7 @@ dependencies = [
"piston",
"piston-texture",
"piston2d-gfx_graphics",
"piston2d-graphics",
"piston2d-graphics 0.44.0",
"pistoncore-glutin_window",
"shader_version",
]
@ -2036,6 +2069,21 @@ dependencies = [
"strict-num",
]
[[package]]
name = "tinyvec"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml"
version = "0.8.19"
@ -2093,12 +2141,27 @@ version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a"
[[package]]
name = "unicode-bidi"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [
"tinyvec",
]
[[package]]
name = "unreal_asset"
version = "0.1.16"
@ -2146,6 +2209,17 @@ dependencies = [
"thiserror",
]
[[package]]
name = "url"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
]
[[package]]
name = "utf8parse"
version = "0.2.2"

View file

@ -1,6 +1,6 @@
[package]
name = "ELApse"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
repository = "https://github.com/BlackDragon-B/ELApse"
authors = ["BlackDragon-B <kyan@blackdrgn.nl>"]
@ -11,10 +11,11 @@ readme = "README.md"
clap = { version = "4.5.17", features = ["derive"] }
image = "0.25.2"
piston = "1.0.0"
piston2d-graphics = "0.44.0"
piston2d-graphics = "0.45.0"
piston_window = "0.132.0"
rand = "0.8.5"
unreal_asset = "0.1.16"
url = "2.5.2"
# The profile that 'cargo dist' will build with
[profile.dist]

View file

@ -1,6 +1,6 @@
use std::{ffi::OsStr, fs::{self, read, File}, os::raw, path::Path};
use image::{ImageFormat, ImageReader};
use unreal_asset::{asset::AssetTrait, cast, engine_version::EngineVersion, exports::{self, normal_export::NormalExport, Export, ExportBaseTrait}, properties::{array_property::ArrayProperty, color_property::ColorProperty, struct_property::StructProperty, Property}, types::{fname::FNameContainer, PackageIndex}, Asset};
use std::{ffi::OsStr, fs::{self, File}, path::Path};
use image::ImageFormat;
use unreal_asset::{cast, engine_version::EngineVersion, exports::Export, properties::Property, Asset};
fn rawrgb(path: &str) -> Result<Vec<u8>, String> {
match fs::read(path) {

View file

@ -30,9 +30,9 @@ pub fn stdin(tx: Sender<Vec<[f32; 4]>>) {
});
}
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>) {
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>,bindaddr: String) {
thread::spawn( move || {
let socket = UdpSocket::bind("127.0.0.1:21324").unwrap();
let socket = UdpSocket::bind(bindaddr).unwrap();
let mut buf = [0; 1500];
loop {
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
@ -45,6 +45,7 @@ pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>) {
pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
thread::spawn( move || {
let Ok(rawbytes) = fileparser::parse(&path) else {
println!("File not found");
std::process::exit(1)
};
for frame in rawbytes.chunks(720) {
@ -58,10 +59,3 @@ pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
std::process::exit(0);
});
}
#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Input {
stdin,
realtimeudp,
file,
}

View file

@ -6,60 +6,64 @@ mod utils;
mod fileparser;
use std::sync::mpsc::{self, Receiver, Sender};
use clap::{command, error::{self, ContextKind, ContextValue, ErrorKind}, Parser};
use clap::Parser;
use url::Url;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Input driver to use
/// Input to use
#[arg(short, long)]
input: input::Input,
input: String,
/// File input for the file driver
#[arg(required(false), short, long, requires = "input")]
file: Option<String>,
/// Output driver to use
/// Output to use
#[arg(short, long)]
output: output::Output,
/// Destination IP for the realtimeudp driver
#[arg(required(false), short, long, requires = "output")]
destip: Option<String>,
output: String,
}
fn main() {
let args = Args::parse();
// let mut arg = clap::command!()
// .arg(clap::arg!(-o --output <file> "The output file to write to. Use - for stdout."))
// .arg_required_else_help(true);
let (tx, rx): (Sender<Vec<[f32; 4]>>, Receiver<Vec<[f32; 4]>>) = mpsc::channel();
// if x {
// input::stdin(tx);
// } else {
// input::realtimeudp(tx)
// }
match args.input {
input::Input::stdin => input::stdin(tx),
input::Input::realtimeudp => input::realtimeudp(tx),
input::Input::file => {
if args.file.is_some() {
input::file(tx, args.file.unwrap());
} else {
utils::err_missing_args(vec!["--file".to_owned()])
match args.input.as_str() {
"-" | "stdin" => input::stdin(tx),
_ => {
match Url::parse(&args.input) {
Ok(o) => {
match o.scheme() {
"udp" => {
input::realtimeudp(tx, utils::get_host(o));
},
"file" => input::file(tx, o.path().to_owned()),
_ => {
println!("Unrecognized uri scheme");
std::process::exit(1);
}
}
},
Err(_) => {
input::file(tx, args.input);
},
};
}
}
match args.output.as_str() {
"piston" => output::piston(rx),
_ => {
match Url::parse(&args.output) {
Ok(o) => {
match o.scheme() {
"udp" => output::realtimeudp(rx,utils::get_host(o)),
_ => {
println!("Unrecognized uri scheme");
std::process::exit(1);
}
// input::file(tx);
// output::piston(rx) 21324
match args.output {
output::Output::piston => output::piston(rx),
output::Output::realtimeudp => {
if args.destip.is_some() {
output::realtimeudp(rx, args.destip.unwrap())
} else {
utils::err_missing_args(vec!["--destip".to_owned()])
}
},
Err(_) => {
println!("Output out of scope");
std::process::exit(1);
},
};
}
}
}

View file

@ -1,10 +1,8 @@
#![allow(non_camel_case_types)]
extern crate piston_window;
use graphics;
use piston_window::*;
use graphics::math::Scalar;
use std::{net::{SocketAddr, UdpSocket}, sync::mpsc::Receiver, time::Duration};
use piston_window::graphics::math::Scalar;
use std::{net::UdpSocket, sync::mpsc::Receiver, time::Duration};
use crate::utils::{compare, offset};

View file

@ -1,5 +1,3 @@
use clap::error::{ContextKind, ContextValue, ErrorKind};
pub fn compare(a: f64, b: f64) -> f64 {
if a > b {
b
@ -20,9 +18,19 @@ pub fn scaleu8tof32(old_value: u8) -> f32 { // Convert a u8 between 0 and 255 to
(((old_value as f32 - 0.0) * (0.0 - 1.0)) / (0.0 - 255.0)) + 0.0
}
pub fn err_missing_args(args: Vec<String>) {
let mut err = clap::Error::new(ErrorKind::MissingRequiredArgument);
err.insert(ContextKind::InvalidArg, ContextValue::Strings(args));
let _ = err.print();
pub fn get_host(url: url::Url) -> String {
match url.host_str() {
Some(addr) => {
let port = match url.port() {
Some(port) => port,
None => 21324,
};
return format!("{}:{}",addr,port);
},
None => {
println!("Invalid host");
std::process::exit(1);
},
}
}