Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
5000d8885e
|
@@ -1,4 +1,4 @@
|
||||
use crate::v0::{Error,File,TimedBlockId};
|
||||
use crate::v0::{Error,File,Timed};
|
||||
|
||||
#[test]
|
||||
fn _1()->Result<(),Error>{
|
||||
@@ -6,14 +6,14 @@ fn _1()->Result<(),Error>{
|
||||
let input=std::io::BufReader::new(file);
|
||||
let mut bot_file=File::new(input).unwrap();
|
||||
println!("header={:?}",bot_file.header);
|
||||
for &TimedBlockId{time,block_id} in &bot_file.header.offline_blocks_timeline{
|
||||
for &Timed{time,event:block_id} in &bot_file.header.offline_blocks_timeline{
|
||||
println!("offline time={} block_id={:?}",time,block_id);
|
||||
let block_info=bot_file.header.block_info(block_id)?;
|
||||
let _block=bot_file.data.read_block_info(block_info)?;
|
||||
// offline blocks include the following event types:
|
||||
// World, Gravity, Run, Camera, Setting
|
||||
}
|
||||
for &TimedBlockId{time,block_id} in &bot_file.header.realtime_blocks_timeline{
|
||||
for &Timed{time,event:block_id} in &bot_file.header.realtime_blocks_timeline{
|
||||
println!("realtime time={} block_id={:?}",time,block_id);
|
||||
let block_info=bot_file.header.block_info(block_id)?;
|
||||
let _block=bot_file.data.read_block_info(block_info)?;
|
||||
|
||||
104
src/v0.rs
104
src/v0.rs
@@ -69,6 +69,20 @@ impl GameControls{
|
||||
}
|
||||
}
|
||||
|
||||
// generic timed event
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug)]
|
||||
pub struct Timed<E>
|
||||
where
|
||||
E:for<'a>binrw::BinRead<Args<'a>=()>,
|
||||
E:for<'a>binrw::BinWrite<Args<'a>=()>,
|
||||
{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:E,
|
||||
}
|
||||
|
||||
// input
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
@@ -78,13 +92,6 @@ pub struct InputEvent{
|
||||
pub game_controls:GameControls,
|
||||
pub mouse_pos:Vector2,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedInputEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:InputEvent,
|
||||
}
|
||||
|
||||
// output
|
||||
bitflags::bitflags!{
|
||||
@@ -119,13 +126,6 @@ pub struct OutputEvent{
|
||||
pub velocity:Vector3,
|
||||
pub acceleration:Vector3,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedOutputEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:OutputEvent,
|
||||
}
|
||||
|
||||
// sound
|
||||
#[binrw]
|
||||
@@ -156,13 +156,6 @@ pub struct SoundEvent{
|
||||
/// Roblox enum
|
||||
pub material:u32,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedSoundEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:SoundEvent,
|
||||
}
|
||||
|
||||
// world
|
||||
#[binrw]
|
||||
@@ -214,13 +207,6 @@ pub enum WorldEvent{
|
||||
#[brw(magic=3u32)]
|
||||
SetPaused(WorldEventSetPaused),
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedWorldEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:WorldEvent,
|
||||
}
|
||||
|
||||
// gravity
|
||||
#[binrw]
|
||||
@@ -228,13 +214,6 @@ pub struct TimedWorldEvent{
|
||||
pub struct GravityEvent{
|
||||
pub gravity:Vector3,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedGravityEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:GravityEvent,
|
||||
}
|
||||
|
||||
// run
|
||||
#[binrw]
|
||||
@@ -305,13 +284,6 @@ pub struct RunEvent{
|
||||
pub mode:Mode,
|
||||
pub flag_reason:FlagReason,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedRunEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:RunEvent,
|
||||
}
|
||||
|
||||
// camera
|
||||
#[binrw]
|
||||
@@ -329,13 +301,6 @@ pub struct CameraEvent{
|
||||
pub camera_event_type:CameraEventType,
|
||||
pub value:Vector3,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedCameraEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:CameraEvent,
|
||||
}
|
||||
|
||||
// setting
|
||||
#[binrw]
|
||||
@@ -360,24 +325,17 @@ pub struct SettingEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub value:f64,
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedSettingEvent{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub event:SettingEvent,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Block{
|
||||
pub input_events:Vec<TimedInputEvent>,
|
||||
pub output_events:Vec<TimedOutputEvent>,
|
||||
pub sound_events:Vec<TimedSoundEvent>,
|
||||
pub world_events:Vec<TimedWorldEvent>,
|
||||
pub gravity_events:Vec<TimedGravityEvent>,
|
||||
pub run_events:Vec<TimedRunEvent>,
|
||||
pub camera_events:Vec<TimedCameraEvent>,
|
||||
pub setting_events:Vec<TimedSettingEvent>,
|
||||
pub input_events:Vec<Timed<InputEvent>>,
|
||||
pub output_events:Vec<Timed<OutputEvent>>,
|
||||
pub sound_events:Vec<Timed<SoundEvent>>,
|
||||
pub world_events:Vec<Timed<WorldEvent>>,
|
||||
pub gravity_events:Vec<Timed<GravityEvent>>,
|
||||
pub run_events:Vec<Timed<RunEvent>>,
|
||||
pub camera_events:Vec<Timed<CameraEvent>>,
|
||||
pub setting_events:Vec<Timed<SettingEvent>>,
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
@@ -488,20 +446,12 @@ pub struct BlockId(#[br(map=|i:u32|i-1)]u32);
|
||||
#[derive(Debug,Clone,Copy)]
|
||||
pub struct BlockPosition(#[br(map=|i:u32|i-1)]u32);
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug,Clone,Copy)]
|
||||
pub struct TimedBlockId{
|
||||
#[br(map=read_trey_double)]
|
||||
pub time:f64,
|
||||
pub block_id:BlockId,
|
||||
}
|
||||
impl PartialEq for TimedBlockId{
|
||||
impl PartialEq for Timed<BlockId>{
|
||||
fn eq(&self,other:&Self)->bool{
|
||||
self.time.eq(&other.time)
|
||||
}
|
||||
}
|
||||
impl PartialOrd for TimedBlockId{
|
||||
impl PartialOrd for Timed<BlockId>{
|
||||
fn partial_cmp(&self,other:&Self)->Option<core::cmp::Ordering>{
|
||||
self.time.partial_cmp(&other.time)
|
||||
}
|
||||
@@ -518,9 +468,9 @@ pub struct FileHeader{
|
||||
#[br(count=num_offline_blocks+num_realtime_blocks+1)]
|
||||
pub block_positions:Vec<BlockPosition>,
|
||||
#[br(count=num_offline_blocks)]
|
||||
pub offline_blocks_timeline:Vec<TimedBlockId>,
|
||||
pub offline_blocks_timeline:Vec<Timed<BlockId>>,
|
||||
#[br(count=num_realtime_blocks)]
|
||||
pub realtime_blocks_timeline:Vec<TimedBlockId>,
|
||||
pub realtime_blocks_timeline:Vec<Timed<BlockId>>,
|
||||
}
|
||||
pub struct BlockInfo{
|
||||
start:u32,
|
||||
@@ -589,7 +539,7 @@ impl<R:BinReaderExt> File<R>{
|
||||
self.header.realtime_blocks_timeline.iter(),
|
||||
);
|
||||
let mut big_block=Block::default();
|
||||
for &TimedBlockId{time:_,block_id} in block_iter{
|
||||
for &Timed{time:_,event:block_id} in block_iter{
|
||||
let block_info=self.header.block_info(block_id)?;
|
||||
self.data.read_block_info_into_block(block_info,&mut big_block)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user