forked from CityGenerator/CityGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamegenerator
More file actions
executable file
·155 lines (126 loc) · 4.62 KB
/
Copy pathnamegenerator
File metadata and controls
executable file
·155 lines (126 loc) · 4.62 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl -wT
use strict;
use CGI;
use Data::Dumper;
use JSON;
use List::Util 'shuffle', 'min', 'max' ;
use POSIX;
use Template;
use XML::Simple;
use lib "lib/";
use NPCGenerator;
use GenericGenerator;
use Switch 'Perl5', 'Perl6';
our $q = CGI->new;
my $seed;
if (defined $q->param('seed') and $q->param('seed') =~/^(\d+)$/ ){
$seed=GenericGenerator::set_seed($1);
}else{
$seed=GenericGenerator::set_seed();
}
my $results={'seed'=>$seed};
if (defined $q->param('type') and $q->param('type') eq 'json' ){
print $q->header( 'application/json' );
my $JSON = JSON->new->utf8;
$JSON->convert_blessed(1);
$results->{'names'}=generate_names();
print $JSON->encode($results)."\n";
}elsif (defined $q->param('type') and $q->param('type') eq 'dump' ){
print $q->header( 'text/plain' );
$results->{'names'}=generate_names();
print Dumper $results;
}else {
print $q->header;
print_page();
}
exit;
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
sub print_page {
my $templates = Template->new({
INCLUDE_PATH => 'Templates/',
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
my $formtmpl;
my $vars = {
'races' => NPCGenerator::get_races() ,
};
$templates->process('nameform.tmpl', $vars, \$formtmpl) || die $templates->error(), "\n";
$vars = {
'title' => 'Name Generator',
'content' => $formtmpl,
};
$templates->process('base.tmpl', $vars) || die $templates->error(), "\n";
}
sub generate_names {
my $count=10;
if (defined $q->param('count') and $q->param('count') =~ /^\d{1,3}$/ and $q->param('count') <=100 ){
$count=$q->param('count');
}
# print Dumper ( defined $q->param('count') and $q->param('count') =~ /^\d{1,3}$/ );
my $results=[ ];
while ($count--){
my $item;
$item->{'seed'} = GenericGenerator::set_seed();
given ($q->param('gentype') || ""){
when('star') {
}
when('moon') {
}
when('continent') {
use ContinentGenerator;
$item= ContinentGenerator::generate_continent_name($item);
}
# when('region') { }
when('city') {
use CityGenerator;
$item= CityGenerator::generate_city_name($item);
}
when('establishment') {
#FIXME this doesn't work by itself
use EstablishmentGenerator;
$item= EstablishmentGenerator::generate_establishment_name($item);
}
when('npc') {
use NPCGenerator;
my $name=NPCGenerator::generate_npc_name($q->param('race'),$item);
$item->{'name'}=$name;
}
when('adventure') {
use AdventureGenerator;
$item=AdventureGenerator::generate_name($item);
}
# when('myth') { }
when('world') {
use WorldGenerator;
$item= WorldGenerator::generate_name($item);
}
default {
use WorldGenerator;
$item= WorldGenerator::generate_name($item);
}
}
push @$results,$item->{'name'};
}
$results = [sort @$results];
return $results;
}
__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