Skip to content

Commit

Permalink
Implemented Connection::TYPE_VERTICAL
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertWesner committed Aug 23, 2024
1 parent 628c52d commit 9797216
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Template/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function getBuffer(int $width, int $height): Buffer
// Bottom bar
$this->drawHorizontal(
$cornerWidth,
$height - count(explode(PHP_EOL, $this->horizontal)),
$height - substr_count($this->horizontal, PHP_EOL) - 1,
$width - $cornerWidth * 2,
$buffer,
);
Expand Down Expand Up @@ -239,8 +239,12 @@ public function getBuffer(int $width, int $height): Buffer
$buffer,
);
} elseif ($connection->type === Connection::TYPE_VERTICAL) {
// TODO: implement vertical connections
die('Vertical Connections are not implemented yet.');
$this->drawVertical(
$beginX,
$beginY + substr_count($beginConnection, PHP_EOL) + 1,
$endY - $beginY - substr_count($beginConnection, PHP_EOL) - 1,
$buffer,
);
}
}

Expand Down
114 changes: 114 additions & 0 deletions tests/Template/BorderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PHPUnit\Framework\TestCase;
use RobertWesner\AWDY\Template\Border;
use RobertWesner\AWDY\Template\Buffer;
use RobertWesner\AWDY\Template\Connection;
use RobertWesner\AWDY\Template\Facing;

#[CoversClass(Border::class)]
#[UsesClass(Buffer::class)]
Expand Down Expand Up @@ -131,6 +133,118 @@ public static function dataProvider(): array
)
// TODO: test connections
],
'connections' => [
<<<EOF
.------------------------------------------------------------------------------.
| |
| .---------------. .-------------------------------------------------- |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| '---------------' '--------------------------------------------------' |
| |
| .----------------------------------------------------------------------. |
| | | |
| | | |
| '----------------------------------------------------------------------' |
| |
'------------------------------------------------------------------------------'
EOF,
80,
40,
Border::create()
->horizontal(<<<EOF
-
-
EOF)
->vertical(<<<EOF
| |
EOF)
->corners(
topLeft: <<<EOF
.----
|
| .
EOF,
topRight: <<<EOF
----.
|
|
EOF,
bottomLeft: <<<EOF
| '
|
'----
EOF,
bottomRight: <<<EOF
' |
|
----'
EOF,
)
->connectFacing(
left: <<<EOF
' |
|
. |
EOF,
right: <<<EOF
| '
|
| .
EOF,
top: <<<EOF
' '
-----
EOF,
bottom: <<<EOF
-----
. .
EOF,
all: <<<EOF
' '
. .
EOF,
)
->connections([
Connection::horizontal()
->begin(0, -8, Facing::RIGHT)
->end(-5, -8, Facing::LEFT),
Connection::vertical()
->begin(20, 0, Facing::BOTTOM)
->end(20, -8, Facing::TOP),
])
]
];
}

Expand Down

0 comments on commit 9797216

Please sign in to comment.