use titan::{ByteStreamWriter, Payload, Result}; use crate::battle::logic_battle::LogicBattle; use crate::battle::logic_time::LogicTime; use crate::battle::logic_tutorial_manager::LogicTutorialManager; use crate::logic_random::LogicRandom; use crate::model::LogicClientAvatar; pub const SECTION_BATTLE: i32 = 11; pub const SECTION_TUTORIAL: i32 = 12; #[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct LogicGameMode { pub time: LogicTime, pub random: LogicRandom, pub random_seed: i32, pub battle: LogicBattle, pub avatars: Vec, pub tutorial_manager: LogicTutorialManager, } impl LogicGameMode { pub fn snapshot(&self) -> Result> { let mut writer = ByteStreamWriter::new(); self.encode(&mut writer)?; Ok(writer.into_inner()) } } impl LogicGameMode { pub fn write(&self, writer: &mut ByteStreamWriter, with_commands: bool) -> Result { writer.write_vint(self.time.tick); writer.write_checksum_checkpoint(); writer.write_vint(SECTION_BATTLE); self.time.encode(writer)?; self.random.encode(writer)?; writer.write_vint(self.random_seed); self.battle.encode(writer)?; for avatar in &self.avatars { avatar.encode(writer)?; } writer.write_vint(SECTION_TUTORIAL); self.tutorial_manager.encode(writer)?; let checksum = writer.write_checksum_checkpoint(); if with_commands { writer.write_vint(0); } Ok(checksum) } pub fn calculate_checksum(&self) -> Result { let mut writer = ByteStreamWriter::new(); self.write(&mut writer, false) } } impl Payload for LogicGameMode { fn encode(&self, writer: &mut ByteStreamWriter) -> Result<()> { self.write(writer, true)?; Ok(()) } fn decode(_reader: &mut titan::ByteStreamReader<'_>) -> Result { Err(titan::Error::Unsupported("LogicGameMode is encode only")) } }