give visualizer a facelift
This commit is contained in:
parent
b6fa959f1e
commit
e0a634464e
4 changed files with 156 additions and 46 deletions
|
@ -74,7 +74,7 @@ async fn debug_get() -> Result<Template, String> {
|
||||||
#[get("/visualizer")]
|
#[get("/visualizer")]
|
||||||
async fn visualizer_get() -> Template {
|
async fn visualizer_get() -> Template {
|
||||||
let game_options = get_games().await;
|
let game_options = get_games().await;
|
||||||
let context = Context::new_with("Visualizer", ContextT::Games(game_options));
|
let context = Context::new_with("Visualizer", json!({"games": game_options, "colours": COLOURS}));
|
||||||
Template::render("visualizer", &context)
|
Template::render("visualizer", &context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ static NAV: [(&'static str, &'static str); 5] = [
|
||||||
("/debug", "Debug Station"),
|
("/debug", "Debug Station"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub static COLOURS: [&'static str; 9] = [
|
||||||
|
"gray", "blue", "cyan", "green", "yellow", "orange", "red", "pink", "purple",
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Map {
|
pub struct Map {
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -91,7 +95,9 @@ impl Ord for GameState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FinishedState> for GameState {
|
impl From<FinishedState> for GameState {
|
||||||
fn from(state: FinishedState) -> Self {
|
fn from(mut state: FinishedState) -> Self {
|
||||||
|
state.players.sort_by_key(|x| x.0);
|
||||||
|
|
||||||
GameState::Finished {
|
GameState::Finished {
|
||||||
map: String::new(),
|
map: String::new(),
|
||||||
players: state
|
players: state
|
||||||
|
@ -136,11 +142,11 @@ pub struct Lobby {
|
||||||
pub maps: Vec<Map>,
|
pub maps: Vec<Map>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
// #[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
// #[serde(rename_all = "camelCase")]
|
||||||
pub enum ContextT {
|
// pub enum ContextT {
|
||||||
Games(Vec<GameState>),
|
// Games(Vec<GameState>),
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Context<T> {
|
pub struct Context<T> {
|
||||||
|
@ -213,11 +219,15 @@ pub async fn get_games() -> Vec<GameState> {
|
||||||
match fs::File::open("games.ini").await {
|
match fs::File::open("games.ini").await {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let mut file = BufReader::new(file);
|
let mut file = BufReader::new(file);
|
||||||
file.lines().filter_map(move |maybe| async {
|
file.lines()
|
||||||
maybe
|
.filter_map(move |maybe| async {
|
||||||
.ok()
|
maybe
|
||||||
.and_then(|line| serde_json::from_str::<FinishedState>(&line).ok())
|
.ok()
|
||||||
}).map(|state| state.into()).collect().await
|
.and_then(|line| serde_json::from_str::<FinishedState>(&line).ok())
|
||||||
|
})
|
||||||
|
.map(|state| state.into())
|
||||||
|
.collect()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
Err(_) => Vec::new(),
|
Err(_) => Vec::new(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "base" %}
|
{% extends "base" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/style/visualizer.css">
|
<link rel="stylesheet" type="text/css" href="/style/visualizer.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/style/state.css">
|
<link rel="stylesheet" type="text/css" href="/style/state.css">
|
||||||
|
|
||||||
|
@ -24,20 +25,21 @@
|
||||||
<input type="range" min="0" max="1" value="1" class="slider" id="turnSlider">
|
<input type="range" min="0" max="1" value="1" class="slider" id="turnSlider">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="options">
|
<div class="options">
|
||||||
{% for state in games %}
|
{% for state in games %}
|
||||||
<div class="option" onclick="visualizer.handle('/games/{{ state.file }}', '{{ state.name }}')">
|
<div class="option" onclick="visualizer.handle('/games/{{ state.file }}', '{{ state.name }}')">
|
||||||
<p>{{state.name}} ({{ state.map }}) <span style="float: right;">{{state.turns}} turns</span></p>
|
<p>{{state.name}} ({{ state.map }}) <span style="float: right;">{{state.turns}} turns</span></p>
|
||||||
<div class="content">
|
<div>
|
||||||
<div class="players">
|
<div class="players">
|
||||||
{% for player in state.players %}
|
{% for player in state.players %}
|
||||||
<p class="{% if player[1] %}winner{% endif %}">{{ player[0] }}</p>
|
<p style="color: {{colours[loop.index]}}" class="{% if player[1] %}winner{% endif %}">{{ player[0] }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,11 +16,12 @@ p {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#main {
|
#main {
|
||||||
height: calc(100% - 200px);
|
height: 100%;
|
||||||
width: 100%;
|
flex-grow: 1;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,46 +41,143 @@ p {
|
||||||
}
|
}
|
||||||
|
|
||||||
.options {
|
.options {
|
||||||
background-color: #444;
|
background-color: black;
|
||||||
overflow-y: hidden;
|
max-width: 300px;
|
||||||
overflow-x: scroll;
|
width: 20%;
|
||||||
white-space: nowrap;
|
min-width: 150px;
|
||||||
height: 200px;
|
height: 100%;
|
||||||
min-height: 200px !important;
|
display: flex;
|
||||||
max-height: 200px !important;
|
flex-direction: column;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.option {
|
.option {
|
||||||
display: inline-block;
|
|
||||||
color: white;
|
color: white;
|
||||||
text-align: center;
|
margin: 0 0 20px 0;
|
||||||
width: 200px;
|
padding: 10px;
|
||||||
height: 100%;
|
background-color: grey;
|
||||||
vertical-align: top
|
}
|
||||||
|
|
||||||
|
.option:last-child {
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.option:hover {
|
.option:hover {
|
||||||
background-color: #777;
|
background-color: #777;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading {
|
.lds-roller {
|
||||||
position: relative;
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading>.lds-roller {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading::before {
|
.lds-roller {
|
||||||
content: "";
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100px;
|
|
||||||
height: 100px;
|
|
||||||
background-color: #1c5ba2;
|
|
||||||
border-radius: 100%;
|
|
||||||
z-index: 5;
|
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
-webkit-animation: slide-top 0.5s ease-out infinite alternate;
|
width: 80px;
|
||||||
animation: slide-top 0.5s ease-out infinite alternate;
|
height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div {
|
||||||
|
animation: lds-roller 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
||||||
|
transform-origin: 40px 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:after {
|
||||||
|
content: " ";
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #fff;
|
||||||
|
margin: -4px 0 0 -4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(1) {
|
||||||
|
animation-delay: -0.036s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(1):after {
|
||||||
|
top: 63px;
|
||||||
|
left: 63px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(2) {
|
||||||
|
animation-delay: -0.072s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(2):after {
|
||||||
|
top: 68px;
|
||||||
|
left: 56px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(3) {
|
||||||
|
animation-delay: -0.108s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(3):after {
|
||||||
|
top: 71px;
|
||||||
|
left: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(4) {
|
||||||
|
animation-delay: -0.144s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(4):after {
|
||||||
|
top: 72px;
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(5) {
|
||||||
|
animation-delay: -0.18s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(5):after {
|
||||||
|
top: 71px;
|
||||||
|
left: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(6) {
|
||||||
|
animation-delay: -0.216s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(6):after {
|
||||||
|
top: 68px;
|
||||||
|
left: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(7) {
|
||||||
|
animation-delay: -0.252s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(7):after {
|
||||||
|
top: 63px;
|
||||||
|
left: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(8) {
|
||||||
|
animation-delay: -0.288s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-roller div:nth-child(8):after {
|
||||||
|
top: 56px;
|
||||||
|
left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes lds-roller {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#speed {
|
#speed {
|
||||||
|
@ -226,4 +324,4 @@ p {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
background-color: #F90;
|
background-color: #F90;
|
||||||
background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%, transparent)
|
background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%, transparent)
|
||||||
}
|
}
|
Loading…
Reference in a new issue