mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
game event list
This commit is contained in:
parent
722afaeffa
commit
abe9418a3b
2 changed files with 56 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use bitstream_reader::{BitRead};
|
||||||
|
|
||||||
use crate::{ParseError, Result};
|
use crate::{ParseError, Result};
|
||||||
|
|
||||||
|
|
@ -17,15 +18,17 @@ pub struct GameEventEntry {
|
||||||
pub kind: GameEventValueType,
|
pub kind: GameEventValueType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(BitRead, Debug, Clone, Copy, PartialEq)]
|
||||||
|
#[discriminant_bits = 3]
|
||||||
pub enum GameEventValueType {
|
pub enum GameEventValueType {
|
||||||
String,
|
None = 0,
|
||||||
Float,
|
String = 1,
|
||||||
Long,
|
Float = 2,
|
||||||
Short,
|
Long = 3,
|
||||||
Byte,
|
Short = 4,
|
||||||
Boolean,
|
Byte = 5,
|
||||||
Local,
|
Boolean = 6,
|
||||||
|
Local = 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
use bitstream_reader::{BitRead, BitReadSized, LittleEndian};
|
use bitstream_reader::{BitRead, BitReadSized, LittleEndian};
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ fn read_event_value(stream: &mut Stream, definition: &GameEventEntry) -> Result<
|
||||||
GameEventValueType::Byte => GameEventValue::Byte(stream.read()?),
|
GameEventValueType::Byte => GameEventValue::Byte(stream.read()?),
|
||||||
GameEventValueType::Boolean => GameEventValue::Boolean(stream.read()?),
|
GameEventValueType::Boolean => GameEventValue::Boolean(stream.read()?),
|
||||||
GameEventValueType::Local => GameEventValue::Local,
|
GameEventValueType::Local => GameEventValue::Local,
|
||||||
|
GameEventValueType::None => unreachable!()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,4 +48,47 @@ impl Parse for GameEventMessage {
|
||||||
event
|
event
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GameEventListMessage {
|
||||||
|
event_list: HashMap<GameEventType, GameEventDefinition>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitRead<LittleEndian> for GameEventDefinition {
|
||||||
|
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||||
|
let event_type = stream.read()?;
|
||||||
|
let name = stream.read()?;
|
||||||
|
let mut entries = Vec::new();
|
||||||
|
|
||||||
|
let mut entry_type = stream.read()?;
|
||||||
|
while entry_type != GameEventValueType::None {
|
||||||
|
let entry_name = stream.read()?;
|
||||||
|
entries.push(GameEventEntry {
|
||||||
|
name: entry_name,
|
||||||
|
kind: entry_type,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(GameEventDefinition {
|
||||||
|
id: event_type,
|
||||||
|
name,
|
||||||
|
entries,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitRead<LittleEndian> for GameEventListMessage {
|
||||||
|
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||||
|
let count: u16 = stream.read_sized(9)?;
|
||||||
|
let length: u16 = stream.read_sized(20)?;
|
||||||
|
let data = stream.read_bits(length as usize)?;
|
||||||
|
let event_list_vec: Vec<GameEventDefinition> = stream.read_sized(count as usize)?;
|
||||||
|
let event_list = HashMap::from_iter(
|
||||||
|
event_list_vec.into_iter().map(|def| (def.id, def))
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(GameEventListMessage {
|
||||||
|
event_list
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue