forked from CityGenerator/CityGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpcgenerator
More file actions
executable file
·117 lines (86 loc) · 3.08 KB
/
Copy pathnpcgenerator
File metadata and controls
executable file
·117 lines (86 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl -wT
use strict;
use warnings;
use CGI;
use Data::Dumper;
use JSON;
use List::Util 'shuffle', 'min', 'max' ;
use POSIX;
use Template;
use XML::Simple;
use lib "lib/";
use GenericGenerator;
use NPCGenerator;
use NPCFormatter;
our $q = CGI->new;
my $seed=GenericGenerator::set_seed();
if (defined $q->param('seed')){
$seed=$q->param('seed');
}
my $npc=NPCGenerator::create_npc({seed=>$seed});
if (defined $q->param('type') and $q->param('type') eq 'xml' ){
print $q->header( 'text/xml' );
print "<?xml version='1.0' encoding='utf-8' ?>\n";
print XMLout($npc);
} elsif (defined $q->param('type') and $q->param('type') eq 'json' ){
print $q->header( 'application/json' );
my $JSON = JSON->new->utf8;
$JSON->convert_blessed(1);
print $JSON->encode($npc);
} elsif (defined $q->param('type') and $q->param('type') eq 'dump' ){
print $q->header( 'text/plain' );
print Dumper $npc;
} else {
print $q->header( 'text/html; charset=utf-8' );
print_page($npc);
}
exit;
#################################################################################################
#################################################################################################
#################################################################################################
sub print_page {
my ($npc)=@_;
my $templates = Template->new({
INCLUDE_PATH => 'Templates/',
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
my $vars = {
'title' => 'Meet '.$npc->{'name'}."! ($npc->{'seed'})",
'seed' => $npc->{'seed'},
'content' => print_content($npc),
};
return $templates->process('base.tmpl', $vars) || die $templates->error(), "\n";
}
sub print_content {
my ($npc)=@_;
my $templates = Template->new({
INCLUDE_PATH => 'Templates/',
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
my $formtmpl;
my $vars = {
'npcname' => $npc->{'name'},
'seed' => $npc->{'seed'},
'summarytext' => NPCFormatter::printSummary($npc),
};
$templates->process('npcgenerator_content.tmpl', $vars, \$formtmpl) || die $templates->error(), "\n";
return $formtmpl;
}
__END__
=head1 AUTHOR
Jesse Morgan (morgajel) C<< <morgajel@gmail.com> >>
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2013, Jesse Morgan (morgajel) C<< <morgajel@gmail.com> >>. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
=head1 DISCLAIMER OF WARRANTY
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
=cut