summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-11 19:26:25 +0200
committerYorhel <git@yorhel.nl>2019-09-11 19:26:25 +0200
commit26c2f1290468309e69d3139842481920e79cd5bc (patch)
tree634ca2909ed3db568f8b4cb679240e601a63f9bb
parent04e92a4ef886c141783efcb1c62de12722511cc4 (diff)
VNDB::Types: Convert char_roles, blood_types and genders
-rw-r--r--data/global.pl8
-rw-r--r--lib/VN3/ElmGen.pm6
-rw-r--r--lib/VN3/Types.pm33
-rw-r--r--lib/VN3/VN/Page.pm6
-rw-r--r--lib/VN3/Validation.pm6
-rw-r--r--lib/VNDB/Handler/Chars.pm25
-rw-r--r--lib/VNDB/Handler/Staff.pm7
-rw-r--r--lib/VNDB/Handler/VNPage.pm12
-rw-r--r--lib/VNDB/Types.pm24
-rwxr-xr-xutil/jsgen.pl6
10 files changed, 65 insertions, 68 deletions
diff --git a/data/global.pl b/data/global.pl
index cf23b9c2..252cc9bb 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -130,14 +130,6 @@ our %S;
icons_ero_animated => [ 'unknown', 'ero_not_animated', 'ero_simple_animated', 'ero_some_fully_animated', 'ero_all_fully_animated' ],
voiced => [ 'Unknown', 'Not voiced', 'Only ero scenes voiced', 'Partially voiced', 'Fully voiced' ],
icons_voiced => [ 'unknown', 'not_voiced', 'ero_voiced', 'partially_voiced', 'fully_voiced' ],
- blood_types => ordhash(qw{unknown Unknown o O a A b B ab AB}),
- genders => ordhash(unknown => 'Unknown or N/A', qw{m Male f Female b Both}),
- char_roles => ordhash(
- main => [ 'Protagonist', 'Protagonists' ],
- primary => [ 'Main character', 'Main characters' ],
- side => [ 'Side character', 'Side characters' ],
- appears => [ 'Makes an appearance', 'Make an appearance' ],
- ),
atom_feeds => { # num_entries, title, id
announcements => [ 10, 'VNDB Site Announcements', '/t/an' ],
changes => [ 25, 'VNDB Recent Changes', '/hist' ],
diff --git a/lib/VN3/ElmGen.pm b/lib/VN3/ElmGen.pm
index 202b72fd..18f15521 100644
--- a/lib/VN3/ElmGen.pm
+++ b/lib/VN3/ElmGen.pm
@@ -178,9 +178,9 @@ def minAges => 'List (Int, String)' => list map tuple($_, string mi
def resolutions => 'List (String, String)' => list map tuple(string $_, string resolution_display_full $_), keys %RESOLUTIONS;
def voiced => 'List String' => list map string($_), @VOICED;
def animated => 'List String' => list map string($_), @ANIMATED;
-def genders => 'List (String, String)' => list map tuple(string $_, string gender_display $_), keys %GENDERS;
-def bloodTypes => 'List (String, String)' => list map tuple(string $_, string blood_type_display $_), keys %BLOOD_TYPES;
-def charRoles => 'List (String, String)' => list map tuple(string $_, string char_role_display $_), keys %CHAR_ROLES;
+def genders => 'List (String, String)' => list map tuple(string $_, string gender_display $_), keys %GENDER;
+def bloodTypes => 'List (String, String)' => list map tuple(string $_, string blood_type_display $_), keys %BLOOD_TYPE;
+def charRoles => 'List (String, String)' => list map tuple(string $_, string char_role_display $_), keys %CHAR_ROLE;
def vnlistStatus => 'List (Int, String)' => list map tuple($_, string $VNLIST_STATUS{$_}), keys %VNLIST_STATUS;
def emailPattern => String => string { tuwf->compile({ email => 1 })->analyze->html5_validation() }->{pattern};
diff --git a/lib/VN3/Types.pm b/lib/VN3/Types.pm
index b8fb3ca0..18e481b0 100644
--- a/lib/VN3/Types.pm
+++ b/lib/VN3/Types.pm
@@ -20,7 +20,7 @@ our @EXPORT = qw/
%PRODUCER_TYPES
ReleaseDate
@VN_LENGTHS vn_length_time vn_length_display
- %CHAR_ROLES char_roles char_role_display
+ char_roles char_role_display
vote_display vote_string
date_display
vn_relation_reverse vn_relation_display
@@ -31,8 +31,8 @@ our @EXPORT = qw/
%RESOLUTIONS resolution_display_full
@VOICED
@ANIMATED
- %GENDERS gender_display gender_icon
- %BLOOD_TYPES blood_type_display
+ gender_display gender_icon
+ blood_type_display
/;
@@ -137,18 +137,9 @@ sub vn_length_display {
-our %CHAR_ROLES;
-tie %CHAR_ROLES, 'Tie::IxHash',
- main => [ 'Protagonist', 'Protagonists' ],
- primary => [ 'Main character', 'Main characters' ],
- side => [ 'Side character', 'Side characters' ],
- appears => [ 'Makes an appearance', 'Make an appearance' ];
-
-sub char_roles { keys %CHAR_ROLES }
-
sub char_role_display {
my($role, $num) = @_;
- $CHAR_ROLES{$role}[!$num || $num == 1 ? 0 : 1];
+ $CHAR_ROLE{$role}{!$num || $num == 1 ? 'txt' : 'plural'};
}
@@ -252,22 +243,12 @@ our @ANIMATED = ('Unknown', 'No animations', 'Simple animations', 'Some fully an
-our %GENDERS;
-tie %GENDERS, 'Tie::IxHash',
- unknown => [ 'Unknown', '' ],
- m => [ 'Male', '♂' ],
- f => [ 'Female', '♀' ],
- mf => [ 'Both', '♂♀' ];
-
-sub gender_display { $GENDERS{$_[0]}[0] }
-sub gender_icon { $GENDERS{$_[0]}[1] }
-
+sub gender_display { $GENDER{$_[0]} }
+sub gender_icon { +{qw/m ♂ f ♀ mf ♂♀/}->{$_[0]}||'' }
-our %BLOOD_TYPES;
-tie %BLOOD_TYPES, 'Tie::IxHash', qw/unknown Unknown o O a A b B ab AB/;
-sub blood_type_display { $BLOOD_TYPES{$_[0]} }
+sub blood_type_display { $BLOOD_TYPE{$_[0]} }
1;
diff --git a/lib/VN3/VN/Page.pm b/lib/VN3/VN/Page.pm
index d71f1ac1..a09bbeb9 100644
--- a/lib/VN3/VN/Page.pm
+++ b/lib/VN3/VN/Page.pm
@@ -343,7 +343,7 @@ sub CharacterList {
A mkclass('character-browser__char' => 1, 'character-browser__char--active' => $_->{id} == $first_char),
href => "/c$_->{id}", title => $_->{original}||$_->{name}, 'data-character' => $_->{id}, $_->{name}
for @{$roles->{$_}};
- } for grep @{$roles->{$_}}, char_roles;
+ } for grep @{$roles->{$_}}, keys %CHAR_ROLE;
}
@@ -464,9 +464,9 @@ sub Characters {
my %roles = map {
my $r = $_;
($r, [ grep grep($_->{role} eq $r, @{$_->{releases}}) && !$done{$_->{id}}++, @$chars ]);
- } char_roles;
+ } keys %CHAR_ROLE;
- my($first_char) = map @{$roles{$_}} ? $roles{$_}[0]{id} : (), char_roles;
+ my($first_char) = map @{$roles{$_}} ? $roles{$_}[0]{id} : (), keys %CHAR_ROLE;
Div class => 'section', id => 'characters', sub {
H2 class => 'section__title', sub { Txt 'Characters'; Debug \%roles };
diff --git a/lib/VN3/Validation.pm b/lib/VN3/Validation.pm
index 91f09e68..5c1c73d7 100644
--- a/lib/VN3/Validation.pm
+++ b/lib/VN3/Validation.pm
@@ -27,13 +27,13 @@ TUWF::set custom_validations => {
vn_relation => { enum => \%VN_RELATION },
producer_relation => { enum => \%PRODUCER_RELATION },
staff_role => { enum => \%CREDIT_TYPE },
- char_role => { enum => \%CHAR_ROLES },
+ char_role => { enum => \%CHAR_ROLE },
language => { enum => \%LANGUAGE },
platform => { enum => \%PLATFORM },
medium => { enum => \%MEDIA },
resolution => { enum => \%RESOLUTIONS },
- gender => { enum => \%GENDERS },
- blood_type => { enum => \%BLOOD_TYPES },
+ gender => { enum => \%GENDER },
+ blood_type => { enum => \%BLOOD_TYPE },
gtin => { uint => 1, func => sub { $_[0] eq 0 || gtintype($_[0]) } },
minage => { uint => 1, enum => \@MINAGE },
animated => { uint => 1, range => [ 0, $#ANIMATED ] },
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index 4ef583c7..59b365fe 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -6,6 +6,7 @@ use warnings;
use TUWF ':html', 'uri_escape';
use Exporter 'import';
use VNDB::Func;
+use VNDB::Types;
use List::Util 'min';
our @EXPORT = ('charOps', 'charTable', 'charBrowseTable');
@@ -46,7 +47,7 @@ sub page {
[ original => 'Original name', diff => 1 ],
[ alias => 'Aliases', diff => qr/[ ,\n\.]/ ],
[ desc => 'Description', diff => qr/[ ,\n\.]/ ],
- [ gender => 'Sex', serialize => sub { $self->{genders}{$_[0]} } ],
+ [ gender => 'Sex', serialize => sub { $GENDER{$_[0]} } ],
[ b_month => 'Birthday/month',serialize => sub { $_[0]||'[empty]' } ],
[ b_day => 'Birthday/day', serialize => sub { $_[0]||'[empty]' } ],
[ s_bust => 'Bust', serialize => sub { $_[0]||'[empty]' } ],
@@ -54,7 +55,7 @@ sub page {
[ s_hip => 'Hip', serialize => sub { $_[0]||'[empty]' } ],
[ height => 'Height', serialize => sub { $_[0]||'[empty]' } ],
[ weight => 'Weight', serialize => sub { $_[0]//'[empty]' } ],
- [ bloodt => 'Blood type', serialize => sub { $self->{blood_types}{$_[0]} } ],
+ [ bloodt => 'Blood type', serialize => sub { $BLOOD_TYPE{$_[0]} } ],
[ main => 'Main character',htmlize => sub { $_[0] ? sprintf '<a href="/c%d">c%d</a>', $_[0], $_[0] : '[empty]' } ],
[ main_spoil=> 'Spoiler', serialize => \&fmtspoil ],
[ image => 'Image', htmlize => sub {
@@ -67,7 +68,7 @@ sub page {
[ vns => 'Visual novels', join => '<br />', split => sub {
map sprintf('<a href="/v%d">v%d</a> %s %s (%s)', $_->{vid}, $_->{vid},
$_->{rid}?sprintf('[<a href="/r%d">r%d</a>]', $_->{rid}, $_->{rid}):'',
- $self->{char_roles}{$_->{role}}[0], fmtspoil $_->{spoil}), @{$_[0]};
+ $CHAR_ROLE{$_->{role}}{txt}, fmtspoil $_->{spoil}), @{$_[0]};
}],
);
}
@@ -157,8 +158,8 @@ sub charTable {
b style => 'margin-right: 10px', $r->{name};
}
b class => 'grayedout', style => 'margin-right: 10px', $r->{original} if $r->{original};
- cssicon "gen $r->{gender}", $self->{genders}{$r->{gender}} if $r->{gender} ne 'unknown';
- span $self->{blood_types}{$r->{bloodt}} if $r->{bloodt} ne 'unknown';
+ cssicon "gen $r->{gender}", $GENDER{$r->{gender}} if $r->{gender} ne 'unknown';
+ span $BLOOD_TYPE{$r->{bloodt}} if $r->{bloodt} ne 'unknown';
end;
end;
end;
@@ -224,7 +225,7 @@ sub charTable {
# special case: all releases, no exceptions
if(!$vn && @r == 1 && !$r[0]{rid}) {
span class => charspoil $r[0]{spoil};
- txt $self->{char_roles}{$r[0]{role}}[0].' - ';
+ txt $CHAR_ROLE{$r[0]{role}}{txt}.' - ';
a href => "/v$r[0]{vid}/chars", $r[0]{vntitle};
end;
next;
@@ -238,7 +239,7 @@ sub charTable {
span class => charspoil $_->{spoil};
br if !$vn || $_ != $r[0];
b class => 'grayedout', '> ';
- txt $self->{char_roles}{$_->{role}}[0].' - ';
+ txt $CHAR_ROLE{$_->{role}}{txt}.' - ';
if($_->{rid}) {
b class => 'grayedout', "r$_->{rid}:";
a href => "/r$_->{rid}", $_->{rtitle};
@@ -318,7 +319,7 @@ sub edit {
{ post => 'original', required => 0, maxlength => 200, default => '' },
{ post => 'alias', required => 0, maxlength => 500, default => '' },
{ post => 'desc', required => 0, maxlength => 5000, default => '' },
- { post => 'gender', required => 0, default => 'unknown', enum => [ keys %{$self->{genders}} ] },
+ { post => 'gender', required => 0, default => 'unknown', enum => [ keys %GENDER ] },
{ post => 'image', required => 0, default => 0, template => 'id' },
{ post => 'bday', required => 0, default => '', regex => [ qr/^(?:[01]?[0-9])-(?:[0123]?[0-9])$/, 'Birthday must be in MM-DD format.' ] },
{ post => 's_bust', required => 0, default => 0, template => 'uint', max => 32767 },
@@ -326,7 +327,7 @@ sub edit {
{ post => 's_hip', required => 0, default => 0, template => 'uint', max => 32767 },
{ post => 'height', required => 0, default => 0, template => 'uint', max => 32767 },
{ post => 'weight', required => 0, default => undef, template => 'uint', max => 32767 },
- { post => 'bloodt', required => 0, default => 'unknown', enum => [ keys %{$self->{blood_types}} ] },
+ { post => 'bloodt', required => 0, default => 'unknown', enum => [ keys %BLOOD_TYPE ] },
{ post => 'main', required => 0, default => 0, template => 'id' },
{ post => 'main_spoil', required => 0, default => 0, enum => [ 0..2 ] },
{ post => 'traits', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-[0-2])(?: +[1-9]\d*-[0-2])*$/, 'Incorrect trait format.' ] },
@@ -404,7 +405,7 @@ sub edit {
[ static => content => '(Un)official aliases, separated by a newline.' ],
[ text => name => 'Description<br /><b class="standout">English please!</b>', short => 'desc', rows => 6 ],
[ select => name => 'Sex', short => 'gender', options => [
- map [ $_, $self->{genders}{$_} ], keys %{$self->{genders}} ] ],
+ map [ $_, $GENDER{$_} ], keys %GENDER ] ],
[ input => name => 'Birthday', short => 'bday', width => 100,post => ' MM-DD (e.g. "01-26" for the 26th of January)' ],
[ input => name => 'Bust', short => 's_bust', width => 50, post => ' cm' ],
[ input => name => 'Waist', short => 's_waist',width => 50, post => ' cm' ],
@@ -412,7 +413,7 @@ sub edit {
[ input => name => 'Height', short => 'height', width => 50, post => ' cm' ],
[ input => name => 'Weight', short => 'weight', width => 50, post => ' kg', allow0 => 1 ],
[ select => name => 'Blood type',short => 'bloodt', options => [
- map [ $_, $self->{blood_types}{$_} ], keys %{$self->{blood_types}} ] ],
+ map [ $_, $BLOOD_TYPE{$_} ], keys %BLOOD_TYPE ] ],
[ static => content => '<br />' ],
[ input => name => 'Instance of',short => 'main', width => 50, post => ' ID of the main character - the character of which this is an instance of.' ],
[ select => name => 'Spoiler', short => 'main_spoil', options => [
@@ -580,7 +581,7 @@ sub charBrowseTable {
my($s, $n, $l) = @_;
Tr;
td class => 'tc1';
- cssicon "gen $l->{gender}", $self->{genders}{$l->{gender}} if $l->{gender} ne 'unknown';
+ cssicon "gen $l->{gender}", $GENDER{$l->{gender}} if $l->{gender} ne 'unknown';
end;
td class => 'tc2';
a href => "/c$l->{id}", title => $l->{original}||$l->{name}, shorten $l->{name}, 50;
diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm
index ceaf56bb..fc62843a 100644
--- a/lib/VNDB/Handler/Staff.pm
+++ b/lib/VNDB/Handler/Staff.pm
@@ -42,7 +42,7 @@ sub page {
$self->htmlRevision('s', $prev, $s,
[ name => 'Name (romaji)', diff => 1 ],
[ original => 'Original name', diff => 1 ],
- [ gender => 'Gender', serialize => sub { $self->{genders}{$_[0]} } ],
+ [ gender => 'Gender', serialize => sub { $GENDER{$_[0]} } ],
[ lang => 'Language', serialize => sub { "$_[0] ($LANGUAGE{$_[0]})" } ],
[ l_site => 'Official page', diff => 1 ],
[ l_wp => 'Wikipedia link', htmlize => sub { $_[0] ? sprintf '<a href="http://en.wikipedia.org/wiki/%s">%1$s</a>', xml_escape $_[0] : '[empty]' }],
@@ -69,7 +69,7 @@ sub page {
td colspan => 2;
b style => 'margin-right: 10px', $s->{name};
b class => 'grayedout', style => 'margin-right: 10px', $s->{original} if $s->{original};
- cssicon "gen $s->{gender}", $self->{genders}{$s->{gender}} if $s->{gender} ne 'unknown';
+ cssicon "gen $s->{gender}", $GENDER{$s->{gender}} if $s->{gender} ne 'unknown';
end;
end;
end;
@@ -278,7 +278,7 @@ sub edit {
[ static => content => '<br />' ],
[ text => name => 'Staff note<br /><b class="standout">English please!</b>', short => 'desc', rows => 4 ],
[ select => name => 'Gender',short => 'gender', options => [
- map [ $_, $self->{genders}{$_} ], qw(unknown m f) ] ],
+ map [ $_, $GENDER{$_} ], qw(unknown m f) ] ],
[ select => name => 'Primary language', short => 'lang',
options => [ map [ $_, "$_ ($LANGUAGE{$_})" ], keys %LANGUAGE ] ],
[ input => name => 'Official page', short => 'l_site' ],
@@ -354,7 +354,6 @@ sub list {
ul;
for ($perlist*$c..($perlist*($c+1))-1) {
li;
- my $gender = $list->[$_]{gender};
cssicon 'lang '.$list->[$_]{lang}, $LANGUAGE{$list->[$_]{lang}};
a href => "/s$list->[$_]{id}",
title => $list->[$_]{original}, $list->[$_]{name};
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index d8e0840e..614ae166 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -976,15 +976,15 @@ sub _chars {
return if !@$l;
my %done;
my %rol;
- for my $r (keys %{$self->{char_roles}}) {
+ for my $r (keys %CHAR_ROLE) {
$rol{$r} = [ grep grep($_->{role} eq $r, @{$_->{vns}}) && !$done{$_->{id}}++, @$l ];
}
div class => 'charops', id => 'charops';
$self->charOps(1, 'chars');
- for my $r (keys %{$self->{char_roles}}) {
+ for my $r (keys %CHAR_ROLE) {
next if !@{$rol{$r}};
div class => 'mainbox';
- h1 $self->{char_roles}{$r}[ @{$rol{$r}} > 1 ? 1 : 0 ];
+ h1 $CHAR_ROLE{$r}{ @{$rol{$r}} > 1 ? 'plural' : 'txt' };
$self->charTable($_, 1, $_ != $rol{$r}[0], 1, _charspoillvl $v->{id}, $_) for (@{$rol{$r}});
end;
}
@@ -997,7 +997,7 @@ sub _charsum {
return if !@$l;
my(@l, %done, $has_spoilers);
- for my $r (keys %{$self->{char_roles}}) {
+ for my $r (keys %CHAR_ROLE) {
last if $r eq 'appears';
for (grep grep($_->{role} eq $r, @{$_->{vns}}) && !$done{$_->{id}}++, @$l) {
$_->{role} = $r;
@@ -1013,8 +1013,8 @@ sub _charsum {
for my $c (@l) {
div class => 'charsum_bubble'.($has_spoilers ? ' '.charspoil(_charspoillvl $v->{id}, $c) : '');
div class => 'name';
- i $self->{char_roles}{$c->{role}}[0];
- cssicon "gen $c->{gender}", $self->{genders}{$c->{gender}} if $c->{gender} ne 'unknown';
+ i $CHAR_ROLE{$c->{role}}{txt};
+ cssicon "gen $c->{gender}", $GENDER{$c->{gender}} if $c->{gender} ne 'unknown';
a href => "/c$c->{id}", title => $c->{original}||$c->{name}, $c->{name};
end;
if(@{$c->{seiyuu}}) {
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 8c29df3b..aa642762 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -171,3 +171,27 @@ hash VNLIST_STATUS =>
2 => 'Finished',
3 => 'Stalled',
4 => 'Dropped';
+
+
+
+# SQL: ENUM blood_type
+hash BLOOD_TYPE =>
+ unknown => 'Unknown',
+ o => 'O',
+ a => 'A',
+ b => 'B',
+ ab => 'AB';
+
+# SQL: ENUM blood_type
+hash GENDER =>
+ unknown => 'Unknown or N/A',
+ m => 'Male',
+ f => 'Female',
+ b => 'Both';
+
+# SQL: ENUM char_role
+hash CHAR_ROLE =>
+ main => { txt => 'Protagonist', plural => 'Protagonists' },
+ primary => { txt => 'Main character', plural => 'Main characters' },
+ side => { txt => 'Side character', plural => 'Side characters' },
+ appears => { txt => 'Makes an appearance', plural => 'Make an appearance' };
diff --git a/util/jsgen.pl b/util/jsgen.pl
index 7228276f..8c44fb99 100755
--- a/util/jsgen.pl
+++ b/util/jsgen.pl
@@ -41,14 +41,14 @@ sub vars {
age_ratings => [ map [ $_, $_ == -1 ? 'Unknown' : $_ == 0 ? 'All ages' : "$_+" ], @{$S{age_ratings}} ],
languages => [ map [ $_, $LANGUAGE{$_} ], keys %LANGUAGE ],
platforms => [ map [ $_, $PLATFORM{$_} ], keys %PLATFORM ],
- char_roles => [ map [ $_, $S{char_roles}{$_}[0] ], keys %{$S{char_roles}} ],
+ 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}} ],
animated => [ map [ $_, $S{animated}[$_] ], 0..$#{$S{animated}} ],
voiced => [ map [ $_, $S{voiced}[$_] ], 0..$#{$S{voiced}} ],
vn_lengths => [ map [ $_, $S{vn_lengths}[$_][0] ], 0..$#{$S{vn_lengths}} ],
- blood_types => [ map [ $_, $S{blood_types}{$_} ], keys %{$S{blood_types}} ],
- genders => [ map [ $_, $S{genders}{$_} ], keys %{$S{genders}} ],
+ blood_types => [ map [ $_, $BLOOD_TYPE{$_} ], keys %BLOOD_TYPE ],
+ genders => [ map [ $_, $GENDER{$_} ], keys %GENDER ],
credit_type => [ map [ $_, $CREDIT_TYPE{$_} ], keys %CREDIT_TYPE ],
resolutions => scalar resolutions(),
);