Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit695cb3d

Browse files
committed
fix modals by propagating event target to be sure what exactly triggers events
1 parent08311e8 commit695cb3d

File tree

11 files changed

+69
-60
lines changed

11 files changed

+69
-60
lines changed

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ tracing = { version = "0.1", features = ["max_level_debug", "release_max_level_w
116116
# request more than 7 arguments, which would undesirably trigger this lint.
117117
too_many_arguments ="allow"
118118
type_complexity ="allow"# Queries may access many components, which would undesirably trigger this lint.
119+
collapsible_if ="allow"# Queries may access many components, which would undesirably trigger this lint.
119120
nonstandard_macro_braces ="warn"# Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`.
120121

121122
[package.metadata.bevy_cli.release]# Disable dev features for release builds.

‎README.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,25 @@ If you want to use serving with hotpatching, you can use dioxus-cli:
5858
-[x] experimental sound with[bevy_seedling] based on Firewheel audio engine (which will probably replace bevy_audio), with**highly** experimental audio stutter fix for web
5959
-[x] consistent Esc back navigation in gameplay and menu via stacked modals (kudos for the idea to skyemakesgames)
6060
-[x] serialize and save settings
61-
-[x] audio, video and keys rebind tabs in settings (currentlynot really working)
61+
-[x] audio, video and keys rebind tabs in settings (currentlybroken)
6262
-[x] easy drop in scene integration using awesome[skein] with a simple scene
6363

6464
###TODOs
65-
-[ ] add basic mood change per zone
66-
-[ ] implement different music states(exploration, combat)
65+
-[ ] implement different music states(exploration, combat) on mood change event
6766
-[ ] custom font replace example using pre-loaded font
6867
-[ ] Movement sfx sounds: jump, dash, sprint
6968
-[ ] sky background instead of just void lol
7069
-[ ] spatial audio demo: boombox emitting background music
7170
-[ ] Jump with timer(tricky with tnua jump in air counter)
7271
-[ ] small door/portal demo
73-
-[ ] split screen for coop
72+
-[ ] split screen forlocalcoop
7473
-[ ] vault on objects if they are reachable
7574
-[ ] climbing
76-
-[ ] do not rotate player on aim(silly bug, if you release aim looking to the floor - player model left rotated parallel to the floor)
7775
-[ ] basic fighting: punch, kick, take weapon
7876
-[ ] weapon select wheel
79-
-[ ] bow
8077
-[ ] rifle
78+
-[ ] bow
79+
-[ ] do not rotate player on aim(silly bug, if you release aim looking to the floor - player model left rotated parallel to the floor)
8180

8281
##Write your game
8382

‎src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn main() {
5454
};
5555
// DEBUG
5656
// let filter = "info,symphonia=off,naga=off,wgpu=warn,bevy_enhanced_input=debug".to_string();
57-
let filter ="info,calloop=off,symphonia=off,naga=off,wgpu=warn".to_string();
57+
let filter ="debug,calloop=off,symphonia=off,naga=off,wgpu=warn".to_string();
5858
let log_level = log::LogPlugin{
5959
level: log::Level::TRACE,
6060
filter,

‎src/models/event_dispatch.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct SettingsChanged;
5959

6060
// ================== trigger events on input ========================
6161
fnback(
62-
_:Trigger<Started<Escape>>,
62+
on:Trigger<Started<Escape>>,
6363
screen:Res<State<Screen>>,
6464
states:Res<GameState>,
6565
mutcommands:Commands,
@@ -68,13 +68,13 @@ fn back(
6868
Screen::Splash |Screen::Title |Screen::Loading =>{}
6969
_ =>{
7070
let last = states.last_screen.clone();
71-
commands.trigger(Back(last));
71+
commands.entity(on.target()).trigger(Back(last));
7272
}
7373
}
7474
}
75-
fnpause(_:Trigger<Started<Pause>>,mutcommands:Commands){
76-
commands.trigger(TogglePause);
75+
fnpause(on:Trigger<Started<Pause>>,mutcommands:Commands){
76+
commands.entity(on.target()).trigger(TogglePause);
7777
}
78-
fnmute(_:Trigger<Started<Mute>>,mutcommands:Commands){
79-
commands.trigger(ToggleMute);
78+
fnmute(on:Trigger<Started<Mute>>,mutcommands:Commands){
79+
commands.entity(on.target()).trigger(ToggleMute);
8080
}

‎src/models/input.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub fn plugin(app: &mut App) {
1111
.add_observer(add_player_ctx);
1212
}
1313

14-
fnspawn_ctx(mutcmds:Commands){
15-
cmds.spawn(ModalCtx);
14+
fnspawn_ctx(mutcommands:Commands){
15+
commands.spawn(ModalCtx);
1616
}
1717

1818
#[derive(InputAction)]
@@ -23,12 +23,12 @@ pub struct Navigate;
2323
#[action_output(Vec2)]
2424
pubstructPan;
2525

26-
//#[cfg(feature = "top_down")]
26+
#[cfg(feature ="top_down")]
2727
#[derive(InputAction)]
2828
#[action_output(Vec2)]
2929
pubstructScrollZoom;
3030

31-
//#[cfg(feature = "top_down")]
31+
#[cfg(feature ="top_down")]
3232
#[derive(InputAction)]
3333
#[action_output(bool)]
3434
pubstructRotateToggle;

‎src/models/player.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
usesuper::*;
2-
use std::collections::HashMap;
2+
use std::{
3+
collections::HashMap,
4+
sync::{Arc,Mutex},
5+
};
36

47
#[derive(Component,Reflect,Clone)]
58
#[reflect(Component)]
@@ -13,7 +16,9 @@ pub struct Player {
1316
implDefaultforPlayer{
1417
fndefault() ->Self{
1518
Self{
16-
id:Entity::PLACEHOLDER,
19+
// u32::MAX is Entity::PLACEHOLDER and using placeholder leeds to issues and using option
20+
// here while idiomatic will unnecessary complicate handling it in systems
21+
id:Entity::from_raw(u32::MAX -1),
1722
speed:1.0,
1823
animation_state:AnimationState::StandIdle,
1924
animations:HashMap::new(),

‎src/player/control.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ fn handle_sprint_in(
8989
mutplayer_query:Query<&mutPlayer,With<PlayerCtx>>,
9090
) ->Result{
9191
let entity = on.target();
92-
ifletOk(mut player) = player_query.get_mut(entity)
93-
&& player.speed <= cfg.player.movement.speed
94-
{
95-
player.speed *= cfg.player.movement.sprint_factor;
96-
info!("Sprint started for entity: {entity}");
92+
ifletOk(mut player) = player_query.get_mut(entity){
93+
if player.speed <= cfg.player.movement.speed{
94+
player.speed *= cfg.player.movement.sprint_factor;
95+
info!("Sprint started for entity: {entity}");
96+
}
9797
}
9898

9999
Ok(())
@@ -105,10 +105,10 @@ fn handle_sprint_out(
105105
mutplayer_query:Query<&mutPlayer,With<PlayerCtx>>,
106106
){
107107
let entity = on.target();
108-
ifletOk(mut player) = player_query.get_mut(entity)
109-
&& player.speed > cfg.player.movement.speed
110-
{
111-
player.speed = cfg.player.movement.speed;
108+
ifletOk(mut player) = player_query.get_mut(entity){
109+
if player.speed > cfg.player.movement.speed{
110+
player.speed = cfg.player.movement.speed;
111+
}
112112
}
113113
}
114114

‎src/player/mod.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub fn spawn_player(
6868
let pos =Vec3::from(cfg.player.spawn_pos);
6969
let pos =Transform::from_translation(pos).with_rotation(player_rot);
7070
let player =Player{
71-
id:Entity::PLACEHOLDER,
7271
speed: cfg.player.movement.speed,
7372
animation_state:AnimationState::StandIdle,
7473
..default()
@@ -88,7 +87,7 @@ pub fn spawn_player(
8887
TopDownCameraTarget,
8988
),
9089
PlayerCtx,
91-
// tnuastuff
90+
// tnuacharacter control bundles
9291
(
9392
TnuaController::default(),
9493
// Tnua can fix the rotation, but the character will still get rotated before it can do so.

‎src/screens/gameplay.rs‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,25 @@ fn click_to_menu(
9090
mutcommands:Commands,
9191
mutstate:ResMut<GameState>,
9292
){
93-
info!("click NewModal target entity: {}", on.target());
94-
commands.entity(on.target()).insert(ModalCtx);
95-
commands.trigger(GoTo(Screen::Title));
93+
let target = on.target();
94+
commands
95+
.entity(target)
96+
.insert(ModalCtx)
97+
.trigger(GoTo(Screen::Title));
9698
state.reset();
9799
}
98-
fnclick_pop_modal(_:Trigger<Pointer<Click>>,mutcmds:Commands){
99-
cmds.trigger(PopModal);
100+
fnclick_pop_modal(on:Trigger<Pointer<Click>>,mutcommands:Commands){
101+
commands.entity(on.target()).trigger(PopModal);
100102
}
101-
fnclick_spawn_settings(_:Trigger<Pointer<Click>>,mutcmds:Commands){
102-
cmds.trigger(NewModal(Modal::Settings));
103+
fnclick_spawn_settings(on:Trigger<Pointer<Click>>,mutcommands:Commands){
104+
commands
105+
.entity(on.target())
106+
.trigger(NewModal(Modal::Settings));
103107
}
104108

105109
fntrigger_menu_toggle_on_esc(
106-
_:Trigger<Back>,
107-
mutcmds:Commands,
110+
on:Trigger<Back>,
111+
mutcommands:Commands,
108112
screen:Res<State<Screen>>,
109113
state:ResMut<GameState>,
110114
){
@@ -113,9 +117,9 @@ fn trigger_menu_toggle_on_esc(
113117
}
114118

115119
if state.modals.is_empty(){
116-
cmds.trigger(NewModal(Modal::Main));
120+
commands.entity(on.target()).trigger(NewModal(Modal::Main));
117121
}else{
118-
cmds.trigger(PopModal);
122+
commands.entity(on.target()).trigger(PopModal);
119123
}
120124
}
121125

@@ -129,20 +133,19 @@ fn add_new_modal(
129133
return;
130134
}
131135

132-
info!("newmodal:{:?}, settings.paused:{}",on.0, state.paused);
136+
letmutmodal = commands.entity(on.target());
133137
if state.modals.is_empty(){
134-
info!("NewModal target entity: {}", on.target());
135-
commands.entity(on.target()).insert(ModalCtx);
138+
modal.insert(ModalCtx);
136139
ifModal::Main == on.0{
137140
if !state.paused{
138-
commands.trigger(TogglePause);
141+
modal.trigger(TogglePause);
139142
}
140-
commands.trigger(CamCursorToggle);
143+
modal.trigger(CamCursorToggle);
141144
}
142145
}
143146

144147
// despawn all previous modal entities to avoid clattering
145-
commands.trigger(ClearModals);
148+
modal.trigger(ClearModals);
146149
letNewModal(modal) = on.event();
147150
match modal{
148151
Modal::Main => commands.spawn(menu_modal()),
@@ -192,9 +195,11 @@ fn pop_modal(
192195

193196
if state.modals.is_empty(){
194197
info!("PopModal target entity: {}", on.target());
195-
commands.entity(on.target()).insert(ModalCtx);
196-
commands.trigger(TogglePause);
197-
commands.trigger(CamCursorToggle);
198+
commands
199+
.entity(on.target())
200+
.insert(ModalCtx)
201+
.trigger(TogglePause)
202+
.trigger(CamCursorToggle);
198203
}
199204
}
200205

@@ -203,18 +208,18 @@ fn clear_modals(
203208
state:ResMut<GameState>,
204209
menu_marker:Query<Entity,With<MenuModal>>,
205210
settings_marker:Query<Entity,With<SettingsModal>>,
206-
mutcmds:Commands,
211+
mutcommands:Commands,
207212
){
208213
for min&state.modals{
209214
match m{
210215
Modal::Main =>{
211216
ifletOk(modal) = menu_marker.single(){
212-
cmds.entity(modal).despawn();
217+
commands.entity(modal).despawn();
213218
}
214219
}
215220
Modal::Settings =>{
216221
ifletOk(modal) = settings_marker.single(){
217-
cmds.entity(modal).despawn();
222+
commands.entity(modal).despawn();
218223
}
219224
}
220225
}

‎src/screens/mod.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ pub fn on_go_to(trig: Trigger<GoTo>, mut next_screen: ResMut<NextState<Screen>>)
6666
pubmod to{
6767
usesuper::*;
6868

69-
pubfntitle(_:Trigger<OnPress>,mutcmds:Commands,mutstate:ResMut<GameState>){
69+
pubfntitle(on:Trigger<OnPress>,mutcommands:Commands,mutstate:ResMut<GameState>){
7070
state.reset();
71-
cmds.trigger(GoTo(Screen::Title));
71+
commands.entity(on.target()).trigger(GoTo(Screen::Title));
7272
}
73-
pubfnsettings(_:Trigger<OnPress>,mutcmds:Commands){
74-
cmds.trigger(GoTo(Screen::Settings));
73+
pubfnsettings(on:Trigger<OnPress>,mutcommands:Commands){
74+
commands.entity(on.target()).trigger(GoTo(Screen::Settings));
7575
}
76-
pubfncredits(_:Trigger<OnPress>,mutcmds:Commands){
77-
cmds.trigger(GoTo(Screen::Credits));
76+
pubfncredits(on:Trigger<OnPress>,mutcommands:Commands){
77+
commands.entity(on.target()).trigger(GoTo(Screen::Credits));
7878
}
7979
pubfngameplay_or_loading(
8080
_:Trigger<OnPress>,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp