-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathloader_system.rs
More file actions
89 lines (82 loc) · 2.88 KB
/
Copy pathloader_system.rs
File metadata and controls
89 lines (82 loc) · 2.88 KB
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
use crate::{
consoles::SparseConsole, fonts::FontStore, BTermBuilder, BracketContext, SimpleConsole,
TerminalLayer,
};
use bevy::{
prelude::{
AssetServer, Assets, Camera2dBundle, Commands, Component, HandleUntyped, Mesh, Res, ResMut,
},
sprite::ColorMaterial,
};
use super::image_fixer::ImagesToLoad;
#[derive(Component)]
pub struct BracketCamera;
pub(crate) fn load_terminals(
context: Res<BTermBuilder>,
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
if context.with_ortho_camera {
commands
.spawn(Camera2dBundle::default())
.insert(BracketCamera);
}
// Setup the new context
let mut new_context = BracketContext::new(context.palette.clone());
new_context.scaling_mode = context.scaling_mode;
// Load the fonts
let mut texture_handles = Vec::<HandleUntyped>::new();
for font in context.fonts.iter() {
let texture_handle = asset_server.load(&font.filename);
let material_handle = materials.add(ColorMaterial::from(texture_handle.clone()));
texture_handles.push(texture_handle.clone_untyped());
new_context.fonts.push(FontStore::new(
texture_handle,
material_handle,
font.chars_per_row,
font.n_rows,
font.font_height_pixels,
));
}
commands.insert_resource(ImagesToLoad(texture_handles));
// Setup the consoles
for (idx, terminal) in context.layers.iter().enumerate() {
match terminal {
TerminalLayer::Simple {
font_index,
width,
height,
features,
} => {
let mut console = SimpleConsole::new(*font_index, *width, *height);
console.initialize(&new_context.fonts, &mut meshes, features);
console.spawn(
&mut commands,
new_context.fonts[*font_index].material_handle.clone(),
idx,
);
new_context.terminals.lock().push(Box::new(console));
}
TerminalLayer::Sparse {
font_index,
width,
height,
features,
} => {
let mut console = SparseConsole::new(*font_index, *width, *height);
console.initialize(&new_context.fonts, &mut meshes, features);
console.spawn(
&mut commands,
new_context.fonts[*font_index].material_handle.clone(),
idx,
);
new_context.terminals.lock().push(Box::new(console));
}
}
}
// Clean up after the building process
commands.remove_resource::<BTermBuilder>();
commands.insert_resource(new_context);
}