Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// use std::marker::PhantomData;
//
// use bevy::app::{App, Plugin};
// use bevy::ecs::system::{SystemParam, SystemState};
// use bevy::prelude::{
// Commands, Component, DespawnRecursiveExt, Entity, In, Query, Res, ResMut, Resource, System,
// With, World,
// };
// use ldtk_rust::{EntityInstance, Level};
//
// use crate::utils::SerdeClone;
// use crate::{ActiveLevel, LevelIndex, MapQuery};
//
// #[derive(Component, Copy, Clone, Debug)]
// pub struct LdtkDespawnTag;
//
// pub type TileSpawnerInput = (Level, LdtkDespawnTag);
// pub type EntitySpawnerInput = Vec<EntityInstance>;
//
// fn noop_tile_system(_: In<TileSpawnerInput>) {}
// fn noop_entity_system(_: In<EntitySpawnerInput>) {}
//
// #[derive(Resource)]
// pub struct MapSpawner {
// tile_spawner: Option<Box<dyn System<In = TileSpawnerInput, Out = ()>>>,
// entity_spawner: Option<Box<dyn System<In = EntitySpawnerInput, Out = ()>>>,
// }
//
// impl MapSpawner {
// pub fn new(
// tile_spawner: impl System<In = TileSpawnerInput, Out = ()>,
// entity_spawner: impl System<In = EntitySpawnerInput, Out = ()>,
// ) -> Self {
// MapSpawner {
// tile_spawner: Some(Box::new(tile_spawner)),
// entity_spawner: Some(Box::new(entity_spawner)),
// }
// }
//
// pub fn with_tile_spawner(tile_spawner: impl System<In = TileSpawnerInput, Out = ()>) -> Self {
// MapSpawner {
// tile_spawner: Some(Box::new(tile_spawner)),
// entity_spawner: None,
// }
// }
// pub fn with_entity_spawner(
// entity_spawner: impl System<In = EntitySpawnerInput, Out = ()>,
// ) -> Self {
// MapSpawner {
// entity_spawner: Some(Box::new(entity_spawner)),
// tile_spawner: None,
// }
// }
//
// pub fn run_tile_system(&mut self, level: &Level, world: &mut World) {
// match self.tile_spawner {
// Some(ref mut system) => {
// system.run((level.serde_clone(), LdtkDespawnTag), world);
// }
// None => {}
// }
// }
// pub fn run_entity_system(&mut self, level: &Level, world: &mut World) {
// match self.entity_spawner {
// Some(ref mut system) => {
// let entity_list = MapQuery::get_owned_entities_of(level);
// system.run(entity_list, world);
// }
// None => {}
// }
// }
// }
//
// pub fn ldtk_spawning_system(
// world: &mut World,
// systems: &mut SystemState<(
// Commands,
// Option<Res<ActiveLevel>>,
// Option<ResMut<MapSpawner>>,
// Res<LevelIndex>,
// Query<Entity, With<LdtkDespawnTag>>,
// )>,
// ) {
// let (mut commands, active_level, mut spawning_systems, level_index, existing_query) =
// systems.get_mut(world);
//
// let active_level = match active_level {
// Some(res) => res,
// None => return,
// };
//
// if active_level.is_added() || (active_level.is_changed() && active_level.dirty) {
// for entity in &existing_query {
// commands.entity(entity).despawn_recursive();
// }
//
// let level = match level_index.get(&active_level.map) {
// Some(level) => level,
// None => return,
// };
//
// if let Some(mut spawning_systems) = spawning_systems {
// spawning_systems.run_tile_system(level, world);
// spawning_systems.run_entity_system(level, world);
// }
// }
// }