Skip to content

Commit 81b803a

Browse files
committed
Text screenshotting function
1 parent c44c4d2 commit 81b803a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ui/src/game.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,26 @@ impl Game {
652652
pub fn is_game_over(&self) -> bool {
653653
self.retired
654654
}
655+
656+
/// Return a monochrome text screenshot.
657+
pub fn screenshot(&self) -> String {
658+
let mut ret = String::new();
659+
for y in 0..self.s.height() {
660+
for x in 0..self.s.width() {
661+
let mut c = char::from_u32(
662+
self.s.data()[(x + y * self.s.width()) as usize].c as u32,
663+
)
664+
.unwrap_or(' ');
665+
if c == '\0' {
666+
c = ' ';
667+
}
668+
ret.push(c);
669+
}
670+
ret.push('\n');
671+
}
672+
673+
ret
674+
}
655675
}
656676

657677
fn draw_anims(

0 commit comments

Comments
 (0)