summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-11 19:52:44 +0200
committerYorhel <git@yorhel.nl>2019-09-11 19:52:44 +0200
commit794806518f18bfb5470a785bb47ca799f11679b3 (patch)
tree63be39090829a890f9a95d2397d12635bcaab31b /lib/VNDB
parent26c2f1290468309e69d3139842481920e79cd5bc (diff)
VNDB::Types: Convert vn_lengths, anime_types and tag_categories
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/Func.pm9
-rw-r--r--lib/VNDB/Handler/Tags.pm11
-rw-r--r--lib/VNDB/Handler/Users.pm3
-rw-r--r--lib/VNDB/Handler/VNEdit.pm4
-rw-r--r--lib/VNDB/Handler/VNPage.pm6
-rw-r--r--lib/VNDB/Types.pm29
6 files changed, 47 insertions, 15 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index fc52ef08..fbdf01d2 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -8,6 +8,7 @@ use Exporter 'import';
use POSIX 'strftime', 'ceil', 'floor';
use JSON::XS;
use VNDBUtil;
+use VNDB::Types;
use VNDB::BBCode;
our @EXPORT = (@VNDBUtil::EXPORT, 'bb2html', 'bb2text', qw|
clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags
@@ -219,10 +220,10 @@ sub fmtmedia {
# Formats a VN length (xtra = 1 for time indication, 2 for examples)
sub fmtvnlen {
my($len, $xtra) = @_;
- $len = $TUWF::OBJ->{vn_lengths}[$len];
- $len->[0].
- ($xtra && $xtra == 1 && $len->[1] ? " ($len->[1])" : '').
- ($xtra && $xtra == 2 && $len->[2] ? " ($len->[2])" : '');
+ $len = $VN_LENGTH{$len};
+ $len->{txt}.
+ ($xtra && $xtra == 1 && $len->{time} ? " ($len->{time})" : '').
+ ($xtra && $xtra == 2 && $len->{example} ? " ($len->{example})" : '');
}
# Formats a UNIX timestamp as a '<number> <unit> ago' string
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 69fc005b..51cddfef 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -6,6 +6,7 @@ use strict;
use warnings;
use TUWF ':html', ':xml', 'xml_escape';
use VNDB::Func;
+use VNDB::Types;
TUWF::register(
@@ -99,7 +100,7 @@ sub tagpage {
p class => 'center';
b 'Category';
br;
- txt $self->{tag_categories}{$t->{cat}};
+ txt $TAG_CATEGORY{$t->{cat}};
end;
if(@{$t->{aliases}}) {
p class => 'center';
@@ -167,7 +168,7 @@ sub tagedit {
$frm = $self->formValidate(
{ post => 'name', required => 1, maxlength => 250, regex => [ qr/^[^,]+$/, 'A comma is not allowed in tag names' ] },
{ post => 'state', required => 0, default => 0, enum => [ 0..2 ] },
- { post => 'cat', required => 1, enum => [ keys %{$self->{tag_categories}} ] },
+ { post => 'cat', required => 1, enum => [ keys %TAG_CATEGORY ] },
{ post => 'catrec', required => 0 },
{ post => 'searchable', required => 0, default => 0 },
{ post => 'applicable', required => 0, default => 0 },
@@ -259,7 +260,7 @@ sub tagedit {
[ checkbox => short => 'applicable', name => 'Applicable (people can apply this tag to VNs)' ],
) : (),
[ select => short => 'cat', name => 'Category', options => [
- map [$_, $self->{tag_categories}{$_}], keys %{$self->{tag_categories}} ] ],
+ map [$_, $TAG_CATEGORY{$_}], keys %TAG_CATEGORY ] ],
$self->authCan('tagmod') && $tag ? (
[ checkbox => short => 'catrec', name => 'Also edit all child tags to have this category' ],
[ static => content => 'WARNING: This will overwrite the category field for all child tags, this action can not be reverted!' ],
@@ -622,11 +623,11 @@ sub _tagmod_list {
my %my = map +($_->{tag} => $_), @$my;
- for my $cat (keys %{$self->{tag_categories}}) {
+ for my $cat (keys %TAG_CATEGORY) {
my @tags = grep $_->{cat} eq $cat, @$tags;
next if !@tags;
Tr class => 'tagmod_cat';
- td colspan => 7, $self->{tag_categories}{$cat};
+ td colspan => 7, $TAG_CATEGORY{$cat};
end;
for my $t (@tags) {
my $m = $my{$t->{id}};
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 00f0d841..09f148d5 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use TUWF ':html', 'xml_escape';
use VNDB::Func;
+use VNDB::Types;
use POSIX 'floor';
use PWLookup;
@@ -530,7 +531,7 @@ sub edit {
[ check => short => 'traits_sexual', name => 'Show sexual traits by default on character pages.' ],
[ check => short => 'tags_all', name => 'Show all tags by default on visual novel pages.' ],
[ select => short => 'tags_cat', name => 'Tag categories', multi => 1, size => 3,
- options => [ map [ $_, $self->{tag_categories}{$_} ], keys %{$self->{tag_categories}} ] ],
+ options => [ map [ $_, $TAG_CATEGORY{$_} ], keys %TAG_CATEGORY ] ],
[ select => short => 'spoilers', name => 'Spoiler level', options => [
[0, 'Hide spoilers'], [1, 'Show only minor spoilers'], [2, 'Show all spoilers'] ]],
[ select => short => 'skin', name => 'Preferred skin', width => 300, options => [
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index bbf1f545..98b4221e 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -120,7 +120,7 @@ sub edit {
{ post => 'original', required => 0, maxlength => 250, default => '' },
{ post => 'alias', required => 0, maxlength => 500, default => '' },
{ post => 'desc', required => 0, default => '', maxlength => 10240 },
- { post => 'length', required => 0, default => 0, enum => [ 0..$#{$self->{vn_lengths}} ] },
+ { post => 'length', required => 0, default => 0, enum => [ keys %VN_LENGTH ] },
{ post => 'l_renai', required => 0, default => '', maxlength => 100 },
{ post => 'l_wikidata', required => 0, template => 'wikidata' },
{ post => 'anime', required => 0, default => '' },
@@ -270,7 +270,7 @@ sub _form {
'Short description of the main story. Please do not include spoilers, and don\'t forget to list'
.' the source in case you didn\'t write the description yourself. Formatting codes are allowed.' ],
[ select => short => 'length', name => 'Length', width => 450, options =>
- [ map [ $_ => fmtvnlen $_, 2 ], 0..$#{$self->{vn_lengths}} ] ],
+ [ map [ $_ => fmtvnlen $_, 2 ], keys %VN_LENGTH ] ],
[ input => short => 'l_wikidata',name => 'Wikidata ID',
pre => 'https://www.wikidata.org/wiki/',
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 614ae166..a7988df8 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -457,9 +457,9 @@ sub page {
if(@$t) {
div id => 'tagops';
my $tags_cat = $self->authPref('tags_cat') || $self->{default_tags_cat};
- for (keys %{$self->{tag_categories}}) {
+ for (keys %TAG_CATEGORY) {
input id => "cat_$_", type => 'checkbox', class => 'visuallyhidden', $tags_cat =~ /\Q$_/ ? (checked => 'checked') : ();
- label for => "cat_$_", lc $self->{tag_categories}{$_};
+ label for => "cat_$_", lc $TAG_CATEGORY{$_};
}
my $spoiler = $self->authPref('spoilers') || 0;
input id => 'tag_spoil_none', type => 'radio', class => 'visuallyhidden', name => 'tag_spoiler', $spoiler == 0 ? (checked => 'checked') : ();
@@ -694,7 +694,7 @@ sub _anime {
txt '] ';
end;
abbr title => $_->{title_kanji}||$_->{title_romaji}, shorten $_->{title_romaji}, 50;
- b ' ('.(defined $_->{type} ? $self->{anime_types}{$_->{type}}.', ' : '').$_->{year}.')';
+ b ' ('.(defined $_->{type} ? $ANIME_TYPE{$_->{type}}.', ' : '').$_->{year}.')';
br;
}
}
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index aa642762..21ef2425 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -150,6 +150,35 @@ hash CREDIT_TYPE =>
+hash VN_LENGTH =>
+ 0 => { txt => 'Unknown', time => '', example => '' },
+ 1 => { txt => 'Very short', time => '< 2 hours', example => 'OMGWTFOTL, Jouka no Monshou, The world to reverse' },
+ 2 => { txt => 'Short', time => '2 - 10 hours', example => 'Narcissu, Saya no Uta, Planetarian' },
+ 3 => { txt => 'Medium', time => '10 - 30 hours', example => 'Yume Miru Kusuri, Cross†Channel, Crescendo' },
+ 4 => { txt => 'Long', time => '30 - 50 hours', example => 'Tsukihime, Ever17, Demonbane' },
+ 5 => { txt => 'Very long', time => '> 50 hours', example => 'Clannad, Umineko, Fate/Stay Night' };
+
+
+
+# SQL: ENUM anime_type
+hash ANIME_TYPE => # anidb = what the UDP API returns, lowercased
+ tv => { txt => 'TV Series', anidb => 'tv series' },
+ ova => { txt => 'OVA', anidb => 'ova' },
+ mov => { txt => 'Movie', anidb => 'movie' },
+ oth => { txt => 'Other', anidb => 'other' },
+ web => { txt => 'Web', anidb => 'web' },
+ spe => { txt => 'TV Special', anidb => 'tv special' },
+ mv => { txt => 'Music Video', anidb => 'music video' };
+
+
+
+# SQL: ENUM tag_category
+hash TAG_CATEGORY =>
+ cont => 'Content',
+ ero => 'Sexual content',
+ tech => 'Technical';
+
+
hash WISHLIST_STATUS =>
0 => 'High',