Skip to content

Commit

Permalink
feat(web): use random username
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Sep 22, 2023
1 parent 31d40c2 commit 492c5e5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ toml_edit = { workspace = true }
rpassword = { workspace = true }
sentry = { workspace = true }
sentry-rust-minidump = { workspace = true }
rand = { workspace = true }

[dev-dependencies]
glam = { workspace = true }
Expand Down
57 changes: 1 addition & 56 deletions app/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use ambient_settings::SettingsKey;
use ambient_sys::time::Instant;
use ambient_ui_native::{Dock, WindowSized};
use glam::uvec2;
use rand::seq::SliceRandom;

use crate::{
cli::{GoldenImageCommand, RunCli},
Expand All @@ -49,7 +48,7 @@ pub fn run(
let user_id = match run.user_id.clone().or(settings.general.user_id) {
Some(user_id) => user_id,
None => {
let user_id = random_username();
let user_id = ambient_client_shared::util::random_username();
log::warn!(
"No `user_id` found in settings, using random username: {:?}",
user_id
Expand Down Expand Up @@ -391,57 +390,3 @@ fn systems() -> SystemGroup {
],
)
}

fn random_username() -> String {
const ADJECTIVES: &[&str] = &[
"Quirky",
"Sneaky",
"Witty",
"Curious",
"Grumpy",
"Silly",
"Mischievous",
"Goofy",
"Hasty",
"Awkward",
"Zany",
"Peculiar",
"Whimsical",
"Bumbling",
"Absurd",
"Oddball",
"Clumsy",
"Nutty",
"Haphazard",
"Eccentric",
];

const ANIMALS: &[&str] = &[
"Penguin",
"Platypus",
"Lemur",
"Armadillo",
"Sloth",
"Ostrich",
"Tapir",
"Narwhal",
"Chameleon",
"Aardvark",
"Quokka",
"Wombat",
"Kakapo",
"Capybara",
"Mandrill",
"Axolotl",
"Blobfish",
"Echidna",
"Wallaby",
];

let mut rng = rand::thread_rng();
format!(
"{}{}",
ADJECTIVES.choose(&mut rng).unwrap(),
ANIMALS.choose(&mut rng).unwrap()
)
}
1 change: 1 addition & 0 deletions crates/client_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ambient_debugger = { path = "../debugger/" , version = "0.3.0-dev" }
ambient_ecs_editor = { path = "../ecs_editor/" , version = "0.3.0-dev" }

glam = { workspace = true }
rand = { workspace = true }
1 change: 1 addition & 0 deletions crates/client_shared/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod game_view;
pub mod player;
pub mod util;
56 changes: 56 additions & 0 deletions crates/client_shared/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use rand::seq::SliceRandom;

/// Generates an adjective-animal username.
pub fn random_username() -> String {
const ADJECTIVES: &[&str] = &[
"Quirky",
"Sneaky",
"Witty",
"Curious",
"Grumpy",
"Silly",
"Mischievous",
"Goofy",
"Hasty",
"Awkward",
"Zany",
"Peculiar",
"Whimsical",
"Bumbling",
"Absurd",
"Oddball",
"Clumsy",
"Nutty",
"Haphazard",
"Eccentric",
];

const ANIMALS: &[&str] = &[
"Penguin",
"Platypus",
"Lemur",
"Armadillo",
"Sloth",
"Ostrich",
"Tapir",
"Narwhal",
"Chameleon",
"Aardvark",
"Quokka",
"Wombat",
"Kakapo",
"Capybara",
"Mandrill",
"Axolotl",
"Blobfish",
"Echidna",
"Wallaby",
];

let mut rng = rand::thread_rng();
format!(
"{}{}",
ADJECTIVES.choose(&mut rng).unwrap(),
ANIMALS.choose(&mut rng).unwrap()
)
}
1 change: 1 addition & 0 deletions web/Cargo.lock

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

5 changes: 2 additions & 3 deletions web/client/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use ambient_cameras::UICamera;
use ambient_client_shared::{game_view::GameView, player};
use ambient_ecs::{Entity, SystemGroup};
use ambient_element::{element_component, Element, ElementComponentExt, Hooks};
use ambient_native_std::friendly_id;
use ambient_network::{server::RpcArgs, web::client::GameClientView};
use ambient_rpc::RpcRegistry;
use ambient_ui_native::{cb};
use ambient_ui_native::cb;
use std::collections::HashMap;

#[element_component]
Expand All @@ -15,7 +14,7 @@ pub fn MainApp(_hooks: &mut Hooks, server_url: String) -> Element {

GameClientView {
url: server_url,
user_id: friendly_id(),
user_id: ambient_client_shared::util::random_username(),
systems_and_resources: cb(|| {
let mut resources = Entity::new();

Expand Down

0 comments on commit 492c5e5

Please sign in to comment.