From d151938cc85666028bc3741e8b9a5758470c1e79 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 23 Apr 2022 15:56:58 +0200 Subject: [PATCH] auto ticks and naming --- test_data/Kimo_8000_100000_cut.md5 | 2 +- test_data/gully_cut.md5 | 2 +- test_data/icewind_85000_90300_cut.md5 | 2 +- www/index.html | 32 ++++++++++++++++----------- www/index.js | 23 +++++++++++++++++-- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/test_data/Kimo_8000_100000_cut.md5 b/test_data/Kimo_8000_100000_cut.md5 index d741917..852a83b 100644 --- a/test_data/Kimo_8000_100000_cut.md5 +++ b/test_data/Kimo_8000_100000_cut.md5 @@ -1 +1 @@ -4377cdb6395a8fecc6a6ab757a541d87 \ No newline at end of file +d9ca1dea07b67577d3418087152c4e24 \ No newline at end of file diff --git a/test_data/gully_cut.md5 b/test_data/gully_cut.md5 index 5399b0a..f12a4fa 100644 --- a/test_data/gully_cut.md5 +++ b/test_data/gully_cut.md5 @@ -1 +1 @@ -6346c2553bc2c8189eebccf743248bbe \ No newline at end of file +5ef6f0843192808428e9aeb26dddbace \ No newline at end of file diff --git a/test_data/icewind_85000_90300_cut.md5 b/test_data/icewind_85000_90300_cut.md5 index c25c642..e25c9f6 100644 --- a/test_data/icewind_85000_90300_cut.md5 +++ b/test_data/icewind_85000_90300_cut.md5 @@ -1 +1 @@ -810f6572596b4f536d6aa74f09422c81 \ No newline at end of file +b239e76e228dcfde7188c3fc7ce468de \ No newline at end of file diff --git a/www/index.html b/www/index.html index 7921df8..82a3b47 100644 --- a/www/index.html +++ b/www/index.html @@ -1,13 +1,13 @@ - - Demo cutter - + + Demo cutter + @@ -16,19 +16,25 @@ Cut down a demo file to a specific tick range. -

Set the start and end tick and select a demo file below to begin processing, once processed the file will be presented as download

+

+ 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 +

Processing demo files can take a while

- - - +

+ + + +

+

- Note: + Note:

diff --git a/www/index.js b/www/index.js index cb84bf8..e463102 100644 --- a/www/index.js +++ b/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);