package Blacknote::Map; use strict; use warnings FATAL => qw(all); use Blacknote::System; use Blacknote::Logging; use File::Slurp qw(read_file); use Carp qw(croak); use Exporter qw(import); our @EXPORT_OK = qw(load_dotmap); sub load_dotmap { # dotmap mapdata format is just a series of numbers from 0-9 # These tiles should all be some form of static walls my $file = shift; croak "File doesn't exist: $file" unless -e $file; my @contents = split "",read_file($file); my @result = ([]); my $cl = 0; my $x = 0; for my $tile(@contents){ if($tile eq "\n"){ $x = 0; $cl++ and $result[$cl] = []; next; }else{ my $tileinstance = $Blacknote::System::State::TILE_MAPPING{hex $tile}->new(x => $x, y => $cl); push @{$result[$cl]}, $tileinstance; $x++; } } DEBUG "Loaded map $file"; return \@result; } =pod =head1 NAME Blacknote::Map =head1 SYNOPSIS A simple library for loading various map data formats =head2 Functions =head3 load_dotmap($filename) loads a .map file into and returns it as an array ref of tile instances blessed into their respective class by their numerical ID =head2 Map formats =head3 .map .map is a simple array of numbers ranging from 0 to f (hex) These are very simple to load and interpret but aren't very flexible. They can't include numbers higher than 9 other than hex. =head3 .emap - NOT IMPLEMENTED .emap is an idea of an extended map format that uses the alphabet rangin from a-z and A-Z to allow more data in maps =head3 .amap - NOT IMPLEMENTED ascii map. these must be translated back into IDs before they can be used, but offer the most human readable format .