aboutsummaryrefslogtreecommitdiff
path: root/src/components.rs
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2024-04-26 01:27:13 -0400
committerLibravatar Silas Bartha <[email protected]>2024-04-26 01:27:13 -0400
commit646db8328611f21a5850cc9834b6c72bfdf0c829 (patch)
tree0d65f0c20b70da007aab141cfe6b123119e8c909 /src/components.rs
Initial Commitv0.1.0
Diffstat (limited to 'src/components.rs')
-rw-r--r--src/components.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/components.rs b/src/components.rs
new file mode 100644
index 0000000..560ad89
--- /dev/null
+++ b/src/components.rs
@@ -0,0 +1,72 @@
+use bevy::{
+ prelude::*,
+ render::render_resource::{
+ Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
+ },
+};
+use grex_dither_post_process::components::DitherPostProcessSettings;
+use grex_framebuffer_extract::{
+ components::{ExtractFramebufferBundle, FramebufferExtractDestination},
+ render_assets::FramebufferExtractSource,
+};
+
+#[derive(Component)]
+pub struct TerminalDisplay;
+
+#[derive(Bundle)]
+pub struct TerminalDisplayBundle {
+ _terminal_display: TerminalDisplay,
+ extract_framebuffer_bundle: ExtractFramebufferBundle,
+ dither_post_process_settings: DitherPostProcessSettings,
+ image_handle: Handle<Image>,
+}
+
+impl TerminalDisplayBundle {
+ pub fn new(dither_level: u32, asset_server: &AssetServer) -> Self {
+ let terminal_size = crossterm::terminal::size().unwrap();
+ let size = Extent3d {
+ width: (terminal_size.0 as u32) * 2,
+ height: (terminal_size.1 as u32) * 4,
+ depth_or_array_layers: 1,
+ };
+
+ let mut image = Image {
+ texture_descriptor: TextureDescriptor {
+ label: None,
+ size,
+ dimension: TextureDimension::D2,
+ format: TextureFormat::R8Unorm,
+ mip_level_count: 1,
+ sample_count: 1,
+ usage: TextureUsages::TEXTURE_BINDING
+ | TextureUsages::COPY_SRC
+ | TextureUsages::RENDER_ATTACHMENT,
+ view_formats: &[],
+ },
+ ..default()
+ };
+
+ image.resize(size);
+ let image_handle = asset_server.add(image);
+
+ let framebuffer_extract_source =
+ asset_server.add(FramebufferExtractSource(image_handle.clone()));
+
+ Self {
+ _terminal_display: TerminalDisplay,
+ extract_framebuffer_bundle: ExtractFramebufferBundle {
+ source: framebuffer_extract_source,
+ dest: FramebufferExtractDestination::default(),
+ },
+ image_handle,
+ dither_post_process_settings: DitherPostProcessSettings::new(
+ dither_level,
+ asset_server,
+ ),
+ }
+ }
+
+ pub fn image_handle(&self) -> Handle<Image> {
+ self.image_handle.clone()
+ }
+}