mirror of
https://github.com/scratchfoundation/scratch-tech-explorations.git
synced 2025-08-14 06:48:43 -04:00
refactor: upgrade to Bevy 0.10.1
This commit is contained in:
parent
7c47838fc6
commit
38d1d01a24
6 changed files with 717 additions and 575 deletions
1228
Cargo.lock
generated
1228
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,16 +7,16 @@ rust-version = "1.65"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.9.1"
|
||||
bevy = "0.10.1"
|
||||
futures-lite = "1.12.0"
|
||||
serde = {version = "1.0.152", features = ["std", "derive"]}
|
||||
serde_json = {version = "1.0.85", features = ["std", "float_roundtrip"]}
|
||||
zip = "0.6.3"
|
||||
|
||||
[features]
|
||||
# remember to disable bevy's "dynamic" feature for release builds
|
||||
default = ["dynamic"]
|
||||
dynamic = ["bevy/dynamic"]
|
||||
# remember to disable bevy's "dynamic_linking" feature for release builds
|
||||
default = ["dynamic_linking"]
|
||||
dynamic_linking = ["bevy/dynamic_linking"]
|
||||
|
||||
# Enable minor optimization in dev builds
|
||||
[profile.dev]
|
||||
|
|
|
@ -10,25 +10,19 @@ struct LoadingScreen;
|
|||
impl Plugin for ScratchLoadingScreenPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app
|
||||
.add_state(AppState::Loading)
|
||||
.add_system_set(
|
||||
SystemSet::on_enter(AppState::Loading)
|
||||
.with_system(ScratchLoadingScreenPlugin::start_loading_screen)
|
||||
)
|
||||
.add_system_set(
|
||||
SystemSet::on_update(AppState::Loading)
|
||||
.with_system(ScratchLoadingScreenPlugin::update_loading_screen)
|
||||
)
|
||||
.add_system_set(
|
||||
SystemSet::on_exit(AppState::Loading)
|
||||
.with_system(ScratchLoadingScreenPlugin::stop_loading_screen)
|
||||
);
|
||||
.add_system(ScratchLoadingScreenPlugin::start_loading_screen
|
||||
.in_schedule(OnEnter(AppState::Loading)))
|
||||
.add_system(ScratchLoadingScreenPlugin::update_loading_screen
|
||||
.in_set(OnUpdate(AppState::Loading)))
|
||||
.add_system(ScratchLoadingScreenPlugin::stop_loading_screen
|
||||
.in_schedule(OnExit(AppState::Loading)));
|
||||
}
|
||||
}
|
||||
|
||||
impl ScratchLoadingScreenPlugin {
|
||||
|
||||
fn start_loading_screen(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
info!("start_loading_screen");
|
||||
commands.spawn((
|
||||
Text2dBundle {
|
||||
text: Text::from_section("Loading...",
|
||||
|
@ -37,7 +31,7 @@ impl ScratchLoadingScreenPlugin {
|
|||
font_size: 60.0,
|
||||
color: Color::ORANGE,
|
||||
}
|
||||
).with_alignment(TextAlignment::CENTER),
|
||||
).with_alignment(TextAlignment::Center),
|
||||
..default()
|
||||
},
|
||||
LoadingScreen
|
||||
|
@ -51,6 +45,7 @@ impl ScratchLoadingScreenPlugin {
|
|||
}
|
||||
|
||||
fn stop_loading_screen(mut commands: Commands, mut loading_screen_query: Query<Entity, With<LoadingScreen>>) {
|
||||
info!("stop_loading_screen");
|
||||
for loading_screen in &mut loading_screen_query {
|
||||
commands.entity(loading_screen).despawn();
|
||||
}
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -14,9 +14,10 @@ use loading_screen::ScratchLoadingScreenPlugin;
|
|||
use project::ScratchDemoProjectPlugin;
|
||||
use stage::ScratchStagePlugin;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, States, Default)]
|
||||
|
||||
enum AppState {
|
||||
#[default]
|
||||
Loading,
|
||||
Running,
|
||||
}
|
||||
|
@ -24,17 +25,17 @@ enum AppState {
|
|||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
primary_window: Some(Window {
|
||||
title: "scratch-bevy".to_string(),
|
||||
width: 960.,
|
||||
height: 720.,
|
||||
resolution: (960., 720.).into(),
|
||||
resize_constraints: default(),
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
mode: WindowMode::Windowed,
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_state::<AppState>()
|
||||
.add_plugin(ScratchLoadingScreenPlugin)
|
||||
.add_plugin(ScratchStagePlugin)
|
||||
.add_plugin(ScratchDemoProjectPlugin)
|
||||
|
|
|
@ -15,10 +15,8 @@ impl Plugin for ScratchDemoProjectPlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app
|
||||
.add_startup_system(project_load)
|
||||
.add_system_set(
|
||||
SystemSet::on_update(AppState::Loading)
|
||||
.with_system(project_check_load)
|
||||
);
|
||||
.add_system(project_check_load
|
||||
.in_set(OnUpdate(AppState::Loading)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +32,7 @@ fn project_load(mut commands: Commands) {
|
|||
commands.insert_resource(ProjectLoadTask(load_task));
|
||||
}
|
||||
|
||||
fn project_check_load(mut app_state: ResMut<State<AppState>>, mut project_task: Option<ResMut<ProjectLoadTask>>) {
|
||||
fn project_check_load(mut app_state: ResMut<NextState<AppState>>, mut project_task: Option<ResMut<ProjectLoadTask>>) {
|
||||
if let Some(project_task) = &mut project_task {
|
||||
if let Some(project_load_result) = future::block_on(future::poll_once(&mut project_task.0)) {
|
||||
match project_load_result {
|
||||
|
@ -42,7 +40,7 @@ fn project_check_load(mut app_state: ResMut<State<AppState>>, mut project_task:
|
|||
Err(project_error) => error!("Project load failure: {}", project_error),
|
||||
}
|
||||
|
||||
app_state.set(AppState::Running).unwrap();
|
||||
app_state.set(AppState::Running);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/stage.rs
12
src/stage.rs
|
@ -1,12 +1,8 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use bevy::{
|
||||
time::FixedTimestep,
|
||||
};
|
||||
|
||||
use crate::sprite::{ScratchCode, ScratchScripts};
|
||||
|
||||
const TIME_STEP: f64 = 1. / 30.;
|
||||
const TIME_STEP: f32 = 1. / 30.;
|
||||
|
||||
|
||||
pub struct ScratchStagePlugin;
|
||||
|
@ -21,10 +17,8 @@ impl Plugin for ScratchStagePlugin {
|
|||
2.0,
|
||||
TimerMode::Repeating,
|
||||
)))
|
||||
.add_system_set(SystemSet::new()
|
||||
.with_run_criteria(FixedTimestep::step(TIME_STEP))
|
||||
.with_system(step_thread)
|
||||
)
|
||||
.insert_resource(FixedTime::new_from_secs(TIME_STEP))
|
||||
.add_system(step_thread.in_schedule(CoreSchedule::FixedUpdate))
|
||||
.add_startup_system(add_stage_startup);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue