mirror of
https://github.com/demostf/cutter.git
synced 2026-06-03 11:54:08 +02:00
auto ticks and naming
This commit is contained in:
parent
e08617bcf0
commit
d151938cc8
5 changed files with 43 additions and 18 deletions
|
|
@ -1,13 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Demo cutter</title>
|
||||
<style>
|
||||
input[disabled] {
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
<meta charset="utf-8">
|
||||
<title>Demo cutter</title>
|
||||
<style>
|
||||
input[disabled] {
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
|
||||
|
|
@ -16,19 +16,25 @@
|
|||
|
||||
Cut down a demo file to a specific tick range.
|
||||
|
||||
<p>Set the start and end tick and select a demo file below to begin processing, once processed the file will be presented as download</p>
|
||||
<p>
|
||||
Set the start and end tick, select a demo file and press the cut button to begin processing, once processed the file
|
||||
will be presented as download
|
||||
</p>
|
||||
<p>Processing demo files can take a while</p>
|
||||
<form>
|
||||
<input type="number" id="start" value="30000">
|
||||
<input type="number" id="end" value="50000">
|
||||
<input type="file" id="file">
|
||||
<p>
|
||||
<input type="number" id="start" value="30000">
|
||||
<input type="number" id="end" value="50000">
|
||||
<input type="file" id="file">
|
||||
</p>
|
||||
<p><input type="button" id="cut" value="Cut demo"></p>
|
||||
</form>
|
||||
|
||||
<p>
|
||||
Note:
|
||||
Note:
|
||||
</p>
|
||||
<ul>
|
||||
<li>The resulting demo might not work or crash tf2 on playback, blame valve for making bad code</li>
|
||||
<li>The resulting demo might not work or crash tf2 on playback, blame valve for making bad code</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
23
www/index.js
23
www/index.js
|
|
@ -4,7 +4,11 @@ import {cut} from "democutter";
|
|||
let fileSelect = document.getElementById('file');
|
||||
let startInput = document.getElementById('start');
|
||||
let endInput = document.getElementById('end');
|
||||
fileSelect.addEventListener('change', (event) => {
|
||||
let cutButton = document.getElementById('cut');
|
||||
|
||||
let outputName = "cut.dem";
|
||||
|
||||
cutButton.addEventListener('click', (event) => {
|
||||
let start = parseInt(startInput.value);
|
||||
let end = parseInt(endInput.value);
|
||||
console.log(start, end);
|
||||
|
|
@ -15,10 +19,25 @@ fileSelect.addEventListener('change', (event) => {
|
|||
console.log(reader.result);
|
||||
let result = cut(new Uint8Array(reader.result), start, end);
|
||||
fileSelect.disabled = false;
|
||||
save(result, "cut.dem");
|
||||
save(result, outputName);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
fileSelect.addEventListener('change', (event) => {
|
||||
const tickRate = 66;
|
||||
let name = fileSelect.files[0].name;
|
||||
let match = name.match(/^([^_]+)_(\d+)\.dem$/);
|
||||
if (match) {
|
||||
let highlightTick = parseInt(match[2]);
|
||||
startInput.value = highlightTick - tickRate * 10;
|
||||
endInput.value = highlightTick + tickRate * 5 * 60;
|
||||
outputName = `${match[1]}_${tickRate * 10}.dem`;
|
||||
} else {
|
||||
outputName = name.replace(/\.dem/, "_cut.dem");
|
||||
}
|
||||
});
|
||||
|
||||
function save(data, fileName) {
|
||||
let a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue