editor: filters
This commit is contained in:
parent
1e2ecd76c7
commit
9908406623
4 changed files with 207 additions and 14 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -590,9 +590,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bevy_mod_picking"
|
||||
version = "0.8.2"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19f97d740fcd9d089a768399e902e741f45f8d671e756c939d2f1ce8ad14d63a"
|
||||
checksum = "db42ac84b1409452bbfa696d9071b9a7a2505c73620c939b758b5bf23573976a"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_mod_raycast",
|
||||
|
@ -1333,7 +1333,6 @@ dependencies = [
|
|||
"parking_lot 0.12.1",
|
||||
"stdweb",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"windows",
|
||||
]
|
||||
|
|
|
@ -17,14 +17,13 @@ serde = { version = "1.0.144", features = ["derive"] }
|
|||
|
||||
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
|
||||
bevy-inspector-egui = "0.12.1"
|
||||
bevy_mod_picking = "0.8.2"
|
||||
bevy_mod_picking = "0.9.0"
|
||||
cpal = "0.14.0"
|
||||
hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP", default-features = false }
|
||||
serde_json = "1.0.85"
|
||||
ticktock = "0.8.0"
|
||||
|
||||
[target."cfg(target_arch = \"wasm32\")".dependencies]
|
||||
cpal = { version = "0.14.0", features = ["wasm-bindgen"] }
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
|
204
src/editor.rs
204
src/editor.rs
|
@ -55,6 +55,12 @@ struct CharacterColor(Color);
|
|||
#[derive(Component)]
|
||||
struct Size(Vec2);
|
||||
|
||||
#[derive(Component)]
|
||||
struct RotatingFilterAngle(f32);
|
||||
|
||||
#[derive(Component)]
|
||||
struct AbsorbingFilterColor(Color);
|
||||
|
||||
// Bundles
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
@ -66,7 +72,7 @@ struct PlatformBundle {
|
|||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
struct PlatformEndBundle {
|
||||
struct EndBundle {
|
||||
#[bundle]
|
||||
mesh: ColorMesh2dBundle,
|
||||
#[bundle]
|
||||
|
@ -85,6 +91,24 @@ struct CharacterBundle {
|
|||
draggable: Draggable,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
struct AbsorbingFilterBundle {
|
||||
#[bundle]
|
||||
mesh: ColorMesh2dBundle,
|
||||
size: Size,
|
||||
color: AbsorbingFilterColor,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
struct RotatingFilterBundle {
|
||||
#[bundle]
|
||||
mesh: ColorMesh2dBundle,
|
||||
angle: RotatingFilterAngle,
|
||||
#[bundle]
|
||||
pickable: PickableBundle,
|
||||
draggable: Draggable,
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
||||
fn spawn_platform(
|
||||
|
@ -109,7 +133,7 @@ fn spawn_platform(
|
|||
.id();
|
||||
let ends = Ends(
|
||||
commands
|
||||
.spawn_bundle(PlatformEndBundle {
|
||||
.spawn_bundle(EndBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Circle {
|
||||
|
@ -131,7 +155,7 @@ fn spawn_platform(
|
|||
})
|
||||
.id(),
|
||||
commands
|
||||
.spawn_bundle(PlatformEndBundle {
|
||||
.spawn_bundle(EndBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Circle {
|
||||
|
@ -202,6 +226,121 @@ fn spawn_character(
|
|||
.id()
|
||||
}
|
||||
|
||||
fn spawn_absorbing_filter(
|
||||
commands: &mut Commands,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
|
||||
transform: Transform,
|
||||
size: Vec2,
|
||||
color: Color,
|
||||
) {
|
||||
let absorbing_filter = commands
|
||||
.spawn_bundle(AbsorbingFilterBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes.add(Mesh::from(Quad { size, flip: false })).into(),
|
||||
material: materials.add(ColorMaterial::from(color)),
|
||||
transform,
|
||||
..default()
|
||||
},
|
||||
size: Size(size),
|
||||
color: AbsorbingFilterColor(color),
|
||||
})
|
||||
.id();
|
||||
let ends = Ends(
|
||||
commands
|
||||
.spawn_bundle(EndBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Circle {
|
||||
radius: 8.,
|
||||
vertices: 12,
|
||||
}))
|
||||
.into(),
|
||||
material: materials.add(ColorMaterial::from(Color::rgba(1., 1., 0., 0.7))),
|
||||
transform: Transform::from_xyz(
|
||||
transform.translation.x - size.x / 2.,
|
||||
transform.translation.y - size.y / 2.,
|
||||
0.5,
|
||||
),
|
||||
..default()
|
||||
},
|
||||
pickable: PickableBundle::default(),
|
||||
draggable: Draggable,
|
||||
end: End(absorbing_filter),
|
||||
})
|
||||
.id(),
|
||||
commands
|
||||
.spawn_bundle(EndBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Circle {
|
||||
radius: 8.,
|
||||
vertices: 12,
|
||||
}))
|
||||
.into(),
|
||||
material: materials.add(ColorMaterial::from(Color::rgba(1., 1., 0., 0.7))),
|
||||
transform: Transform::from_xyz(
|
||||
transform.translation.x + size.x / 2.,
|
||||
transform.translation.y + size.y / 2.,
|
||||
0.5,
|
||||
),
|
||||
..default()
|
||||
},
|
||||
pickable: PickableBundle::default(),
|
||||
draggable: Draggable,
|
||||
end: End(absorbing_filter),
|
||||
})
|
||||
.id(),
|
||||
);
|
||||
commands.entity(absorbing_filter).insert(ends);
|
||||
}
|
||||
|
||||
fn spawn_rotating_filter(
|
||||
commands: &mut Commands,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
asset_server: &Res<AssetServer>,
|
||||
|
||||
transform: Transform,
|
||||
angle: f32,
|
||||
) -> Entity {
|
||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
||||
commands
|
||||
.spawn_bundle(RotatingFilterBundle {
|
||||
mesh: ColorMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(Mesh::from(Circle {
|
||||
radius: 32.,
|
||||
vertices: 36,
|
||||
}))
|
||||
.into(),
|
||||
material: materials.add(ColorMaterial::from(Color::WHITE)),
|
||||
transform,
|
||||
..default()
|
||||
},
|
||||
angle: RotatingFilterAngle(angle),
|
||||
pickable: PickableBundle::default(),
|
||||
draggable: Draggable,
|
||||
})
|
||||
.with_children(|c| {
|
||||
c.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
&angle.to_string(),
|
||||
TextStyle {
|
||||
font: font.clone(),
|
||||
font_size: 32.,
|
||||
color: Color::RED,
|
||||
},
|
||||
)
|
||||
.with_alignment(TextAlignment::CENTER),
|
||||
transform: Transform::from_xyz(0., 0., 1.),
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.id()
|
||||
}
|
||||
|
||||
fn spawn_stored_level(
|
||||
commands: &mut Commands,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
|
@ -233,6 +372,28 @@ fn spawn_stored_level(
|
|||
));
|
||||
}
|
||||
commands.insert_resource(CharacterList(character_list));
|
||||
|
||||
for absorbing_filter in stored_level.absorbing_filters.iter() {
|
||||
spawn_absorbing_filter(
|
||||
commands,
|
||||
meshes,
|
||||
materials,
|
||||
Transform::from_xyz(absorbing_filter.pos.x, absorbing_filter.pos.y, 0.),
|
||||
absorbing_filter.size,
|
||||
absorbing_filter.color.into(),
|
||||
);
|
||||
}
|
||||
|
||||
for rotating_filter in stored_level.rotating_filters.iter() {
|
||||
spawn_rotating_filter(
|
||||
commands,
|
||||
meshes,
|
||||
materials,
|
||||
asset_server,
|
||||
Transform::from_xyz(rotating_filter.pos.x, rotating_filter.pos.y, 0.),
|
||||
rotating_filter.angle,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn save_level(
|
||||
|
@ -242,6 +403,11 @@ fn save_level(
|
|||
character_list: &Res<CharacterList>,
|
||||
character_query: &Query<(&Transform, &CharacterColor), Without<Platform>>,
|
||||
platform_query: &Query<(&Transform, &Size), With<Platform>>,
|
||||
absorbing_filter_query: &Query<(&Transform, &Size, &AbsorbingFilterColor), Without<Platform>>,
|
||||
rotating_filter_query: &Query<
|
||||
(&Transform, &RotatingFilterAngle),
|
||||
(Without<Platform>, Without<CharacterColor>),
|
||||
>,
|
||||
) {
|
||||
let stored_levels = stored_levels_assets.get_mut(stored_levels_handle).unwrap();
|
||||
if let Some(stored_level) = stored_levels.levels.get_mut(level_id.0 .0 as usize) {
|
||||
|
@ -264,10 +430,33 @@ fn save_level(
|
|||
x: transform.translation.x,
|
||||
y: transform.translation.y,
|
||||
},
|
||||
color: color.0.as_rgba_f32().into(),
|
||||
color: color.0.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
stored_level.absorbing_filters.clear();
|
||||
for (transform, size, color) in absorbing_filter_query.iter() {
|
||||
stored_level.absorbing_filters.push(StoredAbsorbingFilter {
|
||||
pos: Vec2 {
|
||||
x: transform.translation.x,
|
||||
y: transform.translation.y,
|
||||
},
|
||||
size: size.0,
|
||||
color: color.0.into(),
|
||||
})
|
||||
}
|
||||
|
||||
stored_level.rotating_filters.clear();
|
||||
for (transform, angle) in rotating_filter_query.iter() {
|
||||
stored_level.rotating_filters.push(StoredRotatingFilter {
|
||||
pos: Vec2 {
|
||||
x: transform.translation.x,
|
||||
y: transform.translation.y,
|
||||
},
|
||||
angle: angle.0,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -324,6 +513,11 @@ fn input_control_system(
|
|||
character_list: Res<CharacterList>,
|
||||
character_query: Query<(&Transform, &CharacterColor), Without<Platform>>,
|
||||
platform_query: Query<(&Transform, &Size), With<Platform>>,
|
||||
absorbing_filter_query: Query<(&Transform, &Size, &AbsorbingFilterColor), Without<Platform>>,
|
||||
rotating_filter_query: Query<
|
||||
(&Transform, &RotatingFilterAngle),
|
||||
(Without<Platform>, Without<CharacterColor>),
|
||||
>,
|
||||
) {
|
||||
if keyboard_input.just_released(KeyCode::S)
|
||||
&& (keyboard_input.pressed(KeyCode::LControl) || keyboard_input.pressed(KeyCode::RControl))
|
||||
|
@ -335,6 +529,8 @@ fn input_control_system(
|
|||
&character_list,
|
||||
&character_query,
|
||||
&platform_query,
|
||||
&absorbing_filter_query,
|
||||
&rotating_filter_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -475,10 +475,9 @@ fn move_camera(
|
|||
// prevent camera from going too low
|
||||
target_translation.y = target_translation.y.max(half_height - MARGIN);
|
||||
|
||||
camera_transform.translation = camera_transform.translation.lerp(
|
||||
target_translation,
|
||||
time.delta_seconds() * FOLLOW_SPEED,
|
||||
);
|
||||
camera_transform.translation = camera_transform
|
||||
.translation
|
||||
.lerp(target_translation, time.delta_seconds() * FOLLOW_SPEED);
|
||||
|
||||
// always make sure that camera is away from the object in order to render them
|
||||
camera_transform.translation.z = 999.0;
|
||||
|
|
Loading…
Reference in a new issue