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

Merge pull request #11 from Narcha/userid-use-u16

Change `UserId` to use `u16`
This commit is contained in:
Robin Appelman 2023-01-07 13:45:04 +01:00 committed by GitHub
commit f5002f8cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -216,7 +216,7 @@ impl From<HashMap<Class, u8>> for ClassList {
#[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 u16);
impl<E: Endianness> BitWrite<E> for UserId { impl<E: Endianness> BitWrite<E> for UserId {
fn write(&self, stream: &mut BitWriteStream<E>) -> ReadResult<()> { fn write(&self, stream: &mut BitWriteStream<E>) -> ReadResult<()> {
@ -226,23 +226,23 @@ impl<E: Endianness> BitWrite<E> for UserId {
impl From<u32> for UserId { impl From<u32> for UserId {
fn from(int: u32) -> Self { fn from(int: u32) -> Self {
UserId((int & 255) as u8) UserId(int as u16)
} }
} }
impl From<u16> for UserId { impl From<u16> for UserId {
fn from(int: u16) -> Self { fn from(int: u16) -> Self {
UserId((int & 255) as u8) UserId(int)
} }
} }
impl From<u8> for UserId { impl From<u8> for UserId {
fn from(int: u8) -> Self { fn from(int: u8) -> Self {
UserId(int) UserId(int as u16)
} }
} }
impl From<UserId> for u8 { impl From<UserId> for u16 {
fn from(id: UserId) -> Self { fn from(id: UserId) -> Self {
id.0 id.0
} }
@ -254,8 +254,8 @@ impl From<UserId> for u32 {
} }
} }
impl PartialEq<u8> for UserId { impl PartialEq<u16> for UserId {
fn eq(&self, other: &u8) -> bool { fn eq(&self, other: &u16) -> bool {
self.0 == *other self.0 == *other
} }
} }
@ -296,7 +296,7 @@ impl From<crate::demo::data::UserInfo> for UserInfo {
UserInfo { UserInfo {
classes: ClassList::default(), classes: ClassList::default(),
name: info.player_info.name, name: info.player_info.name,
user_id: info.player_info.user_id.into(), user_id: info.player_info.user_id,
steam_id: info.player_info.steam_id, steam_id: info.player_info.steam_id,
entity_id: info.entity_id, entity_id: info.entity_id,
team: Team::default(), team: Team::default(),

View file

@ -566,7 +566,7 @@ impl GameStateAnalyser {
} }
TARGET => { TARGET => {
sentry.auto_aim_target = sentry.auto_aim_target =
UserId::from(i64::try_from(&prop.value).unwrap_or_default() as u8) UserId::from(i64::try_from(&prop.value).unwrap_or_default() as u16)
} }
SHELLS => { SHELLS => {
sentry.shells = i64::try_from(&prop.value).unwrap_or_default() as u16 sentry.shells = i64::try_from(&prop.value).unwrap_or_default() as u16
@ -676,7 +676,7 @@ impl GameStateAnalyser {
dispenser.healing = values dispenser.healing = values
.iter() .iter()
.map(|val| { .map(|val| {
UserId::from(i64::try_from(val).unwrap_or_default() as u8) UserId::from(i64::try_from(val).unwrap_or_default() as u16)
}) })
.collect() .collect()
} }
@ -761,7 +761,7 @@ impl GameStateAnalyser {
LEVEL => *level = i64::try_from(&prop.value).unwrap_or_default() as u8, LEVEL => *level = i64::try_from(&prop.value).unwrap_or_default() as u8,
BUILDER => { BUILDER => {
*builder = *builder =
UserId::from(i64::try_from(&prop.value).unwrap_or_default() as u8) UserId::from(i64::try_from(&prop.value).unwrap_or_default() as u16)
} }
MAX_HEALTH => { MAX_HEALTH => {
*max_health = i64::try_from(&prop.value).unwrap_or_default() as u16 *max_health = i64::try_from(&prop.value).unwrap_or_default() as u16