Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 90 lines (80 sloc) 1.754 kb
9bb4400 Brad Gilbert Added module for loading building data
b2gills authored
1 package LoadBuilding;
2 use strict;
3 use warnings;
4
5 use YAML qw'LoadFile thaw';
6 use Scalar::Util qw'reftype blessed';
7
8 sub _load{
9 my($input) = @_;
10 if( ref $input ){
11 if( reftype $input eq 'SCALAR' ){
12 return thaw $$input;
13 }
14 }else{
15 return LoadFile $input;
16 }
17 }
18
19 sub Load{
20 my($self,$config) = @_;
21 my $class = blessed $self || $self;
8ccb386 Remove whitespace [Gun.io WhitespaceBot]
Gun.io Whitespace Robot authored
22
9bb4400 Brad Gilbert Added module for loading building data
b2gills authored
23 $self = bless {},$class unless ref $self;
24 $self->{yaml} = _load($config);
25 for my $data ( values %{$self->{yaml}} ){
26 @{$data->{tags}} = sort @{ $data->{tags} };
27 }
28 $self
29 }
30
31 sub types{
32 my($self) = @_;
33 my %type;
34 my $yaml = $self->{yaml};
35 for my $building ( sort keys %$yaml ){
36 my $type = $yaml->{$building}{type};
37 push @{$type{$type}}, $building;
38 }
39 return \%type;
40 }
61c448e Brad Gilbert Added tag methods to building module
b2gills authored
41
42 sub tags{
43 my($self) = @_;
44 my %tags;
45 my $yaml = $self->{yaml};
46 for my $building ( sort keys %$yaml ){
47 my $tags = $yaml->{$building}{tags};
48 push @{ $tags{$building} }, @$tags;
49 }
50 return \%tags;
51 }
52
53 sub tag_list{
54 my($self) = @_;
55 my %tags;
56 my $yaml = $self->{yaml};
57 for my $building ( sort keys %$yaml ){
58 my $tags = $yaml->{$building}{tags};
59 for my $tag ( @$tags ){
60 $tags{$tag} = undef;
61 }
62 }
63 my @tags = sort keys %tags;
64 return @tags if wantarray;
65 return \@tags;
66 }
affe207 fireartist expand Types to link building urls with labels (used for plan names)
fireartist authored
67
68 sub labels{
69 my($self) = @_;
70 my %type;
71 my $yaml = $self->{yaml};
72 for my $building ( sort keys %$yaml ){
73 $type{$building} = $yaml->{$building}{label};
74 }
75 return \%type;
76 }
61ba9d3 fireartist new building_glyph_recipes() method in Types.pm
fireartist authored
77
11f9cac fireartist fix building_glyph_recipes
fireartist authored
78 sub glyph_recipes{
61ba9d3 fireartist new building_glyph_recipes() method in Types.pm
fireartist authored
79 my($self) = @_;
80 my %recipes;
81 my $yaml = $self->{yaml};
82 for my $building ( sort keys %$yaml ){
11f9cac fireartist fix building_glyph_recipes
fireartist authored
83 next if !exists $yaml->{$building}{glyph_recipes};
84 my $recipes = $yaml->{$building}{glyph_recipes};
61ba9d3 fireartist new building_glyph_recipes() method in Types.pm
fireartist authored
85 push @{ $recipes{$building} }, @$recipes;
86 }
87 return \%recipes;
88 }
ee7a866 Brad Gilbert Remove Exporter from data/LoadBuilding.pm
b2gills authored
89 1;
Something went wrong with that request. Please try again.