99 lines
5.1 KiB
Rust
99 lines
5.1 KiB
Rust
use super::common::Boolio;
|
|
|
|
#[binrw::binrw]
|
|
#[brw(little)]
|
|
pub enum PhysicsInputInstruction{
|
|
#[brw(magic=0u8)]
|
|
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
|
|
#[brw(magic=1u8)]
|
|
SetNextMouse(super::mouse::MouseState),
|
|
#[brw(magic=2u8)]
|
|
SetMoveRight(Boolio),
|
|
#[brw(magic=3u8)]
|
|
SetMoveUp(Boolio),
|
|
#[brw(magic=4u8)]
|
|
SetMoveBack(Boolio),
|
|
#[brw(magic=5u8)]
|
|
SetMoveLeft(Boolio),
|
|
#[brw(magic=6u8)]
|
|
SetMoveDown(Boolio),
|
|
#[brw(magic=7u8)]
|
|
SetMoveForward(Boolio),
|
|
#[brw(magic=8u8)]
|
|
SetJump(Boolio),
|
|
#[brw(magic=9u8)]
|
|
SetZoom(Boolio),
|
|
#[brw(magic=10u8)]
|
|
Reset,
|
|
#[brw(magic=11u8)]
|
|
Restart,
|
|
#[brw(magic=12u8)]
|
|
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
|
|
#[brw(magic=13u8)]
|
|
PracticeFly,
|
|
#[brw(magic=14u8)]
|
|
SetSensitivity(super::integer::Ratio64Vec2),
|
|
}
|
|
#[derive(Debug)]
|
|
pub enum PhysicsInputInstructionError{
|
|
/// This is an instruction that can be dropped when serializing
|
|
DropInstruction,
|
|
}
|
|
impl std::fmt::Display for PhysicsInputInstructionError{
|
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
write!(f,"{self:?}")
|
|
}
|
|
}
|
|
impl std::error::Error for PhysicsInputInstructionError{}
|
|
impl TryInto<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
|
type Error=super::integer::RatioError;
|
|
fn try_into(self)->Result<strafesnet_common::physics::Instruction,Self::Error>{
|
|
Ok(match self{
|
|
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>strafesnet_common::physics::Instruction::ReplaceMouse(m0.into(),m1.into()),
|
|
PhysicsInputInstruction::SetNextMouse(m)=>strafesnet_common::physics::Instruction::SetNextMouse(m.into()),
|
|
PhysicsInputInstruction::SetMoveRight(state)=>strafesnet_common::physics::Instruction::SetMoveRight(state.into()),
|
|
PhysicsInputInstruction::SetMoveUp(state)=>strafesnet_common::physics::Instruction::SetMoveUp(state.into()),
|
|
PhysicsInputInstruction::SetMoveBack(state)=>strafesnet_common::physics::Instruction::SetMoveBack(state.into()),
|
|
PhysicsInputInstruction::SetMoveLeft(state)=>strafesnet_common::physics::Instruction::SetMoveLeft(state.into()),
|
|
PhysicsInputInstruction::SetMoveDown(state)=>strafesnet_common::physics::Instruction::SetMoveDown(state.into()),
|
|
PhysicsInputInstruction::SetMoveForward(state)=>strafesnet_common::physics::Instruction::SetMoveForward(state.into()),
|
|
PhysicsInputInstruction::SetJump(state)=>strafesnet_common::physics::Instruction::SetJump(state.into()),
|
|
PhysicsInputInstruction::SetZoom(state)=>strafesnet_common::physics::Instruction::SetZoom(state.into()),
|
|
PhysicsInputInstruction::Reset=>strafesnet_common::physics::Instruction::Reset,
|
|
PhysicsInputInstruction::Restart=>strafesnet_common::physics::Instruction::Restart,
|
|
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>strafesnet_common::physics::Instruction::Spawn(
|
|
strafesnet_common::gameplay_modes::ModeId::new(mode_id),
|
|
strafesnet_common::gameplay_modes::StageId::new(stage_id),
|
|
),
|
|
PhysicsInputInstruction::PracticeFly=>strafesnet_common::physics::Instruction::PracticeFly,
|
|
PhysicsInputInstruction::SetSensitivity(sensitivity)=>strafesnet_common::physics::Instruction::SetSensitivity(sensitivity.try_into()?),
|
|
})
|
|
}
|
|
}
|
|
impl TryFrom<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
|
type Error=PhysicsInputInstructionError;
|
|
fn try_from(value:strafesnet_common::physics::Instruction)->Result<Self,Self::Error>{
|
|
match value{
|
|
strafesnet_common::physics::Instruction::ReplaceMouse(m0,m1)=>Ok(PhysicsInputInstruction::ReplaceMouse(m0.into(),m1.into())),
|
|
strafesnet_common::physics::Instruction::SetNextMouse(m)=>Ok(PhysicsInputInstruction::SetNextMouse(m.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveRight(state)=>Ok(PhysicsInputInstruction::SetMoveRight(state.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveUp(state)=>Ok(PhysicsInputInstruction::SetMoveUp(state.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveBack(state)=>Ok(PhysicsInputInstruction::SetMoveBack(state.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveLeft(state)=>Ok(PhysicsInputInstruction::SetMoveLeft(state.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveDown(state)=>Ok(PhysicsInputInstruction::SetMoveDown(state.into())),
|
|
strafesnet_common::physics::Instruction::SetMoveForward(state)=>Ok(PhysicsInputInstruction::SetMoveForward(state.into())),
|
|
strafesnet_common::physics::Instruction::SetJump(state)=>Ok(PhysicsInputInstruction::SetJump(state.into())),
|
|
strafesnet_common::physics::Instruction::SetZoom(state)=>Ok(PhysicsInputInstruction::SetZoom(state.into())),
|
|
strafesnet_common::physics::Instruction::Reset=>Ok(PhysicsInputInstruction::Reset),
|
|
strafesnet_common::physics::Instruction::Restart=>Ok(PhysicsInputInstruction::Restart),
|
|
strafesnet_common::physics::Instruction::Spawn(mode_id,stage_id)=>Ok(PhysicsInputInstruction::Spawn(
|
|
mode_id.get(),
|
|
stage_id.get(),
|
|
)),
|
|
strafesnet_common::physics::Instruction::PracticeFly=>Ok(PhysicsInputInstruction::PracticeFly),
|
|
strafesnet_common::physics::Instruction::SetSensitivity(sensitivity)=>Ok(PhysicsInputInstruction::SetSensitivity(sensitivity.into())),
|
|
strafesnet_common::physics::Instruction::Idle=>Err(PhysicsInputInstructionError::DropInstruction),
|
|
}
|
|
}
|
|
}
|