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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
//! The frame, in order: what the app is built from, what each screen puts
//! up and takes down, and which systems run when.
//!
//! Split from `mod.rs`, which keeps the types the whole shell shares. The
//! two answer different questions, what a thing *is* and when it *runs*,
//! and only this half changes when a system moves.
use super::*;
pub fn run() {
let mut app = App::new();
embedded::register(&mut app);
app.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
title: "Pinch Points".into(),
resolution: dev::window_size().map_or_else(default, |(w, h)| {
bevy::window::WindowResolution::new(w as u32, h as u32)
}),
..default()
}),
..default()
})
.set(bevy::log::LogPlugin {
// Japanese has no word spaces, so a line of it is broken
// with a dictionary - and the one baked into the text
// stack's segmenter does not carry the CJK model. The
// lines still lay out (they break between characters,
// which is how Japanese wraps anyway); what it does is
// warn, from deep inside a layout pass, once per line
// per frame. Sixty of those a second is not a report of
// anything, so this one target is turned off.
filter: format!(
"{},icu_provider=off",
bevy::log::LogPlugin::default().filter
),
..bevy::log::LogPlugin::default()
})
.set(RenderPlugin {
render_creation: RenderCreation::Automatic(Box::new(WgpuSettings {
// Debug builds default to the Vulkan validation
// layer, which floods the log with a known
// wgpu-internal swapchain finding
// (VUID-VkPresentInfoKHR-pImageIndices /
// acquire-semaphore) we cannot act on. Run with
// WGPU_VALIDATION=1 to opt back in when debugging
// rendering.
instance_flags: InstanceFlags::empty().with_env(),
..WgpuSettings::default()
})),
..RenderPlugin::default()
}),
);
insert_resources(&mut app);
add_startup(&mut app);
add_screen_transitions(&mut app);
add_phase_transitions(&mut app);
add_frame_systems(&mut app);
// Dev hook: `PINCH_ST_EXEC=1` swaps every main-world schedule to the
// single-threaded executor, for the backlog's CPU measurement: the
// engine spends more coordinating this game's hundred small systems
// than the systems spend working. The render sub-app keeps its own
// schedules and its parallelism. `new()` rather than `default()`: the
// derived default leaves `apply_final_deferred` false, and the app
// dies on the first frame missing every command-queued resource.
if dev::single_threaded_executor() {
use bevy::ecs::schedule::{Schedules, SingleThreadedExecutor};
let mut schedules = app.world_mut().resource_mut::<Schedules>();
let swapped = schedules
.iter_mut()
.map(|(_, schedule)| schedule.set_executor(SingleThreadedExecutor::new()))
.count();
info!("single-threaded executor on {swapped} main-world schedules");
}
app.run();
}
/// The resources, states and message types the whole shell shares.
fn insert_resources(app: &mut App) {
app.insert_resource(Time::<Fixed>::from_hz(f64::from(
crate::sim::TICKS_PER_SECOND,
)));
app.insert_resource(Sandbox(dev::sandbox()));
let (levels, builtins) = campaign::tide_pool_levels();
app.insert_resource(Campaign {
kind: CampaignKind::TidePool,
levels,
index: 0,
builtins,
});
// Replaced on mode entry; a 1x1 board just keeps the resource non-null.
app.insert_resource(Sim(Board::new(1, 1, 0)));
app.init_resource::<PendingActions>();
app.init_resource::<Paused>();
app.init_resource::<editor::EditorState>();
app.init_resource::<Recorder>();
app.init_resource::<Highlight>();
app.init_resource::<ReelThread>();
app.init_resource::<Bots>();
app.init_resource::<art::Art>();
app.init_resource::<match_setup::MatchConfig>();
app.init_resource::<match_setup::CustomBeaches>();
app.init_resource::<board_render::CastleFlight>();
app.init_resource::<match_setup::MatchMenu>();
app.init_resource::<Playback>();
app.init_resource::<net::Online>();
app.init_resource::<lobby::LobbyState>();
app.init_resource::<Seats>();
app.init_resource::<Resuming>();
app.init_resource::<RoundNotice>();
app.init_resource::<menu_scene::MenuList>();
app.init_resource::<stage_select::StageList>();
app.init_resource::<hint::Hints>();
app.init_resource::<replays::Library>();
app.init_resource::<replays::PlaybackSpeed>();
app.init_resource::<gamepad::PadSeats>();
app.init_resource::<effects::VisualRng>();
app.init_resource::<pause::PauseMenu>();
app.init_resource::<Daily>();
app.init_resource::<SeatNames>();
app.init_resource::<tournament::Tournament>();
app.init_resource::<side_panels::EventLog>();
app.init_resource::<announce::Announcer>();
app.init_resource::<update::UpdateCheck>();
// A first run has no settings file, and opens on the language picker
// rather than on a menu written in a language nobody chose. One read
// answers both questions: what the settings are, and whether there
// were any. A dev hook still wins - `dev::kickoff` sets NextState in
// Startup, which lands before the first state transition.
let saved = settings::GameSettings::load_saved();
let opens_on = language::opening_screen(saved.is_some());
app.insert_resource(saved.unwrap_or_default());
app.init_resource::<settings::screen::SettingsMenu>();
app.init_resource::<controls::ControlsMenu>();
app.insert_state(opens_on);
app.init_state::<Phase>();
app.init_state::<VersusPhase>();
app.add_message::<LoadLevel>();
app.add_message::<PlacementDenied>();
app.add_message::<LevelSaved>();
app.add_message::<sim_events::SimEvent>();
}
/// One-time setup: camera, font, HUD, sounds, saved stats, dev hooks.
fn add_startup(app: &mut App) {
app.add_systems(
Startup,
(
boot::setup_camera,
boot::install_ui_font,
hud::spawn_hud,
audio::load_sounds,
achievements::load,
progress::load,
dev::kickoff,
// Off-thread; the menu polls for the answer.
update::start_check,
),
);
}
/// What each screen builds on entry and tears down on exit.
fn add_screen_transitions(app: &mut App) {
app.add_systems(
OnEnter(Screen::Puzzle),
(cursor::spawn_puzzle_cursor, send_first_load).chain(),
);
app.add_systems(
OnEnter(Screen::Achievements),
achievements::enter_achievements,
);
app.add_systems(
OnEnter(Screen::StageSelect),
stage_select::enter_stage_select,
);
app.add_systems(
OnExit(Screen::StageSelect),
menu_ui::despawn_marked::<stage_select::StageSelectUi>,
);
app.add_systems(OnEnter(Screen::Language), language::enter_language);
app.add_systems(OnEnter(Screen::NewVersion), update::enter_new_version);
app.add_systems(OnExit(Screen::NewVersion), update::exit_new_version);
app.add_systems(
OnExit(Screen::Language),
menu_ui::despawn_marked::<language::LanguageUi>,
);
app.add_systems(OnEnter(Screen::Replays), replays::enter_library);
app.add_systems(
OnExit(Screen::Replays),
menu_ui::despawn_marked::<replays::LibraryUi>,
);
app.add_systems(
OnExit(Screen::Achievements),
menu_ui::despawn_marked::<achievements::AchievementsUi>,
);
app.add_systems(
OnEnter(Screen::Versus),
// Chained so the cursor spawn commands apply before load_versus
// positions the cursors, and the side panels see the seat count.
(
// A local match on a handmade beach reads it off the shelf, so
// the shelf has to be current before the board is built.
match_setup::refresh_custom_beaches,
cursor::spawn_versus_cursors,
load_versus,
resolve_seat_names,
side_panels::spawn_side_panels,
achievements::reset_round_scratch,
)
.chain(),
);
app.add_systems(
OnEnter(Screen::Editor),
(
editor::enter_editor,
editor::spawn_editor_ui,
cursor::spawn_puzzle_cursor,
cursor::center_cursors,
)
.chain(),
);
app.add_systems(
OnEnter(Screen::Menu),
(
menu_scene::enter_menu,
tournament::reset_on_menu,
// Whatever kept a session alive between rounds, the menu is the
// end of it: the socket closes and the beach comes off the air.
|mut online: ResMut<net::Online>| online.0 = None,
),
);
app.add_systems(
OnExit(Screen::Menu),
(
menu_ui::despawn_marked::<menu_scene::MenuArt>,
despawn_board_sprites,
// The notice is news about one round; it is read on the menu and
// does not follow the player into the next thing they pick.
|mut notice: ResMut<RoundNotice>| notice.0.clear(),
),
);
app.add_systems(
OnEnter(Screen::Lobby),
(match_setup::refresh_custom_beaches, lobby::enter_lobby),
);
app.add_systems(
OnExit(Screen::Lobby),
(lobby::exit_lobby, menu_ui::despawn_marked::<lobby::LobbyUi>),
);
app.add_systems(OnEnter(Screen::Settings), settings::screen::enter_settings);
app.add_systems(
OnExit(Screen::Settings),
menu_ui::save_and_despawn::<settings::screen::SettingsUi>,
);
app.add_systems(OnEnter(Screen::Controls), controls::enter_controls);
app.add_systems(
OnExit(Screen::Controls),
menu_ui::save_and_despawn::<controls::ControlsUi>,
);
app.add_systems(
OnEnter(Screen::MatchSetup),
(
match_setup::refresh_custom_beaches,
match_setup::enter_match_setup,
),
);
app.add_systems(
OnExit(Screen::MatchSetup),
menu_ui::save_and_despawn::<match_setup::MatchUi>,
);
app.add_systems(OnEnter(Screen::Interlude), tournament::enter_interlude);
app.add_systems(
OnExit(Screen::Interlude),
menu_ui::despawn_marked::<tournament::InterludeUi>,
);
app.add_systems(
OnExit(Screen::Editor),
(
menu_ui::despawn_marked::<cursor::Cursor>,
menu_ui::despawn_marked::<editor::EditorUi>,
despawn_board_sprites,
editor::exit_editor,
),
);
app.add_systems(
OnExit(Screen::Puzzle),
(
menu_ui::despawn_marked::<cursor::Cursor>,
despawn_board_sprites,
menu_ui::despawn_marked::<results::ResultsPanel>,
menu_ui::despawn_marked::<effects::Particle>,
announce::clear_announcements,
hint::clear_hint_ghosts,
pause::reset_pause,
achievements::save_now,
),
);
app.add_systems(
OnExit(Screen::Versus),
(
menu_ui::despawn_marked::<cursor::Cursor>,
despawn_board_sprites,
end_versus,
menu_ui::despawn_marked::<results::ResultsPanel>,
menu_ui::despawn_marked::<side_panels::SidePanelRoot>,
menu_ui::despawn_marked::<effects::Particle>,
announce::clear_announcements,
pause::reset_pause,
achievements::save_now,
|mut daily: ResMut<Daily>| daily.active = false,
),
);
}
/// Round outcomes: the puzzle win/lose cards and the versus results.
fn add_phase_transitions(app: &mut App) {
app.add_systems(
OnEnter(Phase::Won),
(
audio::play_win,
results::spawn_puzzle_won.run_if(in_state(Screen::Puzzle)),
progress::record_cleared.run_if(in_state(Screen::Puzzle)),
// After the clear is recorded: the campaign-finished trophy asks
// whether every stage is done, and the last one is this one.
achievements::record_puzzle
.run_if(in_state(Screen::Puzzle))
.after(progress::record_cleared),
),
);
app.add_systems(
OnExit(Phase::Won),
menu_ui::despawn_marked::<results::ResultsPanel>,
);
app.add_systems(
OnEnter(Phase::Lost),
(
audio::play_lose,
hint::record_loss.run_if(in_state(Screen::Puzzle)),
),
);
// A banner raised in the last second of a round would otherwise sit on
// top of the results card; the round is over, the news can go.
app.add_systems(OnEnter(Phase::Won), announce::clear_announcements);
app.add_systems(OnEnter(Phase::Lost), announce::clear_announcements);
app.add_systems(OnEnter(VersusPhase::Over), announce::clear_announcements);
app.add_systems(
OnEnter(VersusPhase::Over),
(
tournament::record_series_round.run_if(in_state(Screen::Versus)),
// The stats before the card: the card quotes today's daily
// best, and it should be the best with this round counted.
// A replay being watched counts for nothing.
achievements::record_round.run_if(in_state(Screen::Versus).and_then(not_watching)),
results::spawn_versus_results.run_if(in_state(Screen::Versus)),
)
.chain(),
);
app.add_systems(
OnExit(VersusPhase::Over),
menu_ui::despawn_marked::<results::ResultsPanel>,
);
}
/// The frame, in order. Every `Update` system belongs to exactly one of
/// these, and the sets are chained, so the order is declared here instead
/// of being implied by a system's position in a hundred-line tuple.
#[derive(SystemSet, Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum Frame {
/// Menus and the screens that only read input.
Ui,
/// Settings pushed out into Bevy: sink volume, UI scale, tick rate.
Apply,
/// Play input, level loading, and the round-outcome checks.
Play,
/// Sprites and particles catching up with the sim.
Render,
/// Consumers of the observed sim-event stream. After `Render` on
/// purpose: the effects read the previous frame's events, as they
/// always have.
Events,
/// HUD text, sidebars, results chrome.
Chrome,
/// Camera, audio, dev hooks: the last word on the frame.
Finish,
}
/// The per-frame schedule: the fixed-timestep sim driver, and the `Update`
/// systems grouped into the [`Frame`] sets.
fn add_frame_systems(app: &mut App) {
app.add_systems(FixedUpdate, advance_sim.run_if(sim_should_run));
// A hosted beach keeps its beacon up for the whole match, not just the
// lobby, so a player arriving late sees a game in progress with a chair
// free rather than an empty network. In `Update` rather than beside the
// sim, because it must go on saying so while the round is paused.
app.add_systems(
Update,
(|time: Res<Time>, mut online: ResMut<net::Online>| {
if let Some(session) = &mut online.0 {
session.keep_announcing(time.delta_secs());
}
})
.in_set(Frame::Play),
);
app.configure_sets(
Update,
(
Frame::Ui,
Frame::Apply,
Frame::Play,
Frame::Render,
Frame::Events,
Frame::Chrome,
Frame::Finish,
)
.chain(),
);
add_ui_systems(app);
add_apply_systems(app);
add_play_systems(app);
add_render_systems(app);
add_event_systems(app);
add_chrome_systems(app);
add_finish_systems(app);
}
/// Menu, lobby, settings, controls and match setup: the screens that only
/// read input and repaint their own rows.
fn add_ui_systems(app: &mut App) {
app.add_systems(
Update,
(
gamepad::pad_menu_bridge.run_if(
in_state(Screen::Menu)
.or_else(in_state(Screen::Settings))
.or_else(in_state(Screen::Controls))
.or_else(in_state(Screen::MatchSetup))
.or_else(in_state(Screen::Lobby))
.or_else(in_state(Screen::StageSelect))
.or_else(in_state(Screen::Language))
.or_else(in_state(Screen::NewVersion))
.or_else(versus_over)
.or_else(
in_state(Screen::Puzzle)
.and_then(in_state(Phase::Won).or_else(in_state(Phase::Lost))),
),
),
// The check's answer is read on the menu, and a newer release
// takes the menu to the page. Before the menu's own input, so
// the two never both set the screen from one keypress.
(
update::poll_check,
menu_scene::menu_input,
menu_scene::update_menu_rows,
)
.chain()
.run_if(in_state(Screen::Menu)),
(update::new_version_input, update::update_new_version_rows)
.chain()
.run_if(in_state(Screen::NewVersion)),
(
lobby::discover,
lobby::host_tick,
lobby::join_tick,
lobby::lobby_input,
lobby::update_lobby_list,
lobby::update_lobby_view,
lobby::update_lobby_players,
lobby::update_lobby_terms,
lobby::update_lobby_beach_note,
lobby::update_lobby_chat,
)
.chain()
.run_if(in_state(Screen::Lobby)),
(
settings::screen::settings_input,
settings::screen::update_settings_ui,
)
.chain()
.run_if(in_state(Screen::Settings)),
(controls::controls_input, controls::update_controls_ui)
.chain()
.run_if(in_state(Screen::Controls)),
(
stage_select::stage_select_input,
stage_select::update_stage_tiles,
)
.chain()
.run_if(in_state(Screen::StageSelect)),
(replays::library_input, replays::update_library)
.chain()
.run_if(in_state(Screen::Replays)),
(
language::language_input,
language::update_language_ui,
language::animate_language_art,
)
.chain()
.run_if(in_state(Screen::Language)),
replays::playback_speed_input.run_if(in_state(Screen::Versus)),
(
gamepad::pad_claim_seats,
match_setup::match_setup_input,
match_setup::update_match_ui,
match_setup::update_match_pad_info,
)
.chain()
.run_if(in_state(Screen::MatchSetup)),
)
.chain()
.in_set(Frame::Ui),
);
}
/// Settings reaching the engine, and the two small input reactions.
fn add_apply_systems(app: &mut App) {
app.add_systems(
Update,
(
cursor::flash_cursors,
audio::play_denied,
settings::apply_music_volume,
settings::apply_accessibility,
settings::apply_sim_speed,
)
.chain()
.in_set(Frame::Apply),
);
}
/// Play: level loading, cursors, the editor, pauses, and the checks that
/// end a round.
fn add_play_systems(app: &mut App) {
app.add_systems(
Update,
(
handle_load_level,
hint::reset_on_level.run_if(on_message::<LoadLevel>),
cursor::move_cursor
.run_if(not(in_state(Screen::Menu)).and_then(not(editor::editor_naming))),
cursor::setup_input.run_if(puzzle_setup),
dev::debug_autoplay.run_if(puzzle_setup),
hint::hint_input.run_if(puzzle_setup.or_else(puzzle_done)),
hint::draw_hint.run_if(in_state(Screen::Puzzle)),
cursor::running_input.run_if(puzzle_running),
cursor::done_input.run_if(puzzle_done),
check_outcome.run_if(puzzle_running),
cursor::versus_input.run_if(versus_running),
suspend::copy_round_code.run_if(versus_running),
dev::debug_net_probe.run_if(versus_running),
dev::debug_banner.run_if(versus_running.or_else(puzzle_running)),
// Paired into one slot: the list is at Bevy's twenty-element
// limit. Both only do anything with their variable set.
(dev::debug_tide, dev::debug_lure).run_if(versus_running.or_else(puzzle_running)),
// A player who stops sending holds the whole table on one
// frame. The host gives up on them after a while and hands the
// seat to an AI; every peer does it on the host's word, so they
// all do it on the same frame and stay in step. And when it is
// the *host* that has gone, no word is coming and no seat can
// be filled: the round is over and the joiners are told so
// rather than left watching a still beach. Paired into tuple
// slots because the list around it is at Bevy's limit.
(
check_versus_over,
net::abandon_the_departed,
net::leave_a_hostless_round,
)
.run_if(versus_running),
// The sim is stopped on the results card, so the session has to
// be drained by hand: this is when a latecomer greets to queue
// and when the host's next-round invitation arrives. Chained
// ahead of the input, so an invitation that lands this frame is
// acted on this frame.
// The host can vanish while the card is up as easily as during
// a round, and the card is where a table sits longest. Last in
// the chain, so its notice is the one that survives a frame
// where the player was pressing Enter anyway.
(
net::poll_between_rounds,
cursor::versus_over_input,
net::leave_a_hostless_round,
)
.chain()
.run_if(versus_over),
// `editor_input` is what types the name, so it runs while naming;
// the command keys do not, or the letters of a name would flip
// wrap and start the solver, and Enter would begin a playtest.
(
editor::editor_input,
editor::editor_commands.run_if(not(editor::editor_naming)),
)
.chain()
.run_if(in_state(Screen::Editor).and_then(not(editor::editor_testing))),
editor::editor_test_input
.run_if(in_state(Screen::Editor).and_then(editor::editor_testing)),
// Paired into one slot because the list around it is at Bevy's
// twenty-element limit.
(
editor::poll_solver,
editor::update_editor_palette,
editor::rebuild_statics,
)
.run_if(in_state(Screen::Editor)),
)
.chain()
.in_set(Frame::Play),
);
app.add_systems(
Update,
(
gamepad::pad_move_cursor
.run_if(not(in_state(Screen::Menu)).and_then(not(editor::editor_naming))),
gamepad::pad_setup_input.run_if(puzzle_setup),
gamepad::pad_versus_input.run_if(versus_running),
(pause::pause_input, pause::update_pause_rows)
.chain()
.run_if(play_screens),
)
.chain()
.in_set(Frame::Play)
.after(editor::rebuild_statics),
);
}
/// Everything that redraws the board from sim state.
fn add_render_systems(app: &mut App) {
app.add_systems(
Update,
(
board_render::sync_signposts,
board_render::sync_turnstiles,
board_render::sync_castles,
board_render::kick_castles,
// After the kick, which also writes scale: a bank landing in
// the same frame as a swap must not fight the flight.
board_render::fly_castles,
board_render::wave_pennants,
creatures::sync_crab_sprites,
creatures::sync_gull_sprites,
creatures::interpolate_crabs,
creatures::interpolate_gulls,
board_render::update_waterline,
board_render::update_water_foam,
board_render::pulse_spawners,
board_render::animate_turnstiles,
effects::moment_effects,
effects::crab_trails,
)
.chain()
.run_if(board_screens)
.in_set(Frame::Render),
);
}
/// The sim observer and its consumers, plus the ambient screens.
fn add_event_systems(app: &mut App) {
app.add_systems(
Update,
(
sim_events::observe_sim.run_if(board_screens),
audio::play_events,
achievements::track_events.run_if(play_screens.and_then(not_watching)),
(
announce::collect_announcements,
announce::drive_announcements,
)
.chain()
.run_if(play_screens),
achievements::record_level_built.run_if(in_state(Screen::Editor)),
achievements::update_toasts,
achievements::achievements_input.run_if(in_state(Screen::Achievements)),
tournament::interlude_tick.run_if(in_state(Screen::Interlude)),
menu_scene::menu_ambience.run_if(in_state(Screen::Menu)),
menu_scene::refit_shore.run_if(in_state(Screen::Menu)),
)
.chain()
.in_set(Frame::Events),
);
}
/// The readouts: header, sidebars, clocks, hints.
fn add_chrome_systems(app: &mut App) {
app.add_systems(
Update,
(
hud::update_hud,
hud::header_backdrop,
hud::field_guide_visibility,
hud::update_field_guide,
side_panels::update_side_panels,
side_panels::update_side_clock.run_if(in_state(Screen::Versus)),
side_panels::collect_log.run_if(in_state(Screen::Versus)),
side_panels::update_log,
hud::update_tide_clock,
hud::update_hint,
// The reel lands after the card is up; the card's line waits.
(poll_reel, results::update_highlight_line)
.chain()
.run_if(versus_over),
)
.chain()
.in_set(Frame::Chrome),
);
}
/// Particles, camera, music, and the screenshot hook.
fn add_finish_systems(app: &mut App) {
app.add_systems(
Update,
(
effects::update_particles,
// Until it lands: the font it names is registered by a system
// of Bevy's own, and is not there to be named before that has
// run once.
boot::teach_the_kanji_fallback,
boot::fit_camera,
audio::toggle_music,
audio::rotate_music,
audio::surge_tempo,
dev::debug_screenshot,
)
.chain()
.in_set(Frame::Finish),
);
}
// Named run conditions: the schedule reads as prose instead of nested
// state combinators.
fn versus_running(screen: Res<State<Screen>>, phase: Res<State<VersusPhase>>) -> bool {
*screen.get() == Screen::Versus && *phase.get() == VersusPhase::Running
}
fn versus_over(screen: Res<State<Screen>>, phase: Res<State<VersusPhase>>) -> bool {
*screen.get() == Screen::Versus && *phase.get() == VersusPhase::Over
}
fn puzzle_setup(screen: Res<State<Screen>>, phase: Res<State<Phase>>) -> bool {
*screen.get() == Screen::Puzzle && *phase.get() == Phase::Setup
}
fn puzzle_running(screen: Res<State<Screen>>, phase: Res<State<Phase>>) -> bool {
*screen.get() == Screen::Puzzle && *phase.get() == Phase::Running
}
fn puzzle_done(screen: Res<State<Screen>>, phase: Res<State<Phase>>) -> bool {
*screen.get() == Screen::Puzzle && matches!(*phase.get(), Phase::Won | Phase::Lost)
}
use session::*;