Commit 1ae2c0d4 authored by Rahix's avatar Rahix 🦀
Browse files

heaven: Move orbiting node initialization into separate function

Small cleanup so it is more obvious what the primary objective of the
heaven is.
parent 8f824eb0
......@@ -14,60 +14,7 @@ pub struct HeavenState {
impl HeavenState {
pub fn new() -> HeavenState {
let mut resources = legion::Resources::default();
resources.insert(resources::Clock::new());
resources.insert(resources::Rendering::new("game-canvas").unwrap());
let mut node_world = legion::World::default();
let n0 = node_world.push((
components::Node::new(),
components::Position::new(800.0, 340.0),
components::OrbitBody::new(5.0, 10.0),
components::Gravity,
));
let n1 = node_world.push((
components::Node::new(),
components::Position::new(120.0, 300.0),
components::OrbitBody::new(5.0, -5.0),
components::Gravity,
));
let n2 = node_world.push((
components::Node::new(),
components::Position::new(700.0, 740.0),
components::OrbitBody::new(8.0, -4.0),
components::Gravity,
));
let n3 = node_world.push((
components::Node::new(),
components::Position::new(340.0, 290.0),
components::OrbitBody::new(10.0, 0.0),
components::Gravity,
));
let n4 = node_world.push((
components::Node::new(),
components::Position::new(300.0, 400.0),
components::OrbitBody::new(0.0, 10.0),
components::Gravity,
));
node_world.push((components::Edge::new(n0, n1),));
node_world.push((components::Edge::new(n1, n2),));
node_world.push((components::Edge::new(n0, n2),));
node_world.push((components::Edge::new(n2, n3),));
node_world.push((components::Edge::new(n3, n4),));
node_world.push((components::Edge::new(n0, n4),));
node_world.push((components::TheSun, components::Position::new(600.0, 540.0)));
let node_schedule = legion::Schedule::builder()
.add_system(components::update_gravity_system())
.add_system(components::update_movement_system())
.add_thread_local(components::update_nodes_system())
.flush()
.add_thread_local(components::draw_edges_system())
.add_thread_local(components::draw_nodes_system())
.add_thread_local(components::draw_thesun_system())
.build();
let (node_world, resources, node_schedule) = init_orbiting_nodes();
HeavenState {
gui_svg: utils::get_element_by_id("heaven-ui").unwrap(),
......@@ -121,3 +68,62 @@ impl gamestate::State for HeavenState {
}
}
}
fn init_orbiting_nodes() -> (legion::World, legion::Resources, legion::Schedule) {
let mut resources = legion::Resources::default();
resources.insert(resources::Clock::new());
resources.insert(resources::Rendering::new("game-canvas").unwrap());
let mut node_world = legion::World::default();
let n0 = node_world.push((
components::Node::new(),
components::Position::new(800.0, 340.0),
components::OrbitBody::new(5.0, 10.0),
components::Gravity,
));
let n1 = node_world.push((
components::Node::new(),
components::Position::new(120.0, 300.0),
components::OrbitBody::new(5.0, -5.0),
components::Gravity,
));
let n2 = node_world.push((
components::Node::new(),
components::Position::new(700.0, 740.0),
components::OrbitBody::new(8.0, -4.0),
components::Gravity,
));
let n3 = node_world.push((
components::Node::new(),
components::Position::new(340.0, 290.0),
components::OrbitBody::new(10.0, 0.0),
components::Gravity,
));
let n4 = node_world.push((
components::Node::new(),
components::Position::new(300.0, 400.0),
components::OrbitBody::new(0.0, 10.0),
components::Gravity,
));
node_world.push((components::Edge::new(n0, n1),));
node_world.push((components::Edge::new(n1, n2),));
node_world.push((components::Edge::new(n0, n2),));
node_world.push((components::Edge::new(n2, n3),));
node_world.push((components::Edge::new(n3, n4),));
node_world.push((components::Edge::new(n0, n4),));
node_world.push((components::TheSun, components::Position::new(600.0, 540.0)));
let node_schedule = legion::Schedule::builder()
.add_system(components::update_gravity_system())
.add_system(components::update_movement_system())
.add_thread_local(components::update_nodes_system())
.flush()
.add_thread_local(components::draw_edges_system())
.add_thread_local(components::draw_nodes_system())
.add_thread_local(components::draw_thesun_system())
.build();
(node_world, resources, node_schedule)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment