ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/books.ext
Revision: 1.4
Committed: Tue Sep 23 04:29:11 2008 UTC (15 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_71
Changes since 1.3: +1 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 #! perl # mandatory
2 root 1.1
3     our @BOOKS;
4    
5     sub reload() {
6     @BOOKS = ();
7    
8     my $paragraphs = cf::pod::load_pod "$PODDIR/books.pod"
9     or die "unable to load $PODDIR/books.pod";
10    
11     my $level = 1e9;
12     my @books;
13    
14     for my $par (@$paragraphs) {
15     if ($par->{type} eq "head1") {
16     if ($par->{markup} =~ /^(\S+)/) {
17     push @books, [$par];
18     $level = $par->{level};
19     }
20     } elsif ($par->{level} > $level) {
21     push @{ $books[-1] }, $par;
22     }
23     }
24    
25     @BOOKS = @books;
26     }
27    
28 root 1.4 reload;
29 root 1.1
30     sub make_book {
31     my ($book, $level) = @_;
32    
33     return unless @BOOKS;
34    
35     my ($title, @body) = @{$BOOKS[rand @BOOKS]};
36    
37 root 1.3 # half-assed attempt to make it a single line text-only title
38     $title = cf::pod::as_cfpod [$title];
39 root 1.1 $title =~ s/\n/ /g;
40     $title =~ s/ +$//;
41 root 1.3 $title =~ s/B<([^>]*)>/$1/g;
42 root 1.1
43     $book->name ($title);
44     $book->name_pl ($title);
45     $book->title (undef);
46 root 1.3 $book->msg (cf::pod::as_cfpod \@body);
47 root 1.1 }
48