mirror of
https://codeberg.org/demostf/edit.git
synced 2026-06-03 11:54:07 +02:00
add count_ticks method
This commit is contained in:
parent
4e734f66e8
commit
def9f3da63
3 changed files with 27 additions and 1 deletions
|
|
@ -11,4 +11,9 @@ export interface TickRange {
|
||||||
export async function edit(bytes: Uint8Array, options: EditOptions): Promise<Uint8Array> {
|
export async function edit(bytes: Uint8Array, options: EditOptions): Promise<Uint8Array> {
|
||||||
let m = await import(/* webpackChunkName: "demos-tf-edit" */ "../pkg/index.js");
|
let m = await import(/* webpackChunkName: "demos-tf-edit" */ "../pkg/index.js");
|
||||||
return m.edit_js(bytes, options);
|
return m.edit_js(bytes, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function count_ticks(bytes: Uint8Array): Promise<number> {
|
||||||
|
let m = await import(/* webpackChunkName: "demos-tf-edit" */ "../pkg/index.js");
|
||||||
|
return m.count_ticks(bytes);
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"author": "Robin Appelman <robin@icewind.nl>",
|
"author": "Robin Appelman <robin@icewind.nl>",
|
||||||
"name": "@demostf/edit",
|
"name": "@demostf/edit",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf dist pkg && webpack",
|
"build": "rimraf dist pkg && webpack",
|
||||||
"start": "rimraf dist pkg && webpack-dev-server --open -d",
|
"start": "rimraf dist pkg && webpack-dev-server --open -d",
|
||||||
|
|
|
||||||
21
src/lib.rs
21
src/lib.rs
|
|
@ -14,6 +14,7 @@ use bitbuffer::{BitRead, BitWriteStream, LittleEndian};
|
||||||
use tf_demo_parser::demo::message::packetentities::EntityId;
|
use tf_demo_parser::demo::message::packetentities::EntityId;
|
||||||
|
|
||||||
use bitbuffer::BitWrite;
|
use bitbuffer::BitWrite;
|
||||||
|
use tf_demo_parser::demo::data::DemoTick;
|
||||||
|
|
||||||
use crate::clean::clean_demo;
|
use crate::clean::clean_demo;
|
||||||
use crate::cond::strip_cond;
|
use crate::cond::strip_cond;
|
||||||
|
|
@ -50,6 +51,26 @@ pub fn edit(input: &[u8], options: EditOptions) -> Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn count_ticks(input: &[u8]) -> u32 {
|
||||||
|
let demo = Demo::new(&input);
|
||||||
|
let mut stream = demo.get_stream();
|
||||||
|
let header = Header::read(&mut stream).unwrap();
|
||||||
|
|
||||||
|
let mut tick = DemoTick::default();
|
||||||
|
|
||||||
|
let mut packets = RawPacketStream::new(stream);
|
||||||
|
let mut handler = DemoHandler::default();
|
||||||
|
handler.handle_header(&header);
|
||||||
|
|
||||||
|
while let Some(packet) = packets.next(&handler.state_handler).unwrap() {
|
||||||
|
tick = packet.tick();
|
||||||
|
handler.handle_packet(packet).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
tick.into()
|
||||||
|
}
|
||||||
|
|
||||||
fn no_cut(input: &[u8], options: EditOptions) -> Vec<u8> {
|
fn no_cut(input: &[u8], options: EditOptions) -> Vec<u8> {
|
||||||
let mut out_buffer = Vec::with_capacity(input.len());
|
let mut out_buffer = Vec::with_capacity(input.len());
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue