delete place.rs
This commit is contained in:
parent
7774fe9eb4
commit
c0323d12df
@ -19,17 +19,16 @@ impl Context{
|
||||
pub const fn new(dom:WeakDom)->Self{
|
||||
Self{dom}
|
||||
}
|
||||
pub fn script_singleton(source:String)->(Context,crate::runner::instance::Script,crate::place::Services){
|
||||
pub fn script_singleton(source:String)->(Context,crate::runner::instance::Script,Services){
|
||||
let script=InstanceBuilder::new("Script")
|
||||
.with_property("Source",rbx_types::Variant::String(source));
|
||||
let script_ref=script.referent();
|
||||
let (dom,services)=crate::place::new_place_with_instances_in_workspace(
|
||||
WeakDom::new(
|
||||
InstanceBuilder::new("DataModel")
|
||||
.with_child(script)
|
||||
)
|
||||
);
|
||||
(Context{dom},crate::runner::instance::Script::new(script_ref),services)
|
||||
let mut context=Self::new(WeakDom::new(
|
||||
InstanceBuilder::new("DataModel")
|
||||
.with_child(script)
|
||||
));
|
||||
let services=context.convert_into_place();
|
||||
(context,crate::runner::instance::Script::new(script_ref),services)
|
||||
}
|
||||
pub fn from_ref(dom:&WeakDom)->&Context{
|
||||
unsafe{&*(dom as *const WeakDom as *const Context)}
|
||||
@ -46,4 +45,40 @@ impl Context{
|
||||
pub fn scripts(&self)->Vec<crate::runner::instance::Script>{
|
||||
self.superclass_iter("LuaSourceContainer").map(crate::runner::instance::Script::new).collect()
|
||||
}
|
||||
|
||||
pub fn find_services(&self)->Option<Services>{
|
||||
Some(Services{
|
||||
workspace:*self.dom.root().children().iter().find(|&&r|
|
||||
self.dom.get_by_ref(r).is_some_and(|instance|instance.class=="Workspace")
|
||||
)?,
|
||||
game:self.dom.root_ref(),
|
||||
})
|
||||
}
|
||||
pub fn convert_into_place(&mut self)->Services{
|
||||
//snapshot root instances
|
||||
let children=self.dom.root().children().to_owned();
|
||||
|
||||
//insert services
|
||||
let game=self.dom.root_ref();
|
||||
let workspace=self.dom.insert(game,
|
||||
InstanceBuilder::new("Workspace")
|
||||
.with_child(InstanceBuilder::new("Terrain"))
|
||||
);
|
||||
self.dom.insert(game,InstanceBuilder::new("Lighting"));
|
||||
|
||||
//transfer original root instances into workspace
|
||||
for instance in children{
|
||||
self.dom.transfer_within(instance,workspace);
|
||||
}
|
||||
|
||||
Services{
|
||||
game,
|
||||
workspace,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Services{
|
||||
pub game:Ref,
|
||||
pub workspace:Ref,
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
pub mod place;
|
||||
pub mod runner;
|
||||
pub mod context;
|
||||
|
||||
|
47
src/place.rs
47
src/place.rs
@ -1,47 +0,0 @@
|
||||
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
||||
use rbx_types::Ref;
|
||||
|
||||
pub struct Services{
|
||||
pub game:Ref,
|
||||
pub workspace:Ref,
|
||||
}
|
||||
impl Services{
|
||||
pub fn find_in(dom:&WeakDom)->Option<Self>{
|
||||
Some(Services{
|
||||
workspace:*dom.root().children().iter().find(|&&r|
|
||||
dom.get_by_ref(r).is_some_and(|instance|instance.class=="Workspace")
|
||||
)?,
|
||||
game:dom.root_ref(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_place_with_instances_in_workspace(mut instance_dom:WeakDom)->(WeakDom,Services){
|
||||
//workspace
|
||||
let workspace_bldr=InstanceBuilder::new("Workspace")
|
||||
.with_child(InstanceBuilder::new("Terrain"));
|
||||
let workspace=workspace_bldr.referent();
|
||||
|
||||
//game
|
||||
let game_bldr=
|
||||
InstanceBuilder::new("DataModel")
|
||||
.with_child(workspace_bldr)
|
||||
.with_child(InstanceBuilder::new("Lighting"));
|
||||
let game=game_bldr.referent();
|
||||
|
||||
let mut dom=WeakDom::new(game_bldr);
|
||||
|
||||
//put instances in workspace
|
||||
let children=instance_dom.root().children().to_owned();
|
||||
for instance in children{
|
||||
instance_dom.transfer(instance,&mut dom,workspace);
|
||||
}
|
||||
|
||||
(
|
||||
dom,
|
||||
Services{
|
||||
game,
|
||||
workspace
|
||||
}
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user