diff options
| author | Teddy Wing | 2015-10-08 01:17:11 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-10-08 01:17:11 -0400 |
| commit | 2a0d95e135515b137a48d4b7b81ff01eaa664058 (patch) | |
| tree | bb2b4076310e2d98017b552f708c623d5194256d | |
| parent | ed38753948318b15bc82574bf25482d215e71a19 (diff) | |
| download | vim-space-vlaze-2a0d95e135515b137a48d4b7b81ff01eaa664058.tar.bz2 | |
Add space padding to Lives and Score lines
Pad these 2 status lines with spaces to the right of their string values
so that their background colours extend to the full width of the game
board.
First tried `len()`, then `strlen()` when counting characters in
`padding#RightPadding()` but turns out those deal with bytes and the
player character is a multi-byte character so we would come up sort on
spaces for padding in the Lives line because the player diamond counts
for double. To get around this, used `strchars()` which gives us a count
of the characters instead of the bytes.
| -rw-r--r-- | autoload/space_vlaze/life.vim | 4 | ||||
| -rw-r--r-- | autoload/space_vlaze/padding.vim | 3 | ||||
| -rw-r--r-- | autoload/space_vlaze/score.vim | 4 |
3 files changed, 9 insertions, 2 deletions
diff --git a/autoload/space_vlaze/life.vim b/autoload/space_vlaze/life.vim index 4168a74..400ec01 100644 --- a/autoload/space_vlaze/life.vim +++ b/autoload/space_vlaze/life.vim @@ -28,5 +28,7 @@ function! space_vlaze#life#RenderLives() let i += 1 endwhile - call setline(lives_line, lives_display) + let lives_padding = space_vlaze#padding#RightPadding(lives_display) + + call setline(lives_line, lives_display . lives_padding) endfunction diff --git a/autoload/space_vlaze/padding.vim b/autoload/space_vlaze/padding.vim new file mode 100644 index 0000000..18b6084 --- /dev/null +++ b/autoload/space_vlaze/padding.vim @@ -0,0 +1,3 @@ +function! space_vlaze#padding#RightPadding(string) + return repeat(' ', space_vlaze#game#BoardWidth() - strchars(a:string)) +endfunction diff --git a/autoload/space_vlaze/score.vim b/autoload/space_vlaze/score.vim index 612f02d..0debfaa 100644 --- a/autoload/space_vlaze/score.vim +++ b/autoload/space_vlaze/score.vim @@ -11,6 +11,8 @@ endfunction function! space_vlaze#score#RenderScore() let score_line = space_vlaze#game#BoardHeight() + 2 + let score_text = 'Score: ' . s:score + let score_padding = space_vlaze#padding#RightPadding(score_text) - call setline(score_line, 'Score: ' . s:score) + call setline(score_line, score_text . score_padding) endfunction |
