the replay stuff so it plays back

master
rascul 2 years ago
parent 96011932f6
commit b969a12595

@ -4,7 +4,7 @@ mod routes;
mod wot_log;
use actix_files::Files;
use actix_web::{middleware, web, App, HttpServer};
use actix_web::{guard, middleware, web, App, HttpResponse, HttpServer};
use handlebars::Handlebars;
use log::info;
@ -13,6 +13,8 @@ use client::Client;
use options::Options;
use wot_log::WotLog;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub fn default_false() -> bool {
false
}
@ -41,9 +43,14 @@ async fn main() -> std::io::Result<()> {
.wrap(middleware::Logger::default())
.service(routes::help::get)
.service(routes::index::get)
//.service(
// web::resource("/r/{id}").name("replay").guard(guard::Get()).to(HttpResponse::Ok),
//)
.service(routes::replay::get)
.service(routes::submit::get)
.service(routes::submit::post)
.service(Files::new("/static", "static").show_files_listing())
.service(Files::new("/replays", "replays"))
})
.bind((options.address, options.port))?
.workers(options.workers)

@ -1,3 +1,4 @@
pub mod help;
pub mod index;
pub mod replay;
pub mod submit;

@ -0,0 +1,36 @@
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::PathBuf;
use actix_web::http::header;
use actix_web::{get, HttpRequest, HttpResponse};
use actix_web::web::{Data, Path};
use handlebars::Handlebars;
use log::info;
use serde_json::json;
use crate::Result;
#[get("/+{id}")]
pub async fn get(req: HttpRequest, id: Path<String>, hb: Data<Handlebars<'_>>) -> Result<HttpResponse> {
println!("HIHIHI");
let mut path = PathBuf::from("replays");
let id: String = id.into_inner();
path.push(&id);
let file: File = File::open(&path)?;
info!("loaded file: {:?}", path);
let mut buffer = BufReader::new(file);
let mut file_contents = String::new();
buffer.read_to_string(&mut file_contents)?;
info!("read to buffer");
let data = json!({
"replayid": id,
});
let body = hb.render("replay", &data).unwrap();
Ok(HttpResponse::Ok().body(body))
}

File diff suppressed because it is too large Load Diff

