summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-12 12:52:08 +0200
committerYorhel <git@yorhel.nl>2019-09-12 12:52:08 +0200
commit5d45892f95e83fc3a5185dad991bf61d9db69197 (patch)
tree5e6701fd382522da2386b440a93dd4b80bbf80cf
parent5a62f120bad71b81068fd1d50035effc0fda688c (diff)
VNDB::Types: Convert age_rating and release_type
-rw-r--r--data/global.pl2
-rw-r--r--lib/Multi/API.pm2
-rw-r--r--lib/VN3/ElmGen.pm2
-rw-r--r--lib/VN3/Types.pm20
-rw-r--r--lib/VN3/Validation.pm2
-rw-r--r--lib/VNDB/Func.pm20
-rw-r--r--lib/VNDB/Handler/Releases.pm16
-rw-r--r--lib/VNDB/Types.pm29
-rwxr-xr-xutil/jsgen.pl4
9 files changed, 48 insertions, 49 deletions
diff --git a/data/global.pl b/data/global.pl
index aa2bfb10..1b0834a8 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -49,8 +49,6 @@ our %S;
default_perm => 1+4+16, # Keep synchronised with the default value of users.perm
default_tags_cat=> 'cont,tech',
board_edit_time => 7*24*3600,
- age_ratings => [-1, 0, 6..18],
- release_types => [qw|complete partial trial|],
media => ordhash(
#DB qty txt plural (if qty) icon
cd => [ 1, 'CD', 'CDs', 'disk' ],
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index fdde0e8c..73d0425c 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -697,7 +697,7 @@ my %GET_RELEASE = (
doujin => [ [ bool => 'r.doujin = :value:', {'=',1} ] ],
type => [
[ str => 'r.type :op: :value:', {qw|= = != <>|},
- process => sub { !grep($_ eq $_[0], @{$VNDB::S{release_types}}) ? \'No such release type' : $_[0] } ],
+ process => sub { !$RELEASE_TYPE{$_[0]} ? \'No such release type' : $_[0] } ],
],
gtin => [
[ 'int' => 'r.gtin :op: :value:', {qw|= = != <>|}, process => sub { length($_[0]) > 14 ? \'Too long GTIN code' : $_[0] } ],
diff --git a/lib/VN3/ElmGen.pm b/lib/VN3/ElmGen.pm
index 3e18d70d..900f40c9 100644
--- a/lib/VN3/ElmGen.pm
+++ b/lib/VN3/ElmGen.pm
@@ -174,7 +174,7 @@ def languages => 'List (String, String)' => list map tuple(string $_, st
def platforms => 'List (String, String)' => list map tuple(string $_, string $PLATFORM{$_}), keys %PLATFORM;
def releaseTypes => 'List String' => list map string($_), release_types;
def producerTypes => 'List (String, String)' => list map tuple(string $_, string $PRODUCER_TYPE{$_}), keys %PRODUCER_TYPE;
-def minAges => 'List (Int, String)' => list map tuple($_, string minage_display_full $_), @MINAGE;
+def minAges => 'List (Int, String)' => list map tuple($_, string minage_display_full $_), keys %AGE_RATING;
def resolutions => 'List (String, String)' => list map tuple(string $_, string resolution_display_full $_), keys %RESOLUTIONS;
def voiced => 'List (Int, String)' => list map tuple($_, string($VOICED{$_})), keys %VOICED;
def animated => 'List (Int, String)' => list map tuple($_, string($ANIMATED{$_})), keys %ANIMATED;
diff --git a/lib/VN3/Types.pm b/lib/VN3/Types.pm
index a36cc6dd..f50f417c 100644
--- a/lib/VN3/Types.pm
+++ b/lib/VN3/Types.pm
@@ -26,7 +26,7 @@ our @EXPORT = qw/
producer_relation_reverse producer_relation_display
spoil_display
release_types
- @MINAGE minage_display minage_display_full
+ minage_display minage_display_full
%RESOLUTIONS resolution_display_full
gender_display gender_icon
blood_type_display
@@ -182,22 +182,8 @@ my @RELEASE_TYPES = qw/complete partial trial/;
sub release_types { @RELEASE_TYPES }
-
-# XXX: Apparently, unknown is stored in the DB as -1 rather than NULL, even
-# though the column is marked as nullable; probably needs some fixing for
-# consistency.
-our @MINAGE = (0, 6..18);
-my %MINAGE_EX = (
- 0 => 'CERO A',
- 12 => 'CERO B',
- 15 => 'CERO C',
- 17 => 'CERO D',
- 18 => 'CERO Z',
-);
-
-sub minage_display { !defined $_[0] || $_[0] < 0 ? 'Unknown' : !$_[0] ? 'All ages' : sprintf '%d+', $_[0] }
-
-sub minage_display_full { my $e = $MINAGE_EX{$_[0]||''}; minage_display($_[0]).($e ? " (e.g. $e)" : '') };
+sub minage_display { $AGE_RATING{$_[0]}{txt} }
+sub minage_display_full { my $e = $AGE_RATING{$_[0]}; $e->{txt}.($e->{ex} ? " (e.g. $e->{ex})" : '') };
diff --git a/lib/VN3/Validation.pm b/lib/VN3/Validation.pm
index 0ec83514..ab4214a9 100644
--- a/lib/VN3/Validation.pm
+++ b/lib/VN3/Validation.pm
@@ -35,7 +35,7 @@ TUWF::set custom_validations => {
gender => { enum => \%GENDER },
blood_type => { enum => \%BLOOD_TYPE },
gtin => { uint => 1, func => sub { $_[0] eq 0 || gtintype($_[0]) } },
- minage => { uint => 1, enum => \@MINAGE },
+ minage => { uint => 1, enum => \%AGE_RATING },
animated => { uint => 1, enum => \%ANIMATED },
voiced => { uint => 1, enum => \%VOICED },
rdate => { uint => 1, func => \&_validate_rdate },
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index fbdf01d2..a4e6423e 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -11,7 +11,7 @@ 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
+ clearfloat cssicon tagscore minage fil_parse fil_serialize parenttags
childtags charspoil imgpath imgurl
fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtuser fmtrating fmtspoil
json_encode json_decode script_json
@@ -67,24 +67,10 @@ sub tagscore {
}
-# short wrapper around maketext()
-sub mt {
- return $TUWF::OBJ->{l10n}->maketext(@_);
-}
-
-
sub minage {
my($a, $ex) = @_;
- my $str = $a == -1 ? 'Unknown' : !$a ? 'All ages' : sprintf '%d+', $a;
- $ex = !defined($a) ? '' : {
- 0 => 'CERO A',
- 12 => 'CERO B',
- 15 => 'CERO C',
- 17 => 'CERO D',
- 18 => 'CERO Z',
- }->{$a} if $ex;
- return $str if !$ex;
- return "$str (e.g. $ex)";
+ $a = $AGE_RATING{$a};
+ $ex && $a->{ex} ? "$a->{txt} (e.g. $a->{ex})" : $a->{txt}
}
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index da1c1554..a6b896f1 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -146,7 +146,7 @@ sub _infotable {
td 'Type';
td;
cssicon "rt$r->{type}", $r->{type};
- txt sprintf ' %s%s', ucfirst($r->{type}), $r->{patch} ? ', patch' : '';
+ txt sprintf ' %s%s', $RELEASE_TYPE{$r->{type}}, $r->{patch} ? ', patch' : '';
end;
end;
@@ -352,7 +352,7 @@ sub edit {
return if !$self->authCheckCode;
my $dmm_re = qr{(?:https?://)?(?:www|dlsoft)\.dmm\.(?:com|co\.jp)/[^\s]+};
$frm = $self->formValidate(
- { post => 'type', enum => $self->{release_types} },
+ { post => 'type', enum => [ keys %RELEASE_TYPE ] },
{ post => 'patch', required => 0, default => 0 },
{ post => 'freeware', required => 0, default => 0 },
{ post => 'doujin', required => 0, default => 0 },
@@ -381,7 +381,7 @@ sub edit {
{ post => 'l_egs', required => 0, default => 0, template => 'uint' },
{ post => 'l_erotrail',required => 0, default => 0, template => 'uint' },
{ post => 'released', required => 0, default => 0, template => 'rdate' },
- { post => 'minage' , required => 0, default => -1, enum => $self->{age_ratings} },
+ { post => 'minage' , required => 0, default => -1, enum => [ keys %AGE_RATING ] },
{ post => 'notes', required => 0, default => '', maxlength => 10240 },
{ post => 'platforms', required => 0, default => '', multi => 1, enum => [ keys %PLATFORM ] },
{ post => 'media', required => 0, default => '' },
@@ -479,7 +479,7 @@ sub _form {
$self->htmlForm({ frm => $frm, action => $r ? "/r$r->{id}/".($copy ? 'copy' : 'edit') : "/v$v->{id}/add", editsum => 1 },
rel_geninfo => [ 'General info',
[ select => short => 'type', name => 'Type',
- options => [ map [ $_, ucfirst $_ ], @{$self->{release_types}} ] ],
+ options => [ map [ $_, $RELEASE_TYPE{$_} ], keys %RELEASE_TYPE ] ],
[ check => short => 'patch', name => 'This release is a patch to another release.' ],
[ check => short => 'freeware', name => 'Freeware (i.e. available at no cost)' ],
[ check => short => 'doujin', name => 'Doujin (self-published, not by a company)' ],
@@ -494,7 +494,7 @@ sub _form {
[ date => short => 'released', name => 'Release date' ],
[ static => content => 'Leave month or day blank if they are unknown' ],
[ select => short => 'minage', name => 'Age rating',
- options => [ map [ $_, minage $_, 1 ], @{$self->{age_ratings}} ] ],
+ options => [ map [ $_, minage $_, 1 ], keys %AGE_RATING ] ],
[ check => short => 'uncensored',name => 'No mosaic or other optical censoring (only check if this release has erotic content)' ],
[ static => nolabel => 1, content => '<br><b>Links</b>' ],
@@ -716,17 +716,17 @@ sub _fil_compat {
{ get => 'ln', required => 0, multi => 1, default => '', enum => [ keys %LANGUAGE ] },
{ get => 'pl', required => 0, multi => 1, default => '', enum => [ keys %PLATFORM ] },
{ get => 'me', required => 0, multi => 1, default => '', enum => [ keys %{$self->{media}} ] },
- { get => 'tp', required => 0, default => '', enum => [ '', @{$self->{release_types}} ] },
+ { get => 'tp', required => 0, default => '', enum => [ '', keys %RELEASE_TYPE ] },
{ get => 'pa', required => 0, default => 0, enum => [ 0..2 ] },
{ get => 'fw', required => 0, default => 0, enum => [ 0..2 ] },
{ get => 'do', required => 0, default => 0, enum => [ 0..2 ] },
{ get => 'ma_m', required => 0, default => 0, enum => [ 0, 1 ] },
- { get => 'ma_a', required => 0, default => 0, enum => $self->{age_ratings} },
+ { get => 'ma_a', required => 0, default => 0, enum => [ keys %AGE_RATING ] },
{ get => 'mi', required => 0, default => 0, template => 'uint' },
{ get => 'ma', required => 0, default => 99999999, template => 'uint' },
);
return () if $f->{_err};
- $c{minage} = [ grep $_ >= 0 && ($f->{ma_m} ? $f->{ma_a} >= $_ : $f->{ma_a} <= $_), @{$self->{age_ratings}} ] if $f->{ma_a} || $f->{ma_m};
+ $c{minage} = [ grep $_ >= 0 && ($f->{ma_m} ? $f->{ma_a} >= $_ : $f->{ma_a} <= $_), keys %AGE_RATING ] if $f->{ma_a} || $f->{ma_m};
$c{date_after} = $f->{mi} if $f->{mi};
$c{date_before} = $f->{ma} if $f->{ma} < 99990000;
$c{plat} = $f->{pl} if $f->{pl}[0];
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 6a9aae2e..108c0c5b 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -206,6 +206,35 @@ hash VOICED =>
+# TODO: For some reason the minage column in SQL is nullable but still stores 'unknown' as -1.
+# This should be cleaned up at some point.
+hash AGE_RATING =>
+ -1 => { txt => 'Unknown', ex => '' },
+ 0 => { txt => 'All ages', ex => 'CERO A' },
+ 6 => { txt => '6+', ex => '' },
+ 7 => { txt => '7+', ex => '' },
+ 8 => { txt => '8+', ex => '' },
+ 9 => { txt => '9+', ex => '' },
+ 10 => { txt => '10+', ex => '' },
+ 11 => { txt => '11+', ex => '' },
+ 12 => { txt => '12+', ex => 'CERO B' },
+ 13 => { txt => '13+', ex => '' },
+ 14 => { txt => '14+', ex => '' },
+ 15 => { txt => '15+', ex => 'CERO C' },
+ 16 => { txt => '16+', ex => '' },
+ 17 => { txt => '17+', ex => 'CERO D' },
+ 18 => { txt => '18+', ex => 'CERO Z' };
+
+
+
+# SQL: ENUM release_type
+hash RELEASE_TYPE =>
+ complete => 'Complete',
+ partial => 'Partial',
+ trial => 'Trial';
+
+
+
hash WISHLIST_STATUS =>
0 => 'High',
1 => 'Medium',
diff --git a/util/jsgen.pl b/util/jsgen.pl
index 5cf946fa..09be62e0 100755
--- a/util/jsgen.pl
+++ b/util/jsgen.pl
@@ -38,12 +38,12 @@ sub vars {
my %vars = (
rlist_status => [ map [ $_, $RLIST_STATUS{$_} ], keys %RLIST_STATUS ],
cookie_prefix => $O{cookie_prefix},
- age_ratings => [ map [ $_, $_ == -1 ? 'Unknown' : $_ == 0 ? 'All ages' : "$_+" ], @{$S{age_ratings}} ],
+ age_ratings => [ map [ $_, $AGE_RATING{$_}{txt}], keys %AGE_RATING ],
languages => [ map [ $_, $LANGUAGE{$_} ], keys %LANGUAGE ],
platforms => [ map [ $_, $PLATFORM{$_} ], keys %PLATFORM ],
char_roles => [ map [ $_, $CHAR_ROLE{$_}{txt} ], keys %CHAR_ROLE ],
media => [ map [ $_, $S{media}{$_}[1], $S{media}{$_}[0] ], keys %{$S{media}} ],
- release_types => [ map [ $_, ucfirst $_ ], @{$S{release_types}} ],
+ release_types => [ map [ $_, $RELEASE_TYPE{$_} ], keys %RELEASE_TYPE ],
animated => [ map [ $_, $ANIMATED{$_}{txt} ], keys %ANIMATED ],
voiced => [ map [ $_, $VOICED{$_}{txt} ], keys %VOICED ],
vn_lengths => [ map [ $_, $VN_LENGTH{$_}{txt} ], keys %VN_LENGTH ],