Skip to content

Commit

Permalink
[Druid::View::Text] retrofitted to return Str
Browse files Browse the repository at this point in the history
Previously it just printed things directly to $*OUT, but I needed the actual
strings when dealing with HTTP::Daemon.
  • Loading branch information
Carl Masak committed Apr 12, 2009
1 parent e2db644 commit dd6cca0
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/Druid/View/Text.pm
Expand Up @@ -75,10 +75,13 @@ class Druid::View::Text is Druid::View {
# Prints the 3D game board and the two smaller sub boards, reflecting the
# current state of the game.
method show() {
.print for $!cached-board, self.colors-and-heights();
}

print $!cached-board;

self.print-colors-and-heights();
# Returns the 3D game board and the two smaller sub boards, reflecting the
# current state of the game.
method Str() {
return [~] $!cached-board, self.colors-and-heights();
}

method build-layers($board is copy, $from) {
Expand Down Expand Up @@ -170,7 +173,7 @@ class Druid::View::Text is Druid::View {

# Prints two smaller boards representing (1) who owns each location, and
# (2) how many stones have been piled on each location.
method print-colors-and-heights() {
method colors-and-heights() {

my &from-pretty = { $^pretty.trans( ['>>', '<<', '.']
=> ['%2d','%-2d','%s'] ) };
Expand All @@ -189,16 +192,19 @@ class Druid::View::Text is Druid::View {
$letters.join(' '), "\n";
my $header = "$footer\n";

print $header;
# RAKUDO: .reverse on Ranges out of order. [perl #64458]
for (1..$.size).list.reverse -> $row {
say sprintf from-pretty(
[~] ' ', $board-line, $inter-board-space, $board-line
),
$row, (map &format-colors, @.colors[$row-1].values), $row,
$row, (map &format-heights, @.heights[$row-1].values), $row;
}
print $footer;
return gather {
take $header;
# RAKUDO: .reverse on Ranges out of order. [perl #64458]
for (1..$.size).list.reverse -> $row {
take sprintf from-pretty(
[~] ' ', $board-line, $inter-board-space, $board-line
),
$row, (map &format-colors, @.colors[$row-1].values), $row,
$row, (map &format-heights, @.heights[$row-1].values), $row;
take "\n";
}
take $footer;
};
}

method add-piece($height, $row, $column, $color) {
Expand Down

0 comments on commit dd6cca0

Please sign in to comment.