ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/books.ext
Revision: 1.6
Committed: Fri May 14 22:56:46 2010 UTC (14 years ago) by root
Branch: MAIN
CVS Tags: rel-3_1, rel-3_0, HEAD
Changes since 1.5: +1 -1 lines
Log Message:
music groups, music conf file, post_init async

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 root 1.5
27     ()
28 root 1.1 }
29    
30 root 1.5 cf::post_init {
31 root 1.6 $_[0] ? cf::async_ext { reload } : reload
32 root 1.5 };
33 root 1.1
34     sub make_book {
35     my ($book, $level) = @_;
36    
37     return unless @BOOKS;
38    
39     my ($title, @body) = @{$BOOKS[rand @BOOKS]};
40    
41 root 1.3 # half-assed attempt to make it a single line text-only title
42     $title = cf::pod::as_cfpod [$title];
43 root 1.1 $title =~ s/\n/ /g;
44     $title =~ s/ +$//;
45 root 1.3 $title =~ s/B<([^>]*)>/$1/g;
46 root 1.1
47     $book->name ($title);
48     $book->name_pl ($title);
49     $book->title (undef);
50 root 1.3 $book->msg (cf::pod::as_cfpod \@body);
51 root 1.1 }
52