@ -13,7 +13,7 @@ var timeout = null;
function scroll(el) {
var de = document.documentElement;
if ((el.offsetTop < de.scrollTop) ||
(el.offsetTop + el.offsetHeight > de.scrollTop + de.clientHeight)) {
el.scrollIntoView();
@ -26,12 +26,12 @@ function add_line(line, visible) {
div.id = "replay-div-" + counter;
div.innerHTML = line || "\n";
elmain.appendChild(div);
if (visible) {
div.classList.add("replay-div-visible");
scroll(div);
}
counter += 1;
return counter - 1;
}
@ -50,8 +50,8 @@ function del_line(id) {
function finished() {
playing = false;
notice('Finished <a href="/+' + json.meta.id + '">' +
(json.meta.title || json.meta.id) + '</a>', true);
notice('Finished <a href="/+' + json.id + '">' +
(json.title || json.id) + '</a>', true);
document.getElementById("play_pause").className = "icon-play";
}
@ -79,22 +79,22 @@ function fetch_json(url, callback) {
function load_log_lines() {
json = JSON.parse(this.responseText);
if (!json) {
notice("Loading failed", true);
return;
}
var ready = notice((json.meta.title || json.meta.id) +
var ready = notice((json.title || json.id) +
' loaded <a href="#" onclick="return play_pause();">Play</a>', false);
json.log.forEach(function(line) {
json.log[line.lineno - 1].lineid =
add_line(line.line, false);
json.replay.forEach(function(line) {
json.replay[line.lineno - 1].lineid =
add_line(line.text, false);
});
document.getElementById("progress").max = json.log.length;
document.title = "ReWoT :: " + (json.meta.title || json.meta.id);
document.getElementById("progress").max = json.lines;
document.title = "ReWoT :: " + (json.title || json.id);
document.getElementById("play_pause").className = "icon-play";
update_progress();
show_line(ready);
@ -107,7 +107,7 @@ function load_log(url) {
function play_pause() {
var el = document.getElementById("play_pause");
if (playing) {
if (timeout) {
window.clearTimeout(timeout);
@ -122,8 +122,8 @@ function play_pause() {
if (pausedid) {
del_line(pausedid);
}
if (lineno > json.log.slice(-1)[0].lineno) {
lineno = json.log.slice(-1)[0].lineno;
if (lineno > json.replay.slice(-1)[0].lineno) {
lineno = json.replay.slice(-1)[0].lineno;
} else if (lineno < 1) {
lineno = 1;
}
@ -136,25 +136,25 @@ function play_pause() {
}
function replay_log() {
if (!json.log[lineno] || !playing) {
if (!json.replay[lineno] || !playing) {
return;
}
show_line(json.log[lineno].lineid);
show_line(json.replay[lineno].lineid);
if (direction == "forward") {
lineno += 1;
} else {
hide_line(json.log[lineno].lineid);
hide_line(json.replay[lineno].lineid);
lineno -= 1;
}
if (json.log[lineno]) {
if (json.replay[lineno]) {
if (fast_forward_lines) {
fast_forward_lines -= 1;
replay_log();
} else {
var d = parseFloat(json.log[lineno].delta) * speed;
var d = parseFloat(json.replay[lineno].delta) * speed;
if (d > 4000) {
d = 4000;
}
@ -188,13 +188,11 @@ function hide_line(id) {
}
function update_lineno() {
document.getElementById("lineno").innerHTML = json.log[lineno].lineno;
document.getElementById("lineno").innerHTML = json.replay[lineno].lineno;
}
function update_progress() {
var el = document.getElementById("progress");
el.value = json.log[lineno].lineno;
el.title = json.log[lineno].lineno + " / " + el.max;
el.value = json.replay[lineno].lineno;
el.title = json.replay[lineno].lineno + " / " + el.max;
}

@ -0,0 +1,81 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ReWoT</title>
<link rel="stylesheet" href="/static/rewot.css" type="text/css">
<link rel="stylesheet" href="/static/ansi2html.css" type="text/css">
<link rel="stylesheet" href="/static/fontello/css/fontello.css" type="text/css">
</head>
<body>
<div class="top">
<h1><a href="/">ReWoT</a></h1>
<ul>
<li><a href="/latest">latest</a></li>
<li><a href="/submit">submit</a></li>
<li><a href="/help">help</a></li>
</ul>
</div>
<div class="bottom">
<table>
<tr>
<td></td>
<td>
<a href="#" onclick="return speed_up();">
<i class="icon-plus" title="Speed up"></i>
</a>
</td>
<td></td>
</tr>
<tr>
<td>
<a href="#" onclick="return reverse();">
<i class="icon-fast-backward" title="Rewind"></i>
</a>
</td>
<td>
<a href="#" onclick="return play_pause();">
<i id="play_pause" class="icon-play" title="Play"></i>
</a>
</td>
<td>
<a href="#" onclick="return forward();">
<i class="icon-fast-forward" title="Fast forward"></i>
</a>
</td>
</tr>
<tr>
<td></td>
<td>
<a href="#" onclick="return slow_down();">
<i class="icon-minus" title="Slow down"></i>
</a>
</td>
<td>
<small>x</small><span id="speed" title="Speed">1</span>
</td>
</tr>
<tr>
<td>
<span style="font-size: x-large;" title="Line number">#</span><span id="lineno" title="Line number"></span>
</td>
<td colspan=2>
<progress id="progress" max="0" value="0"></progress>
</td>
</tr>
</table>
</div>
<main id="main">
</main>
<script src="/static/rewot.js"></script>
<script>load_log("/replays/{{ replayid }}");</script>
</body>
</html>
Loading…
Cancel
Save