1use crate::prelude::{Console, DrawBatch, FontCharType};
2use bracket_color::prelude::{ColorPair, RGBA};
3use bracket_geometry::prelude::Point;
4pub use bracket_rex::prelude::{XpCell, XpColor, XpFile, XpLayer};
5
6pub fn xp_to_console(
8 xp: &XpFile,
9 mut console: impl AsMut<dyn Console>,
10 offset_x: i32,
11 offset_y: i32,
12) {
13 for layer in &xp.layers {
14 for y in 0..layer.height {
15 for x in 0..layer.width {
16 let cell = layer.get(x, y).unwrap();
17 if !cell.bg.is_transparent() {
18 console.as_mut().set(
19 x as i32 + offset_x,
20 y as i32 + offset_y,
21 cell.fg.into(),
22 cell.bg.into(),
23 cell.ch as FontCharType,
24 );
25 }
26 }
27 }
28 }
29}
30
31pub fn xp_to_draw_batch(xp: &XpFile, draw_batch: &mut DrawBatch, offset_x: i32, offset_y: i32) {
33 for layer in &xp.layers {
34 for y in 0..layer.height {
35 for x in 0..layer.width {
36 let cell = layer.get(x, y).unwrap();
37 if !cell.bg.is_transparent() {
38 draw_batch.set(
39 Point::new(x as i32 + offset_x, y as i32 + offset_y),
40 ColorPair::new(RGBA::from(cell.fg), RGBA::from(cell.bg)),
41 cell.ch as FontCharType,
42 );
43 }
44 }
45 }
46 }
47}