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

@ -1,3 +1,4 @@
pub mod help; pub mod help;
pub mod index; pub mod index;
pub mod replay;
pub mod submit; 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

@ -50,8 +50,8 @@ function del_line(id) {
function finished() { function finished() {
playing = false; playing = false;
notice('Finished <a href="/+' + json.meta.id + '">' + notice('Finished <a href="/+' + json.id + '">' +
(json.meta.title || json.meta.id) + '</a>', true); (json.title || json.id) + '</a>', true);
document.getElementById("play_pause").className = "icon-play"; document.getElementById("play_pause").className = "icon-play";
} }
@ -85,16 +85,16 @@ function load_log_lines() {
return; 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); ' loaded <a href="#" onclick="return play_pause();">Play</a>', false);
json.log.forEach(function(line) { json.replay.forEach(function(line) {
json.log[line.lineno - 1].lineid = json.replay[line.lineno - 1].lineid =
add_line(line.line, false); add_line(line.text, false);
}); });
document.getElementById("progress").max = json.log.length; document.getElementById("progress").max = json.lines;
document.title = "ReWoT :: " + (json.meta.title || json.meta.id); document.title = "ReWoT :: " + (json.title || json.id);
document.getElementById("play_pause").className = "icon-play"; document.getElementById("play_pause").className = "icon-play";
update_progress(); update_progress();
show_line(ready); show_line(ready);
@ -122,8 +122,8 @@ function play_pause() {
if (pausedid) { if (pausedid) {
del_line(pausedid); del_line(pausedid);
} }
if (lineno > json.log.slice(-1)[0].lineno) { if (lineno > json.replay.slice(-1)[0].lineno) {
lineno = json.log.slice(-1)[0].lineno; lineno = json.replay.slice(-1)[0].lineno;
} else if (lineno < 1) { } else if (lineno < 1) {
lineno = 1; lineno = 1;
} }
@ -136,25 +136,25 @@ function play_pause() {
} }
function replay_log() { function replay_log() {
if (!json.log[lineno] || !playing) { if (!json.replay[lineno] || !playing) {
return; return;
} }
show_line(json.log[lineno].lineid); show_line(json.replay[lineno].lineid);
if (direction == "forward") { if (direction == "forward") {
lineno += 1; lineno += 1;
} else { } else {
hide_line(json.log[lineno].lineid); hide_line(json.replay[lineno].lineid);
lineno -= 1; lineno -= 1;
} }
if (json.log[lineno]) { if (json.replay[lineno]) {
if (fast_forward_lines) { if (fast_forward_lines) {
fast_forward_lines -= 1; fast_forward_lines -= 1;
replay_log(); replay_log();
} else { } else {
var d = parseFloat(json.log[lineno].delta) * speed; var d = parseFloat(json.replay[lineno].delta) * speed;
if (d > 4000) { if (d > 4000) {
d = 4000; d = 4000;
} }
@ -188,13 +188,11 @@ function hide_line(id) {
} }
function update_lineno() { function update_lineno() {
document.getElementById("lineno").innerHTML = json.log[lineno].lineno; document.getElementById("lineno").innerHTML = json.replay[lineno].lineno;
} }
function update_progress() { function update_progress() {
var el = document.getElementById("progress"); var el = document.getElementById("progress");
el.value = json.log[lineno].lineno; el.value = json.replay[lineno].lineno;
el.title = json.log[lineno].lineno + " / " + el.max; 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