fix jump limit

This commit is contained in:
Quaternions 2024-02-16 00:16:50 -08:00
parent 093a54c527
commit 1ca1169697

View File

@ -7,15 +7,17 @@ use crate::updatable::Updatable;
pub struct StageElement{ pub struct StageElement{
stage_id:StageId,//which stage spawn to send to stage_id:StageId,//which stage spawn to send to
force:bool,//allow setting to lower spawn id i.e. 7->3 force:bool,//allow setting to lower spawn id i.e. 7->3
behaviour:StageElementBehaviour behaviour:StageElementBehaviour,
jump_limit:Option<u8>,
} }
impl StageElement{ impl StageElement{
#[inline] #[inline]
pub const fn new(stage_id:StageId,force:bool,behaviour:StageElementBehaviour)->Self{ pub const fn new(stage_id:StageId,force:bool,behaviour:StageElementBehaviour,jump_limit:Option<u8>)->Self{
Self{ Self{
stage_id, stage_id,
force, force,
behaviour, behaviour,
jump_limit,
} }
} }
#[inline] #[inline]
@ -30,6 +32,10 @@ impl StageElement{
pub const fn behaviour(&self)->StageElementBehaviour{ pub const fn behaviour(&self)->StageElementBehaviour{
self.behaviour self.behaviour
} }
#[inline]
pub const fn jump_limit(&self)->Option<u8>{
self.jump_limit
}
} }
#[derive(Clone,Copy,Hash,Eq,PartialEq)] #[derive(Clone,Copy,Hash,Eq,PartialEq)]
@ -128,7 +134,6 @@ pub struct Mode{
stages:Vec<Stage>,//when you load the map you go to stages[0].spawn stages:Vec<Stage>,//when you load the map you go to stages[0].spawn
//mutually exlusive stage element behaviour //mutually exlusive stage element behaviour
elements:HashMap<ModelId,StageElement>, elements:HashMap<ModelId,StageElement>,
jump_limit:HashMap<ModelId,u32>,
} }
impl Mode{ impl Mode{
pub fn new(style:gameplay_style::StyleModifiers,start:ModelId)->Self{ pub fn new(style:gameplay_style::StyleModifiers,start:ModelId)->Self{
@ -138,7 +143,6 @@ impl Mode{
zones:HashMap::new(), zones:HashMap::new(),
stages:Vec::new(), stages:Vec::new(),
elements:HashMap::new(), elements:HashMap::new(),
jump_limit:HashMap::new(),
} }
} }
pub const fn get_start(&self)->ModelId{ pub const fn get_start(&self)->ModelId{
@ -165,9 +169,6 @@ impl Mode{
pub fn get_element(&self,model_id:ModelId)->Option<&StageElement>{ pub fn get_element(&self,model_id:ModelId)->Option<&StageElement>{
self.elements.get(&model_id) self.elements.get(&model_id)
} }
pub fn get_jump_limit(&self,model_id:ModelId)->Option<u32>{
self.jump_limit.get(&model_id).copied()
}
//TODO: put this in the SNF //TODO: put this in the SNF
pub fn denormalize_data(&mut self){ pub fn denormalize_data(&mut self){
//expand and index normalized data //expand and index normalized data
@ -177,12 +178,14 @@ impl Mode{
stage_id:StageId(stage_id as u32), stage_id:StageId(stage_id as u32),
force:false, force:false,
behaviour:StageElementBehaviour::SpawnAt, behaviour:StageElementBehaviour::SpawnAt,
jump_limit:None,
}); });
for (_,&model) in &stage.ordered_checkpoints{ for (_,&model) in &stage.ordered_checkpoints{
self.elements.insert(model,StageElement{ self.elements.insert(model,StageElement{
stage_id:StageId(stage_id as u32), stage_id:StageId(stage_id as u32),
force:false, force:false,
behaviour:StageElementBehaviour::Checkpoint, behaviour:StageElementBehaviour::Checkpoint,
jump_limit:None,
}); });
} }
for &model in &stage.unordered_checkpoints{ for &model in &stage.unordered_checkpoints{
@ -190,6 +193,7 @@ impl Mode{
stage_id:StageId(stage_id as u32), stage_id:StageId(stage_id as u32),
force:false, force:false,
behaviour:StageElementBehaviour::Checkpoint, behaviour:StageElementBehaviour::Checkpoint,
jump_limit:None,
}); });
} }
} }
@ -202,7 +206,6 @@ pub struct ModeUpdate{
stages:HashMap<StageId,StageUpdate>, stages:HashMap<StageId,StageUpdate>,
//mutually exlusive stage element behaviour //mutually exlusive stage element behaviour
elements:HashMap<ModelId,StageElement>, elements:HashMap<ModelId,StageElement>,
jump_limit:HashMap<ModelId,u32>,
} }
impl Updatable<ModeUpdate> for Mode{ impl Updatable<ModeUpdate> for Mode{
fn update(&mut self,update:ModeUpdate){ fn update(&mut self,update:ModeUpdate){
@ -213,7 +216,6 @@ impl Updatable<ModeUpdate> for Mode{
} }
} }
self.elements.extend(update.elements); self.elements.extend(update.elements);
self.jump_limit.extend(update.jump_limit);
} }
} }
impl ModeUpdate{ impl ModeUpdate{
@ -232,11 +234,6 @@ impl ModeUpdate{
mu.elements.insert(model_id,element); mu.elements.insert(model_id,element);
mu mu
} }
pub fn jump_limit(model_id:ModelId,jump_limit:u32)->Self{
let mut mu=Self::default();
mu.jump_limit.insert(model_id,jump_limit);
mu
}
pub fn map_stage_element_ids<F:Fn(StageId)->StageId>(&mut self,f:F){ pub fn map_stage_element_ids<F:Fn(StageId)->StageId>(&mut self,f:F){
for (_,stage_element) in self.elements.iter_mut(){ for (_,stage_element) in self.elements.iter_mut(){
stage_element.stage_id=f(stage_element.stage_id); stage_element.stage_id=f(stage_element.stage_id);