Compare commits

..

4 commits

Author SHA1 Message Date
zoe
f77033ef8a remove snippets 2022-01-30 14:21:45 +01:00
zoe
d0317aca7e remove snippets 2022-01-30 14:20:22 +01:00
zoe
c686002dc1 cleanup whitespace in new room requests 2022-01-30 14:18:50 +01:00
zoe
cdf392a232 copy url button 2022-01-30 12:47:53 +01:00
7 changed files with 31 additions and 19 deletions

View file

@ -1 +0,0 @@
<p>Sorry! This room is already full. Maybe try another one?</p>

View file

@ -23,7 +23,7 @@ struct Args {
// Port number for server // Port number for server
#[clap(short, long, default_value_t = 8000)] #[clap(short, long, default_value_t = 8000)]
port: u16, port: u16,
#[clap(short, long, default_value = "localhost")] #[clap(short, long, default_value = "http://127.0.0.1:8000")]
base_url: String, base_url: String,
} }
@ -39,6 +39,8 @@ fn rocket() -> _ {
#[get("/?<roomname>")] #[get("/?<roomname>")]
async fn index(mut roomname: String) -> Template { async fn index(mut roomname: String) -> Template {
// remove whitespace from roomname
roomname = roomname.split_whitespace().collect();
// generate roomname if there is none yet // generate roomname if there is none yet
if roomname.chars().count() == 0 { if roomname.chars().count() == 0 {
roomname = names::get_random_name().await; roomname = names::get_random_name().await;
@ -70,7 +72,7 @@ async fn index(mut roomname: String) -> Template {
} }
} }
#[get("/room?<roomname>&<token>")] #[get("/room?<roomname>&<token>&<player1>")]
async fn room(roomname: &str, token: usize) -> String{ async fn room(roomname: &str, token: usize, player1: bool) -> String{
"hey gamer".to_string() "hey gamer".to_string()
} }

View file

@ -8,10 +8,12 @@ pub struct Room {
impl Room { impl Room {
pub fn new() -> Room { pub fn new() -> Room {
let random: usize = thread_rng().gen(); // generate room token
let tok: usize = thread_rng().gen();
// flip coin to see who starts
Room { Room {
full: false, full: false,
token: random, token: tok,
} }
} }
} }

View file

@ -2,8 +2,6 @@ use std::collections::HashMap;
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
use clap::Parser; use clap::Parser;
lazy_static! { lazy_static! {
static ref ARGS: Args = Args::parse(); static ref ARGS: Args = Args::parse();
} }
@ -11,7 +9,7 @@ lazy_static! {
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(about, version, author)] #[clap(about, version, author)]
struct Args { struct Args {
#[clap(short, long, default_value = "localhost")] #[clap(short, long, default_value = "http://127.0.0.1:8000")]
base_url: String, base_url: String,
} }
@ -21,13 +19,13 @@ pub fn get_back_to_home(roomname: &str) -> Template {
pub fn join_new_room(roomname: &str, token: usize) -> Template { pub fn join_new_room(roomname: &str, token: usize) -> Template {
let message = format!("your room is \"{}\"! copy your link and send it to a friend to let them join", roomname); let message = format!("your room is \"{}\"! copy your link and send it to a friend to let them join", roomname);
let link_url = link_url_from(roomname, token); let link_url = link_url_from(roomname, token, true);
join_template_from(&message, "let me in!", &link_url, "url_button", roomname) join_template_from(&message, "let me in!", &link_url, "url_button", roomname)
} }
pub fn join_room(roomname: &str, token: usize) -> Template { pub fn join_room(roomname: &str, token: usize) -> Template {
let message = format!("your room is \"{}\"! someone is already waiting in this room!", roomname); let message = format!("your room is \"{}\"! someone is already waiting in this room!", roomname);
let link_url = link_url_from(roomname, token); let link_url = link_url_from(roomname, token, false);
join_template_from(&message, "let me in!", &link_url, "hidden", roomname) join_template_from(&message, "let me in!", &link_url, "hidden", roomname)
} }
@ -42,6 +40,6 @@ fn join_template_from(message: &str, link: &str, link_url: &str, hide_url_button
Template::render("join", context) Template::render("join", context)
} }
fn link_url_from(roomname: &str, token: usize) -> String{ fn link_url_from(roomname: &str, token: usize, player1: bool) -> String{
format!("./room?roomname={}&token={}", roomname, token) format!("./room?roomname={}&token={}&player1={}", roomname, token, player1)
} }

View file

@ -2,8 +2,10 @@ function copyURI(evt) {
evt.preventDefault(); evt.preventDefault();
navigator.clipboard.writeText(evt.target.getAttribute('href')).then(() => { navigator.clipboard.writeText(evt.target.getAttribute('href')).then(() => {
/* clipboard successfully set */ /* clipboard successfully set */
document.getElementById("urlForCopy").innerHTML = "copied";
}, () => { }, () => {
/* clipboard write failed */ /* clipboard write failed */
document.getElementById("urlForCopy").innerHTML = "failed to copy :\(";
}); });
} }

View file

@ -7,6 +7,11 @@
--accent1: #accce4; --accent1: #accce4;
} }
* {
margin: 0;
padding: 0;
}
body, body,
html { html {
color: var(--text); color: var(--text);
@ -19,8 +24,10 @@ html {
justify-content: center; justify-content: center;
width: 100%; width: 100%;
height: 100%; height: 100%;
size: 100%;
margin: 0; margin: 0;
padding: 0; padding: 0;
scrollbar-color: var(--accent1);
} }
::selection { ::selection {
@ -45,12 +52,12 @@ footer {
overflow: visible; overflow: visible;
left: 0; left: 0;
display: flex; display: flex;
height: 10%;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
font-size: 3em; font-size: 16pt;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 10%;
} }
.contentdiv { .contentdiv {
@ -58,8 +65,9 @@ footer {
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
align-self: center; align-self: center;
height: 90%; min-height: 90%;
justify-content: center; justify-content: center;
width: 100%;
} }
button, button,
@ -68,8 +76,8 @@ a,
p { p {
line-height: 1.84em; line-height: 1.84em;
border-radius: 0.48em; border-radius: 0.48em;
font-size: 32pt; font-size: 24pt;
margin: 0.5em; margin-top: 0.5em;
text-align: center; text-align: center;
font-family: "Sen", sans-serif; font-family: "Sen", sans-serif;
line-break: anywhere; line-break: anywhere;
@ -79,10 +87,10 @@ a,
button, button,
input { input {
outline: none; outline: none;
padding: 2%;
background-color: var(--background); background-color: var(--background);
color: var(--text); color: var(--text);
border: 0.12em solid var(--text); border: 0.12em solid var(--text);
width: 90%;
} }
input { input {

View file

@ -16,6 +16,7 @@
<div class="contentdiv"> <div class="contentdiv">
<p>{{message}}</p><br /> <p>{{message}}</p><br />
<a <a
title="copy to clipboard"
onclick="copyURI(event)" onclick="copyURI(event)"
id="urlForCopy" id="urlForCopy"
class="{{hide_url_button}}" class="{{hide_url_button}}"