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

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