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
//! The Bevy plugin for brink ink stories.
use std::marker::PhantomData;
use bevy_app::{App, Plugin, Update};
use bevy_asset::AssetApp;
use bevy_ecs::schedule::IntoScheduleConfigs as _;
#[cfg(feature = "dev")]
use bevy_log::warn;
use brink_runtime::{ExecMode, WorldPolicy};
use crate::asset::{BrinkStoryAsset, InkbLoader, LineTablesAsset, ProgramAsset};
use crate::globals::{BrinkExecMode, BrinkWorldPolicy};
use crate::request::fulfill_flow_requests;
/// A Bevy plugin that registers brink story types, messages, and asset
/// loaders for a single story instance identified by the marker type `M`.
///
/// The default `M = ()` suits the common single-story case. Declare your
/// own marker types (any `Send + Sync + 'static` ZST works) when you need
/// multiple concurrent stories in one app — each gets its own
/// `BrinkGlobals<M>` resource and `BrinkFlow<M>`/`BrinkContext<M>`/
/// `BrinkLocale<M>` components, monomorphized to distinct Bevy types
/// with no runtime overhead.
///
/// Adding `BrinkPlugin<M>` also ensures [`BrinkAssetsPlugin`] is added
/// once to the app (for shared asset types that don't depend on `M`).
///
/// **This plugin does not register an auto-advance system.** Most games
/// drive advancement from input or game-state events, not every tick.
/// Apps that want per-tick advancement can drive
/// [`advance_flow`](crate::advance_flow) — which needs `&mut World` plus
/// the flow's `Entity`, so it can't be registered directly — from their
/// own exclusive system:
///
/// ```no_run
/// # use bevy_app::{App, Update};
/// # use bevy_ecs::prelude::*;
/// # use bevy_brink::{BrinkFlow, advance_flow};
/// # struct MyStory;
/// # let mut app = App::new();
/// fn advance_all_flows(world: &mut World) {
/// let entities: Vec<Entity> = world
/// .query_filtered::<Entity, With<BrinkFlow<MyStory>>>()
/// .iter(world)
/// .collect();
/// for entity in entities {
/// let _ = advance_flow::<MyStory>(world, entity);
/// }
/// }
/// app.add_systems(Update, advance_all_flows);
/// ```
pub struct BrinkPlugin<M: Send + Sync + 'static = ()> {
policy: WorldPolicy,
exec_mode: ExecMode,
// #1029: out-of-band `ProjectConfig` override, threaded to the dev-mode
// `InkLoader` (via `BrinkAssetsPlugin`) when this plugin is the one that
// adds it. `dev`-only: the config only matters to the source-compiling
// asset loader, which doesn't exist without the `dev` feature.
#[cfg(feature = "dev")]
config: Option<brink_project_config::ProjectConfig>,
_marker: PhantomData<fn() -> M>,
}
impl<M: Send + Sync + 'static> Default for BrinkPlugin<M> {
fn default() -> Self {
Self {
policy: WorldPolicy::default(),
// F35 (ruled 2026-07-19): profile-keyed default via
// `BrinkExecMode::default` — `Dev` under debug_assertions, `Prod`
// in release. Diverges from core `ExecMode::default` (always
// `Dev`); a host overrides with `with_exec_mode`.
exec_mode: BrinkExecMode::<M>::default().mode,
#[cfg(feature = "dev")]
config: None,
_marker: PhantomData,
}
}
}
impl<M: Send + Sync + 'static> BrinkPlugin<M> {
/// Install a host-supplied [`WorldPolicy`] for this marker's shared
/// [`BrinkGlobals<M>`](crate::BrinkGlobals) `World` — resolved once,
/// against the first-fulfilled flow's program, when
/// [`fulfill_flow_requests`](crate::fulfill_flow_requests) creates it.
///
/// Default (if this is never called): `WorldPolicy::default()` — every
/// unit homed to `World`, byte-identical to plain ink. Per the F6
/// AMENDMENT (`docs/scoped-flow-state-spec.md`): the plain-ink default
/// stays `World`; hosts opt a per-entity NPC into private state by
/// enumerating `Local` overrides on top, not by flipping the default.
///
/// A [`PolicyError`](brink_runtime::PolicyError) (an override names a
/// variable or knot/stitch the program doesn't declare) surfaces as a
/// logged fulfillment error on the offending request, not a panic — see
/// `fulfill_flow_requests`.
#[must_use]
pub fn with_policy(mut self, policy: WorldPolicy) -> Self {
self.policy = policy;
self
}
/// Override the [`ExecMode`] every flow of this marker starts in (F35,
/// ruled 2026-07-19).
///
/// Default (if this is never called): the build-profile-keyed value —
/// [`ExecMode::Dev`] under `debug_assertions`, [`ExecMode::Prod`] in a
/// release build (see [`BrinkExecMode`](crate::BrinkExecMode)). Call this
/// to pin a mode regardless of profile — e.g. `with_exec_mode(ExecMode::Dev)`
/// to keep the fault-loud posture in a release editor build, or
/// `with_exec_mode(ExecMode::Prod)` to run keep-moving in a debug build.
///
/// The mode is a host/build knob, never embedded in `.inkb` and never
/// persisted in saves; a per-flow override is still available at runtime
/// via [`FlowInstance::set_exec_mode`](brink_runtime::FlowInstance::set_exec_mode).
#[must_use]
pub fn with_exec_mode(mut self, mode: ExecMode) -> Self {
self.exec_mode = mode;
self
}
/// Override the [`ProjectConfig`](brink_project_config::ProjectConfig)
/// the dev-mode [`InkLoader`](crate::InkLoader) uses for stories
/// compiled under this marker (#1029).
///
/// The **programmatic escape hatch**: it wins over whatever `brink.toml`
/// the loader's bounded asset walk-up discovers beside the entry story —
/// for packed/embedded builds where there's no meaningful sibling file,
/// or for a host that simply prefers configuring dialect/types in game
/// code. Fields left `None` on the given [`ProjectConfig`] still fall
/// through to whatever the discovered `brink.toml` (or the built-in
/// default) supplies — same "only touch what you set" precedence as the
/// CLI's `--dialect`/`--types` flags
/// (`AnalysisOptions::apply_project_config`).
///
/// Only takes effect if this is the [`BrinkPlugin<M>`] instance that
/// ends up adding [`BrinkAssetsPlugin`] (the first one, per marker
/// registration order) — later markers' overrides are ignored once
/// `BrinkAssetsPlugin` already exists in the app, same as every other
/// `BrinkAssetsPlugin`-owned setting. Call
/// [`BrinkAssetsPlugin::with_config`] directly instead if you're adding
/// it standalone. A dropped later-marker override is not silent (issue
/// #1382 sweep): [`Plugin::build`](Plugin) surfaces it through the same
/// two channels an unrecognized `[lints]` code uses two paragraphs
/// down — a `tracing::warn!` naming the marker type, and an entry
/// appended to [`BrinkConfigWarnings`](crate::BrinkConfigWarnings) — so
/// a host that adds two `BrinkPlugin<M>`s with conflicting `with_config`
/// calls finds out, rather than silently getting the first one's policy
/// for every marker.
///
/// This override also reaches
/// [`compile_story_inline`](crate::compile_story_inline) (#1380) — but
/// only once `Plugin::build` has actually run, i.e. only *after*
/// `app.add_plugins(BrinkPlugin::<M>::default().with_config(...))`
/// returns. Calling `compile_story_inline` before that `add_plugins`
/// call silently compiles under `OptionOverrides::default()` instead —
/// see `compile_story_inline`'s doc comment for the ordering hazard in
/// full.
///
/// Also covers the `[lints]` tier (issue #1394): a `[lints]` table or
/// `deny-warnings` value set on the passed `ProjectConfig` wins over the
/// same table in a discovered `brink.toml`, mirroring the CLI's
/// `--deny`/`--warn`/`--allow`/`-D warnings` flags (issue #1373) —
/// `InkLoader` forwards `config.lints`/`.deny_warnings` into the same
/// [`OptionOverrides`](brink_environment::OptionOverrides) seam used for
/// `dialect`/`types`, so `Project::load` folds everything in at one
/// resolution point (`AnalysisOptions::apply_lint_overrides`).
/// (Previously scoped to `dialect`/`types` only per the issue #1382
/// audit — that gap is what #1394 closed.)
///
/// An unknown code (not a real `DiagnosticCode`) or a non-overridable
/// one (a code whose *base* severity isn't `Warning`) in `config.lints`
/// is never silently applied — `apply_lint_overrides` rejects it and
/// `Project::load` surfaces the rejection via `tracing::warn!` (issue
/// #1416), the same "warn, never drop" channel every other mount's
/// `[lints]` handling uses. Since `bevy_log`'s logging macros are
/// `tracing`'s own, re-exported verbatim, and `LogPlugin` installs a
/// process-wide `tracing` subscriber, a typo'd code here surfaces on a
/// bevy author's console the same way it would from the CLI or a served
/// `brink.toml` — no extra wiring needed, but see
/// `plugin_override_unknown_and_non_overridable_lint_codes_warn_but_valid_entry_still_applies`
/// (`source_loader.rs`) for the regression proof. **Also** readable
/// without a logger, as [`BrinkConfigWarnings`](crate::BrinkConfigWarnings)
/// — a headless/embedding host that never installs `bevy_log` still gets
/// the rejection (issue #1426).
#[cfg(feature = "dev")]
#[must_use]
pub fn with_config(mut self, config: brink_project_config::ProjectConfig) -> Self {
self.config = Some(config);
self
}
}
impl<M: Send + Sync + 'static> Plugin for BrinkPlugin<M> {
fn build(&self, app: &mut App) {
let assets_already_present = app.is_plugin_added::<BrinkAssetsPlugin>();
if !assets_already_present {
#[cfg(feature = "dev")]
let assets_plugin =
BrinkAssetsPlugin::default().with_config_option(self.config.clone());
#[cfg(not(feature = "dev"))]
let assets_plugin = BrinkAssetsPlugin::default();
app.add_plugins(assets_plugin);
}
// Issue #1382 sweep: `Self::with_config`'s own doc comment already
// documented that a *second* `BrinkPlugin<M>` registration's
// override is ignored once `BrinkAssetsPlugin` already exists (only
// the marker whose plugin actually adds it gets to set the shared
// `InkLoader`'s config) — but until now that drop reached neither
// the `tracing::warn!` channel every other mount's "warn, never
// silently drop" precedent uses, nor `BrinkConfigWarnings` (#1426's
// headless-host escape hatch for hosts with no `tracing`
// subscriber installed) — exactly the gap `BrinkConfigWarnings`'s
// own doc comment used to call out as unresolved. Diagnosed on
// both channels now, matching every other silent-drop fix in this
// sweep (#1394/#1416/#1417).
#[cfg(feature = "dev")]
if assets_already_present && self.config.is_some() {
let message = format!(
"BrinkPlugin::<{}>::with_config's ProjectConfig override was \
ignored: BrinkAssetsPlugin was already added to this app (by \
an earlier BrinkPlugin<M> registration, or added directly) — \
only the BrinkPlugin<M>/BrinkAssetsPlugin instance that \
actually adds BrinkAssetsPlugin can set the shared \
InkLoader's config override. Call BrinkAssetsPlugin::with_config \
directly before adding any BrinkPlugin<M>, or set the override \
on whichever BrinkPlugin<M> is added to the app first.",
std::any::type_name::<M>()
);
warn!("{message}");
if let Some(mut warnings) = app
.world_mut()
.get_resource_mut::<crate::config_warnings::BrinkConfigWarnings>()
{
warnings.0.push(message);
}
}
app.insert_resource(BrinkWorldPolicy::<M>::new(self.policy.clone()));
// F35 (ruled 2026-07-19): the host-selected (or profile-defaulted)
// ExecMode every flow of marker `M` spawns in. Applied to each
// FlowInstance at creation by `fulfill_flow_requests`.
app.insert_resource(BrinkExecMode::<M>::new(self.exec_mode));
app.add_systems(Update, fulfill_flow_requests::<M>);
// T1d-3 handle integration (docs/t1d-spec.md §4): the type-erased
// kind index (empty until a host calls `register_handle_kind`) and
// its diagnostics-only retention metrics, the `is_valid(h)` binding
// (a standard world-query binding per spec, not a language
// intrinsic), and registry GC at `-> DONE` quiescent sweeps.
app.init_resource::<crate::handle::HandleKinds<M>>();
app.init_resource::<crate::handle::HandleRetentionMetrics<M>>();
app.init_resource::<crate::handle::HandleEntityRemap>();
{
use crate::bindings::BrinkBindingsAppExt as _;
app.bind_brink_query::<M, _, _>("is_valid", crate::handle::is_valid_system::<M>);
}
app.add_observer(crate::handle::gc_on_turn_done::<M>);
// BH-1 (docs/effects-spec.md §9, §12–§13; #899): the capability
// registry (name -> ComponentId, empty until `register_capability`
// is called) and the per-story joined-access table, rebuilt whenever
// a `ProgramAsset` loads/unloads (§12.5's load-boundary invariant).
// `CapabilityManifest` inits empty too — a host that never inserts
// one just never gets ECS-capability access data.
app.init_resource::<crate::capability::CapabilityManifest>();
app.init_resource::<crate::capability::CapabilityRegistry<M>>();
app.init_resource::<crate::capability::CapabilityTable<M>>();
// BH detect path (docs/effects-spec.md §12.5; #996): the per-frame,
// per-capability change verdict `mark_wake_dirty` reads. Always present
// so the wake layer can take it as a plain `Res`; each
// `register_capability` call also wires the typed tracker that fills it.
app.init_resource::<crate::capability::CapabilityChanges<M>>();
app.add_systems(Update, crate::capability::rebuild_capability_table::<M>);
// BH-2 (docs/effects-spec.md §12.4; #914): the batch-turn report
// resource, always present so a host that opts into
// `advance_batch::<M>` (not auto-registered — batch mode is opt-in,
// like `advance_flows`) gets its per-flow capability/access bookkeeping
// recorded. The batch driver itself is NOT added here; a host adds
// `app.add_systems(Update, advance_batch::<M>)` when it wants
// frame-start-consistent batched stepping.
app.init_resource::<crate::batch::BrinkBatchReport<M>>();
// Issue #1146 (the #1101 fix): the row-directed wake-dirtying ledger.
// A batch turn's Apply records *which* shared-world cells it wrote;
// `mark_wake_dirty` drains it and re-evaluates only the parked
// policies whose condition's effect read row intersects that set.
// Always present so a host that opts into `advance_batch::<M>` /
// `advance_batch_parallel::<M>` gets the precision automatically;
// without a batch driver it simply never records and the wake pass
// stays on the coarse `BrinkGlobals` change bit.
app.init_resource::<crate::wake_delta::BrinkWorldDelta<M>>();
// BH-4 (docs/effects-spec.md §13.1; #973): reactive sleep. `FlowSleep`
// is a standing wake policy on a flow entity; parked flows are skipped
// by Collect (`advance_batch`). `mark_wake_dirty` consults the `#913`
// detect verdict + `BrinkGlobals` change detection to flag which parked
// conditions need re-evaluation; `run_flow_sleep` (exclusive — it
// re-enters the VM via `call_ink_function`) re-evaluates flagged
// conditions in each flow's own context and wakes on true. Gated so
// neither does work until a flow actually sleeps. Ordered
// dirty-then-eval so a same-frame World change is seen this pass.
//
// `.before(advance_batch::<M>)` closes a same-frame race discovered
// while hardening issue #1081's `WakeArming::Latch` tests: `Collect`
// — in either driver — steps any flow whose `FlowSleep::wants_collect()`
// is true (`state == Woken`), and only `run_flow_sleep`'s repark
// phase clears that back to `Parked` once the woken turn reaches a
// `Done` boundary. Without an explicit order, a host that also
// registers `advance_batch::<M>` leaves the two system sets
// unconstrained relative to each other — Bevy's default multithreaded
// executor does not guarantee a stable relative order between
// independently-added systems that don't conflict on data access, so
// it can (rarely) run `advance_batch` before this chain on one frame
// and after it on the next. That window lets a flow that woke and
// was collected on frame N (still `Woken`, not yet reparked because
// `run_flow_sleep` hadn't run again) get collected a **second** time
// on frame N+1 if `advance_batch` happens to run before this chain
// that frame — an extra, spurious turn from a single wake, the exact
// "over-fire" `wake_fan_out` scenario tests never exercised (they
// don't assert an exact repeated count across many cycles the way
// the `Latch` cycling test does). Forcing this chain before
// `advance_batch` guarantees the repark for a completed wake is
// always applied in the same frame the wake was collected, before
// `advance_batch` gets another chance to run — closing the window
// regardless of scheduler ordering. Inert if the host never adds
// `advance_batch::<M>` (an ordering constraint against an absent
// system is a no-op).
//
// The same constraint is placed against `advance_batch_parallel::<M>`:
// without it, the parallel driver is unconstrained relative to this
// chain, so the module docs' "the wake pass is ordered before it"
// claim (`crate::wake_delta`, `record_wake_delta`'s doc in
// `crate::batch`, `mark_wake_dirty`'s doc) would not actually hold for
// a host that opts into the parallel driver. Ordering costs precision
// only (an unordered parallel driver still never under-reports), but
// pinning it keeps the doc claim true for every driver, not just the
// serial one. Inert if the host never adds
// `advance_batch_parallel::<M>`.
app.add_systems(
Update,
(
crate::sleep::mark_wake_dirty::<M>,
crate::sleep::run_flow_sleep::<M>,
)
.chain()
.before(crate::batch::advance_batch::<M>)
.before(crate::batch::parallel::advance_batch_parallel::<M>)
.run_if(
bevy_ecs::schedule::common_conditions::any_with_component::<
crate::sleep::FlowSleep<M>,
>,
),
);
// Auto-render BrinkTranscript<M> for any flow that has it.
// No-op for flows that don't (the query just yields nothing).
app.add_systems(Update, crate::transcript::refresh_transcripts::<M>);
register_deferred_call_resolvers::<M>(app);
// Service flows that paused on a pending external during normal
// playback (a non-exclusive step_one yielded AwaitingQuery): resolve
// world-access queries inline, fire BrinkExternalAwaited for async
// (event) bindings, spawn tasks for task bindings. Exclusive (needs
// &mut World), gated so it only runs when a flow is actually awaiting.
app.add_systems(
Update,
crate::bindings::resolve_pending_externals::<M>
.run_if(crate::bindings::any_flow_awaiting_external::<M>),
);
// Poll detached bind_brink_task futures; resolve the flow when one
// finishes. Gated so it only runs while a task is pending.
app.add_systems(
Update,
crate::async_bind::poll_brink_tasks::<M>.run_if(
bevy_ecs::schedule::common_conditions::any_with_component::<
crate::async_bind::BrinkPendingTask<M>,
>,
),
);
// Global, event-driven locale switching: the current-locale resource,
// an observer that reconciles flows when it changes, and a catch-up
// system for `.inkl`s that finish loading after a switch.
app.init_resource::<crate::locale::BrinkCurrentLocale<M>>();
app.init_resource::<crate::locale::LocalizedTablesCache<M>>();
app.add_observer(crate::locale::on_locale_changed::<M>);
app.add_systems(Update, crate::locale::catch_up_loaded_locales::<M>);
#[cfg(feature = "dev")]
app.init_resource::<crate::replay::BrinkReplayConfig>();
#[cfg(feature = "dev")]
app.add_systems(Update, crate::replay::replay_on_reload::<M>);
#[cfg(debug_assertions)]
app.add_systems(Update, crate::request::warn_post_fulfillment_mutations::<M>);
}
}
/// Registers the two exclusive resolvers for deferred engine→ink calls
/// issued from non-exclusive systems: single calls
/// (`commands.brink_call`, [`crate::call::resolve_brink_calls`]) and
/// batches (`commands.brink_call_batch`,
/// [`crate::call::resolve_brink_call_batches`], #1076). Both need `&mut
/// World` to run world-access query bindings, and both are gated so they
/// only run when a request is actually pending. Factored out of
/// [`BrinkPlugin::build`] to keep it under clippy's line-count lint.
fn register_deferred_call_resolvers<M: Send + Sync + 'static>(app: &mut App) {
app.add_systems(
Update,
crate::call::resolve_brink_calls::<M>.run_if(
bevy_ecs::schedule::common_conditions::any_with_component::<
crate::call::BrinkCallRequest<M>,
>,
),
);
// Each pending batch runs through a single call_ink_functions call, so
// its front-to-back ordering guarantee holds for the deferred path too,
// not just the exclusive one. (call_ink_functions also amortizes one
// VM-eval setup across the batch's calls, but that's a cost saving —
// ordering is pinned by the whole list arriving and running
// sequentially in one request, not by the setup itself.)
app.add_systems(
Update,
crate::call::resolve_brink_call_batches::<M>.run_if(
bevy_ecs::schedule::common_conditions::any_with_component::<
crate::call::BrinkCallBatchRequest<M>,
>,
),
);
}
/// Registers asset types and loaders that are shared across all markers.
///
/// [`BrinkPlugin::build`] adds this automatically if it's not already
/// present, so you rarely need to add it manually — but you can if you
/// want the asset machinery without any marker-specific plumbing (e.g.
/// for a headless asset-processing binary).
#[derive(Default)]
pub struct BrinkAssetsPlugin {
// #1029: threaded to the dev-mode `InkLoader` (see `BrinkPlugin::with_config`
// for the full precedence contract). `dev`-only for the same reason
// `BrinkPlugin::config` is.
#[cfg(feature = "dev")]
config: Option<brink_project_config::ProjectConfig>,
}
impl BrinkAssetsPlugin {
/// Override the `brink.toml`-sourced [`ProjectConfig`](brink_project_config::ProjectConfig)
/// the dev-mode [`InkLoader`](crate::InkLoader) uses (#1029) — the
/// standalone-plugin equivalent of [`BrinkPlugin::with_config`], for
/// hosts that add `BrinkAssetsPlugin` directly (e.g. a headless
/// asset-processing binary) without going through `BrinkPlugin<M>`.
///
/// An unknown or non-overridable code in `config.lints` is never
/// silently applied — [`build`](Plugin::build) inserts
/// [`BrinkConfigWarnings`](crate::BrinkConfigWarnings) with the
/// rejection eagerly, at plugin-build time, so a headless host that
/// never installs `bevy_log`/a `tracing` subscriber still gets it
/// (issue #1426).
#[cfg(feature = "dev")]
#[must_use]
pub fn with_config(mut self, config: brink_project_config::ProjectConfig) -> Self {
self.config = Some(config);
self
}
/// Same as [`Self::with_config`] but takes the already-`Option`al form
/// `BrinkPlugin::build` holds, so it can thread its own (possibly unset)
/// override through without an `if let` at the call site.
#[cfg(feature = "dev")]
#[must_use]
fn with_config_option(mut self, config: Option<brink_project_config::ProjectConfig>) -> Self {
self.config = config;
self
}
}
impl Plugin for BrinkAssetsPlugin {
fn build(&self, app: &mut App) {
app.init_asset::<BrinkStoryAsset>();
app.init_asset::<ProgramAsset>();
app.init_asset::<LineTablesAsset>();
app.init_asset::<crate::locale::LocaleAsset>();
app.init_asset::<crate::brkt::TranscriptAsset>();
app.init_asset_loader::<InkbLoader>();
app.init_asset_loader::<crate::locale::InklLoader>();
app.init_asset_loader::<crate::brkt::BrktLoader>();
#[cfg(feature = "dev")]
app.register_asset_loader(crate::source_loader::InkLoader {
override_config: self.config.clone(),
});
// #1380: mirror the same override into a resource so
// `compile_story_inline` — a freestanding function with no
// `InkLoader` instance to read a field off of — can see it too.
// Always inserted (even `None`), from the exact same `self.config`
// that seeds `InkLoader` above, so the two entry points can never
// read different values.
#[cfg(feature = "dev")]
app.insert_resource(crate::source_loader::BrinkOverrideConfig(
self.config.clone(),
));
// #1426: the non-log surface for `config.lints`'s rejected codes —
// see `crate::config_warnings`'s module docs. Inserted eagerly, once,
// regardless of whether `self.config` is set or has any lint
// overrides at all (an empty `Vec` is the well-defined "nothing
// rejected" case, not "the check never ran").
#[cfg(feature = "dev")]
app.insert_resource(crate::config_warnings::BrinkConfigWarnings::from_config(
self.config.as_ref(),
));
}
}