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
//! Static-editor build state machine.
//!
//! For **static** game projects the launcher's editor (built into
//! the `jackdaw` binary itself) doesn't carry the user's
//! `MyGamePlugin` types, so the inspector's Add Component picker
//! and PIE Play wouldn't see them. The user runs a separate
//! `<project>/target/debug/editor` binary that statically links
//! their plugin alongside jackdaw's editor stack. The launcher's
//! job for static projects is therefore: build that editor
//! binary, then hand off to it.
//!
//! [`BuildStatus`] tracks where in that lifecycle we are. The
//! launcher's modal (the same one used by the dylib install path)
//! displays progress while [`BuildState::Building`] is active;
//! once [`BuildState::Ready`] fires, the driver in
//! `project_select::drive_static_editor_build` closes the modal,
//! spawns the user's editor binary, and exits the launcher.
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use bevy::prelude::*;
use crate::ext_build::BuildProgress;
/// Single source of truth for whether a static-editor background
/// build is in flight, succeeded, or failed. Read by the status
/// bar, written by the build driver in `project_select`.
#[derive(Resource, Default)]
pub struct BuildStatus {
pub state: BuildState,
}
/// The four states the status bar's right region renders. The
/// `Idle` variant lets the existing gizmo / edit-mode rendering
/// fall through unchanged.
#[derive(Default)]
pub enum BuildState {
#[default]
Idle,
/// Cargo is running. `progress` is the same `Arc<Mutex<…>>`
/// the cargo reader threads write into; the status bar reads
/// `current_crate` + `artifacts_done`/`total` to render the
/// "Compiling X (12/47)" string.
Building {
project: PathBuf,
started: Instant,
progress: Arc<Mutex<BuildProgress>>,
},
/// Build finished successfully. `bin` points at the static
/// editor binary on disk. The driver fires the handoff
/// automatically iff `auto_reload` is `true`; otherwise the
/// user reloads by clicking the footer.
Ready {
project: PathBuf,
bin: PathBuf,
auto_reload: bool,
},
/// Build failed. `log_tail` is the last few lines of cargo's
/// stderr, surfaced via the click handler so the user can
/// figure out what to fix.
Failed { project: PathBuf, log_tail: String },
}