1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-05 02:54:10 +02:00

gamestate analyser wip

This commit is contained in:
Robin Appelman 2019-12-06 18:58:30 +01:00
commit 5f6cfe077e
13 changed files with 379 additions and 9 deletions

View file

@ -11,6 +11,7 @@ use crate::demo::message::stringtable::log_base2;
use crate::demo::packet::datatable::SendTableName;
use crate::demo::parser::MalformedSendPropDefinitionError;
use parse_display::Display;
use serde::export::TryFrom;
use std::convert::TryInto;
use std::fmt;
use std::rc::Rc;
@ -20,6 +21,12 @@ use std::rc::Rc;
)]
pub struct SendPropName(Rc<String>);
impl SendPropName {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl PartialEq<&str> for SendPropName {
fn eq(&self, other: &&str) -> bool {
self.0.as_str() == *other
@ -528,6 +535,66 @@ impl From<Vec<SendPropValue>> for SendPropValue {
}
}
impl TryFrom<&SendPropValue> for i64 {
type Error = ();
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::Integer(val) => Ok(*val),
_ => Err(()),
}
}
}
impl TryFrom<&SendPropValue> for Vector {
type Error = ();
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::Vector(val) => Ok(*val),
_ => Err(()),
}
}
}
impl TryFrom<&SendPropValue> for VectorXY {
type Error = ();
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::VectorXY(val) => Ok(*val),
_ => Err(()),
}
}
}
impl TryFrom<&SendPropValue> for f32 {
type Error = ();
fn try_from(value: &SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::Float(val) => Ok(*val),
_ => Err(()),
}
}
}
impl<'a> TryFrom<&'a SendPropValue> for &'a str {
type Error = ();
fn try_from(value: &'a SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::String(val) => Ok(val.as_str()),
_ => Err(()),
}
}
}
impl<'a> TryFrom<&'a SendPropValue> for &'a [SendPropValue] {
type Error = ();
fn try_from(value: &'a SendPropValue) -> std::result::Result<Self, Self::Error> {
match value {
SendPropValue::Array(val) => Ok(val.as_slice()),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct SendPropDefinitionIndex(u32);