mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
derive Display where possible
This commit is contained in:
parent
88d2a05d62
commit
66668e3e61
7 changed files with 47 additions and 91 deletions
|
|
@ -4,6 +4,7 @@ use crate::{MalformedDemoError, ParseError, Result};
|
|||
|
||||
pub use super::gameevent_gen::{GameEvent, GameEventType};
|
||||
use crate::demo::message::gameevent::GameEventTypeId;
|
||||
use parse_display::Display;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ pub struct GameEventEntry {
|
|||
pub kind: GameEventValueType,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(BitRead, Debug, Clone, Copy, PartialEq, Display)]
|
||||
#[discriminant_bits = 3]
|
||||
pub enum GameEventValueType {
|
||||
None = 0,
|
||||
|
|
@ -54,21 +55,6 @@ pub enum GameEventValueType {
|
|||
Local = 7,
|
||||
}
|
||||
|
||||
impl fmt::Display for GameEventValueType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
GameEventValueType::None => write!(f, "None"),
|
||||
GameEventValueType::String => write!(f, "String"),
|
||||
GameEventValueType::Float => write!(f, "Float"),
|
||||
GameEventValueType::Long => write!(f, "Long"),
|
||||
GameEventValueType::Short => write!(f, "Short"),
|
||||
GameEventValueType::Byte => write!(f, "Byte"),
|
||||
GameEventValueType::Boolean => write!(f, "Boolean"),
|
||||
GameEventValueType::Local => write!(f, "Local"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum GameEventValue {
|
||||
String(String),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::demo::packet::datatable::{SendTable, SendTableName, ServerClass};
|
|||
use crate::demo::parser::ParseBitSkip;
|
||||
use crate::demo::sendprop::{SendProp, SendPropDefinition, SendPropValue};
|
||||
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||
use parse_display::Display;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::hint::unreachable_unchecked;
|
||||
|
|
@ -13,15 +14,9 @@ use std::num::ParseIntError;
|
|||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Display)]
|
||||
pub struct EntityId(u32);
|
||||
|
||||
impl fmt::Display for EntityId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for EntityId {
|
||||
fn from(num: u32) -> Self {
|
||||
EntityId(num)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use bitstream_reader::{BitRead, LittleEndian};
|
|||
use crate::demo::parser::MalformedSendPropDefinitionError;
|
||||
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropName, SendPropType};
|
||||
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||
use parse_display::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
|
@ -36,21 +37,9 @@ pub struct ServerClass {
|
|||
pub data_table: SendTableName,
|
||||
}
|
||||
|
||||
#[derive(BitRead, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
|
||||
#[derive(BitRead, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, Clone, Display)]
|
||||
pub struct SendTableName(Rc<String>);
|
||||
|
||||
impl Clone for SendTableName {
|
||||
fn clone(&self) -> Self {
|
||||
SendTableName(Rc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SendTableName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for SendTableName {
|
||||
fn from(value: String) -> Self {
|
||||
Self(Rc::new(value))
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ use super::vector::{Vector, VectorXY};
|
|||
use crate::demo::message::stringtable::log_base2;
|
||||
use crate::demo::packet::datatable::SendTableName;
|
||||
use crate::demo::parser::MalformedSendPropDefinitionError;
|
||||
use parse_display::Display;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(BitRead, PartialEq, Eq, Hash, Debug)]
|
||||
#[derive(BitRead, PartialEq, Eq, Hash, Debug, Display, Clone)]
|
||||
pub struct SendPropName(Rc<String>);
|
||||
|
||||
impl PartialEq<&str> for SendPropName {
|
||||
|
|
@ -22,18 +23,6 @@ impl PartialEq<&str> for SendPropName {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for SendPropName {
|
||||
fn clone(&self) -> Self {
|
||||
SendPropName(Rc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SendPropName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for SendPropName {
|
||||
fn from(value: String) -> Self {
|
||||
Self(Rc::new(value))
|
||||
|
|
@ -213,7 +202,7 @@ impl SendPropDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(BitRead, Copy, Clone, PartialEq, Debug, Display)]
|
||||
#[discriminant_bits = 5]
|
||||
pub enum SendPropType {
|
||||
Int = 0,
|
||||
|
|
@ -226,21 +215,6 @@ pub enum SendPropType {
|
|||
NumSendPropTypes = 7,
|
||||
}
|
||||
|
||||
impl fmt::Display for SendPropType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
SendPropType::Int => write!(f, "Int"),
|
||||
SendPropType::Float => write!(f, "Float"),
|
||||
SendPropType::Vector => write!(f, "Vector"),
|
||||
SendPropType::VectorXY => write!(f, "VectorXY"),
|
||||
SendPropType::String => write!(f, "String"),
|
||||
SendPropType::Array => write!(f, "Array"),
|
||||
SendPropType::DataTable => write!(f, "DataTable"),
|
||||
SendPropType::NumSendPropTypes => write!(f, "NumSendPropTypes"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(EnumFlags, Copy, Clone, PartialEq, Debug)]
|
||||
#[repr(u16)]
|
||||
pub enum SendPropFlag {
|
||||
|
|
@ -486,22 +460,13 @@ impl From<Vec<SendPropValue>> for SendPropValue {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Display)]
|
||||
#[display("{definition.owner_table}::{definition.name} = {value}")]
|
||||
pub struct SendProp {
|
||||
pub definition: Rc<SendPropDefinition>,
|
||||
pub value: SendPropValue,
|
||||
}
|
||||
|
||||
impl fmt::Display for SendProp {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}::{} = {}",
|
||||
self.definition.owner_table, self.definition.name, self.value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_var_int(stream: &mut Stream, signed: bool) -> ReadResult<i32> {
|
||||
let mut result: i32 = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,22 @@
|
|||
use bitstream_reader::{BitRead, BitSize};
|
||||
use parse_display::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(BitRead, BitSize, Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(
|
||||
BitRead, BitSize, Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Display,
|
||||
)]
|
||||
#[display("({x}, {y}, {z})")]
|
||||
pub struct Vector {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
impl fmt::Display for Vector {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "({}, {}, {})", self.x, self.y, self.z)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitSize, Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(
|
||||
BitRead, BitSize, Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Display,
|
||||
)]
|
||||
#[display("({x}, {y})")]
|
||||
pub struct VectorXY {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
}
|
||||
|
||||
impl fmt::Display for VectorXY {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue