The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Game::TextPatterns - generate patterns of text

SYNOPSIS

  use Game::TextPatterns;

  my $v = Game::TextPatterns->new( pattern => ".#\n#." );

  $v->multiply(7,3)
    ->border(1,'#')->border(1,'.')->border(1,'#');

  print $v->string;

Ta-da! You should now have an Angband checker type vault. (Doors not included. Monsters and items may cost extra.)

  ####################
  #..................#
  #.################.#
  #.#.#.#.#.#.#.#.##.#
  #.##.#.#.#.#.#.#.#.#
  #.#.#.#.#.#.#.#.##.#
  #.##.#.#.#.#.#.#.#.#
  #.#.#.#.#.#.#.#.##.#
  #.##.#.#.#.#.#.#.#.#                       @
  #.################.#
  #..................#
  ####################

DESCRIPTION

Game::TextPatterns contains methods that generate and alter text patterns. Potential uses include the creation of ASCII art or the construction of vaults for roguelike games.

Terminology

Columns (x, width) and Rows (y, height) are used in various places.

    columns ...
  r 
  o  ###%#######+######
  w  #...the.pattern..#
  s  #######+##########
  .  #........#.......#
  .  #.......@'...<...#
  .  ##################

The pattern text can be most any string value.

CONSTRUCTORS

These return new objects. Some require an existing object.

clone

Returns a new object from an existing one with the current state of the pattern attribute.

new pattern => ...

Constructor. A pattern attribute must be specified.

rebuild

MooX::Rebuild feature that returns a new object with the original pattern attribute.

ATTRIBUTES

Only one at the moment.

pattern

Required. Must be a string (which will be split on $/ into an array reference) or an array reference of strings or an object that has a pattern method that ideally returns one of the previous types.

File::Slurper may help read pattern data directly from a file.

pattern can be called as a method to return the current pattern as an array reference. It may be a bad idea to modify the contents of that reference directly.

METHODS

Call these on something returned by a constructor. Those that modify the pattern in-place can be chained with other methods.

append_cols

TODO

append_rows

TODO

border width character

Creates a border of the given width (1 by default) and character (# by default) around the pattern.

cols

Returns the width (x, or number of columns) in the pattern. This is based on the length of the first line of the pattern.

dimensions

Returns the cols and rows of the current pattern.

flip_both

Flips the pattern by columns and by rows.

flip_cols

Flips the columns (vertical mirror) in the pattern.

flip_rows

Flips the rows (horizontal mirror).

multiply cols [ rows ]

Multiplies the existing data in the columns or rows, unless cols or rows is 1. With no rows set multiplies both the columns and rows by the given value.

rows

Returns the height (y, or number of rows) in the pattern.

string sep

Returns the pattern as a string with rows joined by the sep value (a newline by default).

BUGS

Reporting Bugs

Please report any bugs or feature requests to bug-game-textpatterns at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-TextPatterns.

Patches might best be applied towards:

https://github.com/thrig/Game-TextPatterns

Known Issues

The newly being written thing (look for TODO or otherwise absent methods).

SEE ALSO

https://github.com/thrig/ministry-of-silly-vaults/

Consult the t/ directory under this module's distribution for example code.

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2018 by Jeremy Mates

This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause