mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
better fallback for player entityid
This commit is contained in:
parent
6367b19473
commit
c3ea161928
3 changed files with 22 additions and 19 deletions
|
|
@ -68,6 +68,7 @@ pub struct UserInfo {
|
||||||
|
|
||||||
impl UserInfo {
|
impl UserInfo {
|
||||||
pub fn parse_from_string_table(
|
pub fn parse_from_string_table(
|
||||||
|
index: u16,
|
||||||
text: Option<&str>,
|
text: Option<&str>,
|
||||||
data: Option<Stream>,
|
data: Option<Stream>,
|
||||||
) -> ReadResult<Option<Self>> {
|
) -> ReadResult<Option<Self>> {
|
||||||
|
|
@ -77,7 +78,7 @@ impl UserInfo {
|
||||||
|
|
||||||
match text
|
match text
|
||||||
.map(|text| text.parse::<u32>().map(|id| (id + 1).into()))
|
.map(|text| text.parse::<u32>().map(|id| (id + 1).into()))
|
||||||
.unwrap_or_else(|| Ok((raw_info.user_id).into()))
|
.unwrap_or_else(|| Ok((index as u32 + 1).into()))
|
||||||
{
|
{
|
||||||
Ok(entity_id) if !raw_info.steam_id.is_empty() => Ok(Some(UserInfo {
|
Ok(entity_id) if !raw_info.steam_id.is_empty() => Ok(Some(UserInfo {
|
||||||
player_info: raw_info.into(),
|
player_info: raw_info.into(),
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ impl Default for Team {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr,
|
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr,
|
||||||
)]
|
)]
|
||||||
#[display(style = "lowercase")]
|
#[display(style = "lowercase")]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
|
|
@ -140,7 +140,7 @@ pub struct ClassList([u8; 10]);
|
||||||
|
|
||||||
impl ClassList {
|
impl ClassList {
|
||||||
/// Get an iterator for all classes played and the number of spawn on the class
|
/// Get an iterator for all classes played and the number of spawn on the class
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (Class, u8)> + '_ {
|
pub fn iter(&self) -> impl Iterator<Item=(Class, u8)> + '_ {
|
||||||
self.0
|
self.0
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
|
|
@ -150,7 +150,7 @@ impl ClassList {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterator for all classes played and the number of spawn on the class, sorted by the number of spawns
|
/// Get an iterator for all classes played and the number of spawn on the class, sorted by the number of spawns
|
||||||
pub fn sorted(&self) -> impl Iterator<Item = (Class, u8)> {
|
pub fn sorted(&self) -> impl Iterator<Item=(Class, u8)> {
|
||||||
let mut classes = self.iter().collect::<Vec<(Class, u8)>>();
|
let mut classes = self.iter().collect::<Vec<(Class, u8)>>();
|
||||||
classes.sort_by(|a, b| a.1.cmp(&b.1).reverse());
|
classes.sort_by(|a, b| a.1.cmp(&b.1).reverse());
|
||||||
classes.into_iter()
|
classes.into_iter()
|
||||||
|
|
@ -213,7 +213,7 @@ impl From<HashMap<Class, u8>> for ClassList {
|
||||||
|
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Clone, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Default,
|
Debug, Clone, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Default,
|
||||||
)]
|
)]
|
||||||
pub struct UserId(pub u8);
|
pub struct UserId(pub u8);
|
||||||
|
|
||||||
|
|
@ -395,12 +395,13 @@ impl MessageHandler for Analyser {
|
||||||
fn handle_string_entry(
|
fn handle_string_entry(
|
||||||
&mut self,
|
&mut self,
|
||||||
table: &str,
|
table: &str,
|
||||||
_index: usize,
|
index: usize,
|
||||||
entry: &StringTableEntry,
|
entry: &StringTableEntry,
|
||||||
_parser_state: &ParserState,
|
_parser_state: &ParserState,
|
||||||
) {
|
) {
|
||||||
if table == "userinfo" {
|
if table == "userinfo" {
|
||||||
let _ = self.parse_user_info(
|
let _ = self.parse_user_info(
|
||||||
|
index,
|
||||||
entry.text.as_ref().map(|s| s.as_ref()),
|
entry.text.as_ref().map(|s| s.as_ref()),
|
||||||
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
||||||
);
|
);
|
||||||
|
|
@ -464,8 +465,8 @@ impl Analyser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_user_info(&mut self, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
fn parse_user_info(&mut self, index: usize, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(text, data)? {
|
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(index as u16, text, data)? {
|
||||||
self.state
|
self.state
|
||||||
.users
|
.users
|
||||||
.entry(user_info.player_info.user_id.into())
|
.entry(user_info.player_info.user_id.into())
|
||||||
|
|
|
||||||
|
|
@ -193,12 +193,13 @@ impl MessageHandler for GameStateAnalyser {
|
||||||
fn handle_string_entry(
|
fn handle_string_entry(
|
||||||
&mut self,
|
&mut self,
|
||||||
table: &str,
|
table: &str,
|
||||||
_index: usize,
|
index: usize,
|
||||||
entry: &StringTableEntry,
|
entry: &StringTableEntry,
|
||||||
_parser_state: &ParserState,
|
_parser_state: &ParserState,
|
||||||
) {
|
) {
|
||||||
if table == "userinfo" {
|
if table == "userinfo" {
|
||||||
let _ = self.parse_user_info(
|
let _ = self.parse_user_info(
|
||||||
|
index,
|
||||||
entry.text.as_ref().map(|s| s.as_ref()),
|
entry.text.as_ref().map(|s| s.as_ref()),
|
||||||
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
||||||
);
|
);
|
||||||
|
|
@ -345,8 +346,8 @@ impl GameStateAnalyser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_user_info(&mut self, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
fn parse_user_info(&mut self, index: usize, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(text, data)? {
|
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(index as u16, text, data)? {
|
||||||
let id = user_info.entity_id;
|
let id = user_info.entity_id;
|
||||||
self.state.get_or_create_player(id).info = Some(user_info.into());
|
self.state.get_or_create_player(id).info = Some(user_info.into());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue