summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/global.pl51
-rw-r--r--lib/VNDB/DB/VN.pm18
-rw-r--r--lib/VNDB/Handler/VN.pm43
-rw-r--r--static/f/style.css14
4 files changed, 122 insertions, 4 deletions
diff --git a/data/global.pl b/data/global.pl
index edf52008..e983b2e3 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -68,6 +68,57 @@ our %S = (
[ 'Long', '30 - 50 hours', 'Tsukihime' ],
[ 'Very long', '> 50 hours', 'Clannad' ],
],
+ categories => {
+ g => [ 'Gameplay', {
+ aa => 'NVL', # 0..1
+ ab => 'ADV', # 0..1
+ ac => "Act\x{200B}ion", # Ugliest. Hack. Ever.
+ rp => 'RPG',
+ st => 'Strategy',
+ si => 'Simulation',
+ }, 2 ],
+ p => [ 'Plot', { # 0..1
+ li => 'Linear',
+ br => 'Branching',
+ }, 3 ],
+ e => [ 'Elements', {
+ ac => 'Action',
+ co => 'Comedy',
+ dr => 'Drama',
+ fa => 'Fantasy',
+ ho => 'Horror',
+ my => 'Mystery',
+ ro => 'Romance',
+ sc => 'School Life',
+ sf => 'SciFi',
+ sj => 'Shoujo Ai',
+ sn => 'Shounen Ai',
+ }, 1 ],
+ t => [ 'Time', { # 0..1
+ fu => 'Future',
+ pa => 'Past',
+ pr => 'Present',
+ }, 4 ],
+ l => [ 'Place', { # 0..1
+ ea => 'Earth',
+ fa => "Fant\x{200B}asy world",
+ sp => 'Space',
+ }, 5 ],
+ h => [ 'Protagonist', { # 0..1
+ fa => 'Male',
+ fe => "Fem\x{200B}ale",
+ }, 6 ],
+ s => [ 'Sexual content', {
+ aa => 'Sexual content',
+ be => 'Bestiality',
+ in => 'Incest',
+ lo => 'Lolicon',
+ sh => 'Shotacon',
+ ya => 'Yaoi',
+ yu => 'Yuri',
+ ra => 'Rape',
+ }, 7 ],
+ },
);
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index b5ea026f..5d9aafa5 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -9,7 +9,7 @@ our @EXPORT = qw|dbVNGet|;
# Options: id, rev, results, page, order, what
-# What: extended
+# What: extended categories
sub dbVNGet {
my($self, %o) = @_;
$o{results} ||= 10;
@@ -33,7 +33,7 @@ sub dbVNGet {
);
my @select = (
- qw|v.id v.locked v.hidden v.c_released v.c_languages v.c_platforms vr.title vr.original|,
+ qw|v.id v.locked v.hidden v.c_released v.c_languages v.c_platforms vr.title vr.original|, 'vr.id AS cid',
$o{what} =~ /extended/ ? (
qw|vr.alias vr.image vr.img_nsfw vr.length vr.desc vr.l_wp vr.l_encubed vr.l_renai vr.l_vnn| ) : (),
);
@@ -47,6 +47,20 @@ sub dbVNGet {
join(', ', @select), join(' ', @join), \%where, $o{order},
);
+ if(@$r && $o{what} =~ /categories/) {
+ my %r = map {
+ $r->[$_]{categories} = [];
+ ($r->[$_]{cid}, $_)
+ } 0..$#$r;
+
+ push(@{$r->[$r{$_->{vid}}]{categories}}, [ $_->{cat}, $_->{lvl} ]) for (@{$self->dbAll(q|
+ SELECT vid, cat, lvl
+ FROM vn_categories
+ WHERE vid IN(!l)|,
+ [ keys %r ]
+ )});
+ }
+
return wantarray ? ($r, $np) : $r;
}
diff --git a/lib/VNDB/Handler/VN.pm b/lib/VNDB/Handler/VN.pm
index be1beed1..26663d26 100644
--- a/lib/VNDB/Handler/VN.pm
+++ b/lib/VNDB/Handler/VN.pm
@@ -17,7 +17,7 @@ sub page {
# TODO: revision-awareness, hidden/locked flag check
- my $v = $self->dbVNGet(id => $vid, what => 'extended')->[0];
+ my $v = $self->dbVNGet(id => $vid, what => 'extended categories')->[0];
return 404 if !$v->{id};
$self->htmlHeader(title => $v->{title});
@@ -71,7 +71,10 @@ sub page {
end;
}
- # TODO: producers, categories, relations, anime
+ # categories
+ page_categories($self, \$i, $v) if @{$v->{categories}};
+
+ # TODO: producers, relations, anime
end;
end;
@@ -90,6 +93,42 @@ sub page {
$self->htmlFooter;
}
+sub page_categories {
+ my($self, $i, $v) = @_;
+
+ # create an ordered list of selected categories in the form of: [ parent, [ p, sub, lvl ], .. ], ..
+ my @cat;
+ my %nolvl = (map {$_=>1} qw| pli pbr gaa gab hfa hfe |);
+ for my $cp (qw|e s g p h|) {
+ my $thisparent = 0;
+ my @sel = sort grep substr($_->[0], 0, 1) eq $cp, @{$v->{categories}};
+ if(@sel) {
+ push @cat, [ $self->{categories}{$cp}[0] ];
+ push @{$cat[$#cat]}, map [ $cp, substr($_->[0],1,2), $nolvl{$_->[0]} ? 0 : $_->[1] ], @sel;
+ }
+ }
+ my @placetime = grep $_->[0] =~ /^[tl]/, @{$v->{categories}};
+ if(@placetime) {
+ push @cat, [ 'Place/Time' ];
+ push @{$cat[$#cat]}, map [ substr($_->[0],0,1), substr($_->[0],1,2), 0], sort { $a->[0] cmp $b->[0] } @placetime;
+ }
+
+ # format & output categories
+ Tr ++$$i % 2 ? (class => 'odd') : ();
+ td 'Categories';
+ td;
+ dl;
+ for (@cat) {
+ dt shift(@$_).':';
+ dd;
+ lit join ', ', map qq|<i class="catlvl_$_->[2]">$self->{categories}{$_->[0]}[1]{$_->[1]}</i>|, @$_;
+ end;
+ }
+ end;
+ end;
+ end;
+}
+
1;
diff --git a/static/f/style.css b/static/f/style.css
index 443b0a10..34dd891d 100644
--- a/static/f/style.css
+++ b/static/f/style.css
@@ -434,6 +434,20 @@ div.vndetails table {
float: left;
width: 430px;
}
+div.vndetails table td {
+ padding-right: 10px;
+}
+div.vndetails table dt {
+ float: left;
+ font-style: italic;
+}
+div.vndetails table dd {
+ margin-left: 90px;
+}
+.catlvl_0, .catlvl_1, .catlvl_2, .catlvl_3 { font-style: normal; }
+.catlvl_1 { color: #444!important }
+.catlvl_2 { color: #777 }
+.catlvl_3 { color: #fff }
div.vndescription {
clear: left;
padding: 5px 0 0 0;