Skip to content

Commit

Permalink
Merge pull request #931 from AmbientRun/randomly-generated-ids
Browse files Browse the repository at this point in the history
Randomly generated IDs
  • Loading branch information
philpax authored Sep 26, 2023
2 parents 4f907a2 + 7e35f1a commit 2ae01fb
Show file tree
Hide file tree
Showing 151 changed files with 961 additions and 649 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: dtolnay/rust-toolchain@stable
- run: rustup target add --toolchain stable wasm32-wasi
- uses: actions/checkout@v3
- name: Rust cache
uses: Leafwing-Studios/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

77 changes: 41 additions & 36 deletions app/src/cli/assets.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use ambient_native_std::asset_cache::AssetCache;
use anyhow::Context;
use clap::{Args, Subcommand};

use super::PackagePath;

#[derive(Subcommand, Clone, Debug)]
pub enum AssetCommand {
pub enum Assets {
/// Migrate json pipelines to toml
#[command(name = "migrate-pipelines-toml")]
MigratePipelinesToml(MigrateOptions),
Expand All @@ -17,14 +18,14 @@ pub enum AssetCommand {

#[derive(Args, Clone, Debug)]
pub struct MigrateOptions {
#[arg(index = 1, default_value = "./assets")]
#[arg(default_value = "./assets")]
/// The path to the assets folder
pub path: PathBuf,
}

#[derive(Args, Clone, Debug)]
pub struct ImportOptions {
#[arg(index = 1)]
#[arg()]
/// The path to the assets you want to import
pub path: PathBuf,
#[arg(long)]
Expand All @@ -35,41 +36,45 @@ pub struct ImportOptions {
pub collider_from_model: bool,
}

pub async fn handle(command: &AssetCommand, assets: &crate::AssetCache) -> anyhow::Result<()> {
pub async fn handle(command: &Assets, assets: &AssetCache) -> anyhow::Result<()> {
match command {
AssetCommand::MigratePipelinesToml(opt) => {
let path = PackagePath::new_local(opt.path.clone())?;
ambient_build::migrate::toml::process(path.fs_path.unwrap())
.await
.context("Failed to migrate pipelines")?;
Assets::MigratePipelinesToml(opt) => {
migrate_pipelines_toml(opt).await?;
}
AssetCommand::Import(opt) => match opt.path.extension() {
Some(ext) => {
if ext == "wav" || ext == "mp3" || ext == "ogg" {
let convert = opt.convert_audio;
ambient_build::pipelines::import_audio(opt.path.clone(), convert)
.context("Failed to import audio")?;
} else if ext == "fbx" || ext == "glb" || ext == "gltf" || ext == "obj" {
let collider_from_model = opt.collider_from_model;
ambient_build::pipelines::import_model(opt.path.clone(), collider_from_model)
.context("Failed to import models")?;
} else if ext == "jpg" || ext == "png" || ext == "gif" || ext == "webp" {
// TODO: import textures API may change, so this is just a placeholder
todo!();
} else {
anyhow::bail!("Unsupported file type");
}
ambient_build::build_assets(
assets,
&PathBuf::from("assets"),
&PathBuf::from("build"),
true,
)
.await?;
}
None => anyhow::bail!("Unknown file type"),
},
Assets::Import(opt) => import(opt, assets).await?,
}

Ok(())
}

async fn migrate_pipelines_toml(opt: &MigrateOptions) -> Result<(), anyhow::Error> {
let path = PackagePath::new_local(opt.path.clone())?;
ambient_build::migrate::toml::process(path.fs_path.unwrap())
.await
.context("Failed to migrate pipelines")?;
Ok(())
}

async fn import(opt: &ImportOptions, assets: &AssetCache) -> anyhow::Result<()> {
let Some(ext) = opt.path.extension() else {
anyhow::bail!("Unknown file type");
};

if ext == "wav" || ext == "mp3" || ext == "ogg" {
let convert = opt.convert_audio;
ambient_build::pipelines::import_audio(opt.path.clone(), convert)
.context("Failed to import audio")?;
} else if ext == "fbx" || ext == "glb" || ext == "gltf" || ext == "obj" {
let collider_from_model = opt.collider_from_model;
ambient_build::pipelines::import_model(opt.path.clone(), collider_from_model)
.context("Failed to import models")?;
} else if ext == "jpg" || ext == "png" || ext == "gif" || ext == "webp" {
// TODO: import textures API may change, so this is just a placeholder
todo!();
} else {
anyhow::bail!("Unsupported file type");
}
ambient_build::build_assets(assets, Path::new("assets"), Path::new("build"), true).await?;

Ok(())
}
45 changes: 0 additions & 45 deletions app/src/cli/client.rs

This file was deleted.

44 changes: 44 additions & 0 deletions app/src/cli/join.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use ambient_native_std::{
asset_cache::{AssetCache, SyncAssetKeyExt},
download_asset::ReqwestClientKey,
};
use ambient_network::native::client::ResolvedAddr;
use clap::Parser;

use crate::{client, server::QUIC_INTERFACE_PORT};

use super::ClientCli;

#[derive(Parser, Clone, Debug)]
/// Join a multiplayer session
pub struct Join {
#[command(flatten)]
pub client: ClientCli,
/// The server to connect to; defaults to localhost
pub host: Option<String>,
}

pub fn handle(args: &Join, rt: &tokio::runtime::Runtime, assets: AssetCache) -> anyhow::Result<()> {
let assets_ref = &assets;
let server_addr = rt.block_on(async move {
let Some(mut host) = args.host.as_ref().cloned() else {
return Ok(ResolvedAddr::localhost_with_port(QUIC_INTERFACE_PORT));
};

if host.starts_with("http://") || host.starts_with("https://") {
tracing::info!("NOTE: Joining server by http url is still experimental and can be removed without warning.");

let reqwest = &ReqwestClientKey.get(assets_ref);
host = reqwest.get(host).send().await?.text().await?;

if host.is_empty() {
anyhow::bail!("Failed to resolve host");
}
}
if !host.contains(':') {
host = format!("{host}:{QUIC_INTERFACE_PORT}");
}
ResolvedAddr::lookup_host(&host).await
})?;
client::run(rt, assets, server_addr, &args.client, None)
}
Loading

0 comments on commit 2ae01fb

Please sign in to comment.