summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2018-10-02 12:54:41 +0200
committerYorhel <git@yorhel.nl>2018-10-02 12:56:38 +0200
commit6bd0b0cd1f3892253d881f71533940f0cf07c13d (patch)
tree852ffd40f3aaa4aea6c04245e71a45ef73a7e372 /lib/VNDB/Handler
parent815f9b1496c75026c9e3ea57bac2f5d5348085ba (diff)
DB: Convert resolution into an enum
Been wanting to do this for a long time - using an integer index into an array that changes once in a while is way too fragile. Doubly so when said indices are also used in filters and URLs that can't be updated every time a new resolution is added.
Diffstat (limited to 'lib/VNDB/Handler')
-rw-r--r--lib/VNDB/Handler/Releases.pm15
-rw-r--r--lib/VNDB/Handler/VNPage.pm14
2 files changed, 12 insertions, 17 deletions
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index d69d20af..ad32e78f 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -62,7 +62,7 @@ sub page {
[ notes => 'Notes', diff => qr/[ ,\n\.]/ ],
[ platforms => 'Platforms', join => ', ', split => sub { map $self->{platforms}{$_}, @{$_[0]} } ],
[ media => 'Media', join => ', ', split => sub { map fmtmedia($_->{medium}, $_->{qty}), @{$_[0]} } ],
- [ resolution => 'Resolution', serialize => sub { $self->{resolutions}[$_[0]][0]; } ],
+ [ resolution => 'Resolution', serialize => sub { $self->{resolutions}{$_[0]}[0]; } ],
[ voiced => 'Voiced', serialize => sub { $self->{voiced}[$_[0]] } ],
[ ani_story => 'Story animation', serialize => sub { $self->{animated}[$_[0]] } ],
[ ani_ero => 'Ero animation', serialize => sub { $self->{animated}[$_[0]] } ],
@@ -164,10 +164,10 @@ sub _infotable {
end;
}
- if($r->{resolution}) {
+ if($r->{resolution} ne 'unknown') {
Tr;
td 'Resolution';
- td $self->{resolutions}[$r->{resolution}][0];
+ td $self->{resolutions}{$r->{resolution}}[0];
end;
}
@@ -324,7 +324,7 @@ sub edit {
{ post => 'notes', required => 0, default => '', maxlength => 10240 },
{ post => 'platforms', required => 0, default => '', multi => 1, enum => [ keys %{$self->{platforms}} ] },
{ post => 'media', required => 0, default => '' },
- { post => 'resolution',required => 0, default => 0, enum => [ 0..$#{$self->{resolutions}} ] },
+ { post => 'resolution',required => 0, default => 0, enum => [ keys %{$self->{resolutions}} ] },
{ post => 'voiced', required => 0, default => 0, enum => [ 0..$#{$self->{voiced}} ] },
{ post => 'ani_story', required => 0, default => 0, enum => [ 0..$#{$self->{animated}} ] },
{ post => 'ani_ero', required => 0, default => 0, enum => [ 0..$#{$self->{animated}} ] },
@@ -347,7 +347,8 @@ sub edit {
$frm->{$_} = $frm->{$_} ? 1 : 0 for (qw|patch freeware doujin uncensored ihid ilock|);
# reset some fields when the patch flag is set
- $frm->{doujin} = $frm->{resolution} = $frm->{voiced} = $frm->{ani_story} = $frm->{ani_ero} = 0 if $frm->{patch};
+ $frm->{doujin} = $frm->{voiced} = $frm->{ani_story} = $frm->{ani_ero} = 0 if $frm->{patch};
+ $frm->{resolution} = 'unknown' if $frm->{patch};
$frm->{uncensored} = 0 if $frm->{minage} != 18;
my $same = $rid &&
@@ -422,7 +423,7 @@ sub _form {
rel_format => [ 'Format',
[ select => short => 'resolution', name => 'Resolution', options => [
- map [ $_, @{$self->{resolutions}[$_]} ], 0..$#{$self->{resolutions}} ] ],
+ map [ $_, @{$self->{resolutions}{$_}} ], keys %{$self->{resolutions}} ] ],
[ select => short => 'voiced', name => 'Voiced', options => [
map [ $_, $self->{voiced}[$_] ], 0..$#{$self->{voiced}} ] ],
[ select => short => 'ani_story', name => 'Story animation', options => [
@@ -611,7 +612,6 @@ sub _fil_compat {
{ get => 'ma_a', required => 0, default => 0, enum => $self->{age_ratings} },
{ get => 'mi', required => 0, default => 0, template => 'uint' },
{ get => 'ma', required => 0, default => 99999999, template => 'uint' },
- { get => 're', required => 0, multi => 1, default => 0, enum => [ 1..$#{$self->{resolutions}} ] },
);
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};
@@ -620,7 +620,6 @@ sub _fil_compat {
$c{plat} = $f->{pl} if $f->{pl}[0];
$c{lang} = $f->{ln} if $f->{ln}[0];
$c{med} = $f->{me} if $f->{me}[0];
- $c{resolution} = $f->{re} if $f->{re}[0];
$c{type} = $f->{tp} if $f->{tp};
$c{patch} = $f->{pa} == 2 ? 0 : 1 if $f->{pa};
$c{freeware} = $f->{fw} == 2 ? 0 : 1 if $f->{fw};
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 565d73ce..0bf9ec4d 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -122,13 +122,9 @@ my @rel_cols = (
na_for_patch => 1,
default => 1,
what => 'extended',
- has_data => sub { !!$_[0]{resolution} },
+ has_data => sub { $_[0]{resolution} ne 'unknown' },
draw => sub {
- if($_[0]{resolution}) {
- txt $TUWF::OBJ->{resolutions}[$_[0]{resolution}][0];
- } else {
- txt 'Unknown';
- }
+ txt $_[0]{resolution} eq 'unknown' ? 'Unknown' : $TUWF::OBJ->{resolutions}{$_[0]{resolution}}[0];
},
}, { # Voiced
id => 'voi',
@@ -869,11 +865,11 @@ sub _release_icons {
# Resolution column
my $resolution = $rel->{resolution};
- if($resolution) {
- my $resolution_type = $resolution == 1 ? 'custom' : $self->{resolutions}[$resolution][1] eq 'widescreen' ? '16-9' : '4-3';
+ if($resolution ne 'unknown') {
+ my $resolution_type = $resolution eq 'nonstandard' ? 'custom' : $self->{resolutions}{$resolution}[1] eq 'widescreen' ? '16-9' : '4-3';
# Ugly workaround: PC-98 has non-square pixels, thus not widescreen
$resolution_type = '4-3' if $resolution_type eq '16-9' && grep $_ eq 'p98', @{$rel->{platforms}};
- _release_icon "res$resolution_type", $self->{resolutions}[$resolution][0], "resolution_$resolution_type";
+ _release_icon "res$resolution_type", $self->{resolutions}{$resolution}[0], "resolution_$resolution_type";
}
# Media column