Compare commits
6 Commits
md-compare
...
strafe-sta
| Author | SHA1 | Date | |
|---|---|---|---|
|
eb40c1a0d0
|
|||
|
6ca6d5e484
|
|||
|
0668ac2def
|
|||
|
73e3181d0c
|
|||
|
19ba8f2445
|
|||
|
0495d07e26
|
644
Cargo.lock
generated
644
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -91,6 +91,7 @@ pub trait MeshQuery{
|
||||
(self.vert(v1)-self.vert(v0))*((directed_edge_id.parity() as i64)*2-1)
|
||||
}
|
||||
/// This must return a point inside the mesh.
|
||||
#[expect(dead_code)]
|
||||
fn hint_point(&self)->Planar64Vec3;
|
||||
fn vert(&self,vert_id:Self::Vert)->Planar64Vec3;
|
||||
fn face_nd(&self,face_id:Self::Face)->(Self::Normal,Self::Offset);
|
||||
|
||||
@@ -488,8 +488,21 @@ impl StyleHelper for StyleModifiers{
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Debug)]
|
||||
struct StrafeTickState{
|
||||
tick_number:u64,
|
||||
}
|
||||
impl StrafeTickState{
|
||||
fn next_tick(&self,settings:&gameplay_style::StrafeSettings)->Time{
|
||||
let n=self.tick_number as i128;
|
||||
let ticks=settings.tick_rate.num() as i128;
|
||||
let seconds=settings.tick_rate.den() as i128;
|
||||
let time=n*seconds/ticks;
|
||||
Time::from_nanos(time as i64)
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Debug)]
|
||||
enum MoveState{
|
||||
Air,
|
||||
Air(StrafeTickState),
|
||||
Walk(ContactMoveState),
|
||||
Ladder(ContactMoveState),
|
||||
#[expect(dead_code)]
|
||||
@@ -497,11 +510,21 @@ enum MoveState{
|
||||
Fly,
|
||||
}
|
||||
impl MoveState{
|
||||
fn air(time:Time,settings:Option<&gameplay_style::StrafeSettings>)->Self{
|
||||
let tick_number=if let Some(settings)=settings{
|
||||
// let time=n*seconds/ticks;
|
||||
let time=time.nanos() as i128;
|
||||
let ticks=settings.tick_rate.num() as i128;
|
||||
let seconds=settings.tick_rate.den() as i128;
|
||||
(time*ticks/seconds) as u64
|
||||
}else{0};
|
||||
MoveState::Air(StrafeTickState{tick_number})
|
||||
}
|
||||
//call this after state.move_state is changed
|
||||
fn apply_enum(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
match self{
|
||||
MoveState::Fly=>body.acceleration=vec3::zero(),
|
||||
MoveState::Air=>{
|
||||
MoveState::Air(_)=>{
|
||||
//calculate base acceleration
|
||||
let a=touching.base_acceleration(models,style,camera,input_state);
|
||||
//set_acceleration clips according to contacts
|
||||
@@ -513,7 +536,7 @@ impl MoveState{
|
||||
//function to coerce &mut self into &self
|
||||
fn apply_to_body(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
match self{
|
||||
MoveState::Air=>(),
|
||||
MoveState::Air(_)=>(),
|
||||
MoveState::Water=>(),
|
||||
MoveState::Fly=>{
|
||||
//set velocity according to current control state
|
||||
@@ -534,7 +557,7 @@ impl MoveState{
|
||||
fn apply_input(&mut self,body:&Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
match self{
|
||||
MoveState::Fly
|
||||
|MoveState::Air
|
||||
|MoveState::Air(_)
|
||||
|MoveState::Water=>(),
|
||||
MoveState::Walk(ContactMoveState{target,contact,jump_direction:_})=>{
|
||||
if let Some(walk_settings)=&style.walk{
|
||||
@@ -559,13 +582,13 @@ impl MoveState{
|
||||
MoveState::Walk(walk_state)
|
||||
|MoveState::Ladder(walk_state)
|
||||
=>Some(walk_state),
|
||||
MoveState::Air
|
||||
MoveState::Air(_)
|
||||
|MoveState::Water
|
||||
|MoveState::Fly
|
||||
=>None,
|
||||
}
|
||||
}
|
||||
fn next_move_instruction(&self,strafe:&Option<gameplay_style::StrafeSettings>,time:Time)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
fn next_move_instruction(&self,strafe:Option<&gameplay_style::StrafeSettings>)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
//check if you have a valid walk state and create an instruction
|
||||
match self{
|
||||
MoveState::Walk(walk_state)|MoveState::Ladder(walk_state)=>match &walk_state.target{
|
||||
@@ -577,9 +600,9 @@ impl MoveState{
|
||||
|TransientAcceleration::Reached
|
||||
=>None,
|
||||
}
|
||||
MoveState::Air=>strafe.as_ref().map(|strafe|{
|
||||
MoveState::Air(strafe_tick_state)=>strafe.as_ref().map(|strafe|{
|
||||
TimedInstruction{
|
||||
time:strafe.next_tick(time),
|
||||
time:strafe_tick_state.next_tick(strafe),
|
||||
//only poll the physics if there is a before and after mouse event
|
||||
instruction:InternalInstruction::StrafeTick
|
||||
}
|
||||
@@ -607,7 +630,7 @@ impl MoveState{
|
||||
//this function call reads the above state that was just set
|
||||
self.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}
|
||||
fn cull_velocity(&mut self,velocity:Planar64Vec3,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
fn cull_velocity(&mut self,velocity:Planar64Vec3,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState,time:Time){
|
||||
//TODO: be more precise about contacts
|
||||
if set_velocity_cull(body,touching,models,hitbox_mesh,velocity){
|
||||
// TODO do better
|
||||
@@ -615,7 +638,7 @@ impl MoveState{
|
||||
match self.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if !touching.contains_contact(&walk_state.contact.convex_mesh_id){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
self.set_move_state(MoveState::air(time,style.strafe.as_ref()),body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
@@ -890,7 +913,7 @@ impl Default for PhysicsState{
|
||||
time:Time::ZERO,
|
||||
style:StyleModifiers::default(),
|
||||
touching:TouchingState::default(),
|
||||
move_state:MoveState::Air,
|
||||
move_state:MoveState::air(Time::ZERO,None),
|
||||
camera:PhysicsCamera::default(),
|
||||
input_state:InputState::default(),
|
||||
_world:WorldState{},
|
||||
@@ -935,10 +958,10 @@ impl PhysicsState{
|
||||
*self=Self::default();
|
||||
}
|
||||
fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
self.move_state.next_move_instruction(&self.style.strafe,self.time)
|
||||
self.move_state.next_move_instruction(self.style.strafe.as_ref())
|
||||
}
|
||||
fn cull_velocity(&mut self,data:&PhysicsData,velocity:Planar64Vec3){
|
||||
self.move_state.cull_velocity(velocity,&mut self.body,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
||||
fn cull_velocity(&mut self,data:&PhysicsData,velocity:Planar64Vec3,time:Time){
|
||||
self.move_state.cull_velocity(velocity,&mut self.body,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state,time);
|
||||
}
|
||||
fn set_move_state(&mut self,data:&PhysicsData,move_state:MoveState){
|
||||
self.move_state.set_move_state(move_state,&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
||||
@@ -1262,7 +1285,7 @@ fn recalculate_touching(
|
||||
//I would have preferred while let Some(contact)=contacts.pop()
|
||||
//but there is no such method
|
||||
while let Some((&convex_mesh_id,_face_id))=touching.contacts.iter().next(){
|
||||
collision_end_contact(move_state,body,touching,models,hitbox_mesh,style,camera,input_state,models.contact_attr(convex_mesh_id.model_id),&convex_mesh_id)
|
||||
collision_end_contact(move_state,body,touching,models,hitbox_mesh,style,camera,input_state,models.contact_attr(convex_mesh_id.model_id),&convex_mesh_id,time)
|
||||
}
|
||||
while let Some(&convex_mesh_id)=touching.intersects.iter().next(){
|
||||
collision_end_intersect(move_state,body,touching,models,hitbox_mesh,style,camera,input_state,mode,run,models.intersect_attr(convex_mesh_id.model_id),&convex_mesh_id,time);
|
||||
@@ -1598,7 +1621,7 @@ fn collision_start_contact(
|
||||
gameplay_attributes::SetTrajectory::TargetPointTime{..}=>todo!(),
|
||||
gameplay_attributes::SetTrajectory::TargetPointSpeed{..}=>todo!(),
|
||||
&gameplay_attributes::SetTrajectory::Velocity(velocity)=>{
|
||||
move_state.cull_velocity(velocity,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.cull_velocity(velocity,body,touching,models,hitbox_mesh,style,camera,input_state,time);
|
||||
},
|
||||
gameplay_attributes::SetTrajectory::DotVelocity{..}=>todo!(),
|
||||
}
|
||||
@@ -1628,7 +1651,7 @@ fn collision_start_contact(
|
||||
}else{
|
||||
let jump_dir=walk_state.jump_direction.direction(models,hitbox_mesh,&walk_state.contact);
|
||||
let jumped_velocity=jump_settings.jumped_velocity(style,jump_dir,body.velocity,attr.general.booster.as_ref());
|
||||
move_state.cull_velocity(jumped_velocity,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.cull_velocity(jumped_velocity,body,touching,models,hitbox_mesh,style,camera,input_state,time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1658,7 +1681,7 @@ fn collision_start_intersect(
|
||||
touching.insert_intersect(intersect);
|
||||
//insta booster!
|
||||
if let Some(booster)=&attr.general.booster{
|
||||
move_state.cull_velocity(booster.boost(body.velocity),body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.cull_velocity(booster.boost(body.velocity),body,touching,models,hitbox_mesh,style,camera,input_state,time);
|
||||
}
|
||||
if let Some(mode)=mode{
|
||||
let zone=mode.get_zone(intersect.convex_mesh_id.model_id.into());
|
||||
@@ -1692,6 +1715,7 @@ fn collision_end_contact(
|
||||
input_state:&InputState,
|
||||
_attr:&gameplay_attributes::ContactAttributes,
|
||||
convex_mesh_id:&ConvexMeshId<ContactModelId>,
|
||||
time:Time,
|
||||
){
|
||||
touching.remove_contact(convex_mesh_id);//remove contact before calling contact_constrain_acceleration
|
||||
//check ground
|
||||
@@ -1702,7 +1726,7 @@ fn collision_end_contact(
|
||||
// This does not check the face! Is that a bad thing? It should be
|
||||
// impossible to stop touching a different face than you started touching...
|
||||
Some(walk_state)=>if &walk_state.contact.convex_mesh_id==convex_mesh_id{
|
||||
move_state.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.set_move_state(MoveState::air(time,style.strafe.as_ref()),body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
move_state.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
@@ -1781,7 +1805,8 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
Collision::Contact(contact)=>collision_end_contact(
|
||||
&mut state.move_state,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state,
|
||||
data.models.contact_attr(contact.convex_mesh_id.model_id),
|
||||
&contact.convex_mesh_id
|
||||
&contact.convex_mesh_id,
|
||||
state.time,
|
||||
),
|
||||
Collision::Intersect(intersect)=>collision_end_intersect(
|
||||
&mut state.move_state,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state,
|
||||
@@ -1793,6 +1818,11 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
),
|
||||
},
|
||||
InternalInstruction::StrafeTick=>{
|
||||
let strafe_tick_state=match &mut state.move_state{
|
||||
MoveState::Air(strafe_tick_state)=>strafe_tick_state,
|
||||
_=>panic!("StrafeTick fired for non-air MoveState"),
|
||||
};
|
||||
strafe_tick_state.tick_number+=1;
|
||||
//TODO make this less huge
|
||||
if let Some(strafe_settings)=&state.style.strafe{
|
||||
let controls=state.input_state.controls;
|
||||
@@ -1804,7 +1834,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
if let Some(ticked_velocity)=strafe_settings.tick_velocity(state.body.velocity,(camera_mat*control_dir).with_length(Planar64::ONE).divide().wrap_1()){
|
||||
//this is wrong but will work ig
|
||||
//need to note which push planes activate in push solve and keep those
|
||||
state.cull_velocity(data,ticked_velocity);
|
||||
state.cull_velocity(data,ticked_velocity,state.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1812,7 +1842,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
}
|
||||
InternalInstruction::ReachWalkTargetVelocity=>{
|
||||
match &mut state.move_state{
|
||||
MoveState::Air
|
||||
MoveState::Air(_)
|
||||
|MoveState::Water
|
||||
|MoveState::Fly
|
||||
=>println!("ReachWalkTargetVelocity fired for non-walking MoveState"),
|
||||
@@ -1854,7 +1884,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
|MoveState::Water
|
||||
|MoveState::Walk(_)
|
||||
|MoveState::Ladder(_)=>true,
|
||||
MoveState::Air=>false,
|
||||
MoveState::Air(_)=>false,
|
||||
}
|
||||
},
|
||||
//the body must be updated unconditionally
|
||||
@@ -1888,7 +1918,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact);
|
||||
let booster_option=data.models.contact_attr(walk_state.contact.convex_mesh_id.model_id).general.booster.as_ref();
|
||||
let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option);
|
||||
state.cull_velocity(data,jumped_velocity);
|
||||
state.cull_velocity(data,jumped_velocity,state.time);
|
||||
}
|
||||
}
|
||||
b_refresh_walk_target=false;
|
||||
@@ -1918,7 +1948,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
}
|
||||
set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time);
|
||||
set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,vec3::zero());
|
||||
state.set_move_state(data,MoveState::Air);
|
||||
state.set_move_state(data,MoveState::air(state.time,state.style.strafe.as_ref()));
|
||||
b_refresh_walk_target=false;
|
||||
}
|
||||
// Spawn does not necessarily imply reset
|
||||
@@ -1942,7 +1972,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
Instruction::Misc(MiscInstruction::PracticeFly)=>{
|
||||
match &state.move_state{
|
||||
MoveState::Fly=>{
|
||||
state.set_move_state(data,MoveState::Air);
|
||||
state.set_move_state(data,MoveState::air(state.time,state.style.strafe.as_ref()));
|
||||
},
|
||||
_=>{
|
||||
state.set_move_state(data,MoveState::Fly);
|
||||
@@ -1957,7 +1987,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
}
|
||||
if b_refresh_walk_target{
|
||||
state.apply_input_and_body(data);
|
||||
state.cull_velocity(data,state.body.velocity);
|
||||
state.cull_velocity(data,state.body.velocity,state.time);
|
||||
//also check if accelerating away from surface
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16
|
||||
|
||||
use crate::integer::{int,vec3::int as int3,AbsoluteTime,Ratio64,Planar64,Planar64Vec3};
|
||||
use crate::controls_bitflag::Controls;
|
||||
use crate::physics::Time as PhysicsTime;
|
||||
|
||||
#[derive(Clone,Debug)]
|
||||
pub struct StyleModifiers{
|
||||
@@ -273,9 +272,6 @@ impl StrafeSettings{
|
||||
false=>None,
|
||||
}
|
||||
}
|
||||
pub fn next_tick(&self,time:PhysicsTime)->PhysicsTime{
|
||||
PhysicsTime::from_nanos(self.tick_rate.rhs_div_int(self.tick_rate.mul_int(time.nanos())+1))
|
||||
}
|
||||
pub const fn activates(&self,controls:Controls)->bool{
|
||||
self.enable.activates(controls)
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ impl_additive_operator!( Fixed, BitXor, bitxor, Self );
|
||||
// non-wide operators. The result is the same width as the inputs.
|
||||
|
||||
// This macro is not used in the default configuration.
|
||||
#[allow(unused_macros)]
|
||||
#[expect(unused_macros)]
|
||||
macro_rules! impl_multiplicative_operator_not_const_generic {
|
||||
( ($struct: ident, $trait: ident, $method: ident, $output: ty ), $width:expr ) => {
|
||||
impl<const F:usize> core::ops::$trait for $struct<$width,F>{
|
||||
@@ -545,7 +545,7 @@ impl_shift_operator!( Fixed, Shr, shr, Self );
|
||||
|
||||
// wide operators. The result width is the sum of the input widths, i.e. none of the multiplication
|
||||
|
||||
#[allow(unused_macros)]
|
||||
#[expect(unused_macros)]
|
||||
macro_rules! impl_wide_operators{
|
||||
($lhs:expr,$rhs:expr)=>{
|
||||
impl core::ops::Mul<Fixed<$rhs,{$rhs*32}>> for Fixed<$lhs,{$lhs*32}>{
|
||||
|
||||
@@ -13,16 +13,16 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
bytemuck = "1.14.3"
|
||||
glam = "0.30.0"
|
||||
regex = { version = "1.11.3", default-features = false }
|
||||
rbx_binary = { version = "1.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "3.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_mesh = "0.5.0"
|
||||
rbx_reflection = "5.0.0"
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_xml = { version = "1.0.1-sn5", registry = "strafesnet" }
|
||||
rbxassetid = { version = "0.1.0", path = "../rbxassetid", registry = "strafesnet" }
|
||||
roblox_emulator = { version = "0.5.1", path = "../roblox_emulator", default-features = false, registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.7.0", path = "../common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "../deferred_loader", registry = "strafesnet" }
|
||||
rbx_binary = "2.0.1"
|
||||
rbx_dom_weak = "4.1.0"
|
||||
rbx_reflection = "6.1.0"
|
||||
rbx_reflection_database = "2.0.2"
|
||||
rbx_xml = "2.0.1"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -559,7 +559,7 @@ pub fn convert<'a>(
|
||||
//just going to leave it like this for now instead of reworking the data structures for this whole thing
|
||||
let textureless_render_group=render_config_deferred_loader.acquire_render_config_id(None);
|
||||
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let basepart=&db.classes["BasePart"];
|
||||
let baseparts=dom.descendants().filter(|&instance|
|
||||
db.classes.get(instance.class.as_str()).is_some_and(|class|
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "roblox_emulator"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
edition = "2024"
|
||||
repository = "https://git.itzana.me/StrafesNET/strafe-project"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@@ -15,10 +15,10 @@ run-service=[]
|
||||
glam = "0.30.0"
|
||||
mlua = { version = "0.11.3", features = ["luau"] }
|
||||
phf = { version = "0.13.1", features = ["macros"] }
|
||||
rbx_dom_weak = { version = "3.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_reflection = "5.0.0"
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_types = "2.0.0"
|
||||
rbx_dom_weak = "4.1.0"
|
||||
rbx_reflection = "6.1.0"
|
||||
rbx_reflection_database = "2.0.2"
|
||||
rbx_types = "3.1.0"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -52,7 +52,7 @@ impl Context{
|
||||
}
|
||||
/// Creates an iterator over all items of a particular class.
|
||||
pub fn superclass_iter<'a>(&'a self,superclass:&'a str)->impl Iterator<Item=Ref>+'a{
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let Some(superclass)=db.classes.get(superclass)else{
|
||||
panic!("Invalid class");
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ impl PartialEq for EnumItem<'_>{
|
||||
pub struct Enums;
|
||||
impl Enums{
|
||||
pub fn get(&self,index:&str)->Option<EnumItems<'static>>{
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
db.enums.get(index).map(|ed|EnumItems{ed})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ pub fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>
|
||||
}
|
||||
|
||||
pub fn class_is_a(class:&str,superclass:&str)->bool{
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let (Some(class),Some(superclass))=(db.classes.get(class),db.classes.get(superclass))else{
|
||||
return false;
|
||||
};
|
||||
@@ -80,14 +80,14 @@ pub fn find_first_descendant_of_class<'a>(dom:&'a WeakDom,instance:&rbx_dom_weak
|
||||
}
|
||||
|
||||
pub fn find_first_child_which_is_a<'a>(dom:&'a WeakDom,instance:&rbx_dom_weak::Instance,superclass:&str)->Option<&'a rbx_dom_weak::Instance>{
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let superclass_descriptor=db.classes.get(superclass)?;
|
||||
instance.children().iter().filter_map(|&r|dom.get_by_ref(r)).find(|inst|{
|
||||
db.classes.get(inst.class.as_str()).is_some_and(|descriptor|db.has_superclass(descriptor,superclass_descriptor))
|
||||
})
|
||||
}
|
||||
pub fn find_first_descendant_which_is_a<'a>(dom:&'a WeakDom,instance:&rbx_dom_weak::Instance,superclass:&str)->Option<&'a rbx_dom_weak::Instance>{
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let superclass_descriptor=db.classes.get(superclass)?;
|
||||
dom.descendants_of(instance.referent()).find(|inst|{
|
||||
db.classes.get(inst.class.as_str()).is_some_and(|descriptor|db.has_superclass(descriptor,superclass_descriptor))
|
||||
@@ -282,7 +282,7 @@ impl mlua::UserData for Instance{
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=this.get(dom)?;
|
||||
//println!("__index t={} i={index:?}",instance.name);
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let class=db.classes.get(instance.class.as_str()).ok_or_else(||mlua::Error::runtime("Class missing"))?;
|
||||
// Find existing property
|
||||
// Interestingly, ustr can know ahead of time if
|
||||
@@ -344,7 +344,7 @@ impl mlua::UserData for Instance{
|
||||
let index_str=&*index.to_str()?;
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=this.get_mut(dom)?;
|
||||
let db=rbx_reflection_database::get();
|
||||
let db=rbx_reflection_database::get().unwrap();
|
||||
let class=db.classes.get(instance.class.as_str()).ok_or_else(||mlua::Error::runtime("Class missing"))?;
|
||||
let property=db.superclasses_iter(class).find_map(|cls|
|
||||
cls.properties.get(index_str)
|
||||
|
||||
@@ -13,10 +13,10 @@ futures = "0.3.31"
|
||||
image = "0.25.2"
|
||||
image_dds = "0.7.1"
|
||||
rbx_asset = { version = "0.5.0", registry = "strafesnet" }
|
||||
rbx_binary = { version = "1.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "3.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_xml = { version = "1.0.1-sn5", registry = "strafesnet" }
|
||||
rbx_binary = "2.0.1"
|
||||
rbx_dom_weak = "4.1.0"
|
||||
rbx_reflection_database = "2.0.2"
|
||||
rbx_xml = "2.0.1"
|
||||
rbxassetid = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_bsp_loader = { version = "0.3.1", path = "../lib/bsp_loader", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "../lib/deferred_loader", registry = "strafesnet" }
|
||||
|
||||
Reference in New Issue
Block a user