summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Releases
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-06-15 19:00:39 +0200
committerYorhel <git@yorhel.nl>2020-06-15 19:00:41 +0200
commit7f02fd77fd71022712407c78816cc41e75b2fbc0 (patch)
tree4cfe76fad2d9daedf3dbd530e1aebbfc88d53e05 /lib/VNWeb/Releases
parent1febd87dd16439203ee0de1f1adc6e9be75860e9 (diff)
Releases: Allow custom resolutions to be entered
The resolution field now works much like the engine field.
Diffstat (limited to 'lib/VNWeb/Releases')
-rw-r--r--lib/VNWeb/Releases/Edit.pm47
-rw-r--r--lib/VNWeb/Releases/Lib.pm8
-rw-r--r--lib/VNWeb/Releases/Page.pm8
3 files changed, 39 insertions, 24 deletions
diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm
index a315d96b..d7f62cdf 100644
--- a/lib/VNWeb/Releases/Edit.pm
+++ b/lib/VNWeb/Releases/Edit.pm
@@ -22,7 +22,8 @@ my $FORM = {
released => { default => 99999999, min => 1, rdate => 1 },
minage => { int => 1, enum => \%AGE_RATING },
uncensored => { anybool => 1 },
- resolution => { default => 'unknown', enum => \%RESOLUTION },
+ reso_x => { uint => 1, range => [0,32767] },
+ reso_y => { uint => 1, range => [0,32767] },
voiced => { uint => 1, enum => \%VOICED },
ani_story => { uint => 1, enum => \%ANIMATED },
ani_ero => { uint => 1, enum => \%ANIMATED },
@@ -47,6 +48,10 @@ my $FORM = {
engine => {},
count => { uint => 1 },
} },
+ resolutions=> { _when => 'out', aoh => {
+ resolution => {},
+ count => { uint => 1 },
+ } },
authmod => { _when => 'out', anybool => 1 },
editsum => { _when => 'in out', editsum => 1 },
};
@@ -57,23 +62,29 @@ my $FORM_CMP = form_compile cmp => $FORM;
sub to_extlinks { $_[0]{extlinks} = { map +($_, delete $_[0]{$_}), grep /^l_/, keys $_[0]->%* } }
-sub engines {
- tuwf->dbAlli(q{
- SELECT engine, count(*) AS count FROM releases WHERE NOT hidden AND engine <> ''
- GROUP BY engine ORDER BY count(*) DESC, engine
- })
+sub enrich_form {
+ my($e) = @_;
+ $e->{authmod} = auth->permDbmod;
+ $e->{engines} = tuwf->dbAlli(q{
+ SELECT engine, count(*) AS count FROM releases WHERE NOT hidden AND engine <> ''
+ GROUP BY engine ORDER BY count(*) DESC, engine
+ });
+ $e->{resolutions} = [ map +{ resolution => resolution($_), count => $_->{count} }, tuwf->dbAlli(q{
+ SELECT reso_x, reso_y, count(*) AS count FROM releases WHERE NOT hidden AND NOT (reso_x = 0 AND reso_y = 0)
+ GROUP BY reso_x, reso_y ORDER BY count(*) DESC
+ })->@* ];
}
+
TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub {
my $e = db_entry r => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound;
my $copy = tuwf->capture('action') eq 'copy';
return tuwf->resDenied if !can_edit r => $copy ? {} : $e;
$e->{rtype} = delete $e->{type};
- $e->{authmod} = auth->permDbmod;
$e->{editsum} = $copy ? "Copied from r$e->{id}.$e->{chrev}" : $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision r$e->{id}.$e->{chrev}";
- $e->{engines} = engines;
+ enrich_form $e;
to_extlinks $e;
enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vn};
@@ -98,6 +109,14 @@ TUWF::get qr{/$RE{vid}/add}, sub {
my $delrel = tuwf->dbAlli('SELECT r.id, r.title, r.original FROM releases r JOIN releases_vn rv ON rv.id = r.id WHERE r.hidden AND rv.vid =', \$v->{id}, 'ORDER BY id');
enrich_flatten languages => id => id => 'SELECT id, lang FROM releases_lang WHERE id IN', $delrel;
+ my $e = {
+ elm_empty($FORM_OUT)->%*,
+ title => $v->{title},
+ original => $v->{original},
+ vn => [{vid => $v->{id}, title => $v->{title}}],
+ };
+ enrich_form $e;
+
framework_ title => "Add release to $v->{title}",
sub {
editmsg_ r => undef, "Add release to $v->{title}";
@@ -118,14 +137,7 @@ TUWF::get qr{/$RE{vid}/add}, sub {
}
} if @$delrel;
- elm_ ReleaseEdit => $FORM_OUT, {
- elm_empty($FORM_OUT)->%*,
- title => $v->{title},
- original => $v->{original},
- engines => engines(),
- authmod => auth->permDbmod(),
- vn => [{vid => $v->{id}, title => $v->{title}}],
- };
+ elm_ ReleaseEdit => $FORM_OUT, $e;
};
};
@@ -141,11 +153,12 @@ elm_api ReleaseEdit => $FORM_OUT, $FORM_IN, sub {
$data->{locked} = $e->{locked}||0;
}
$data->{doujin} = $data->{voiced} = $data->{ani_story} = $data->{ani_ero} = 0 if $data->{patch};
- $data->{resolution} = 'unknown' if $data->{patch};
+ $data->{reso_x} = $data->{reso_y} = 0 if $data->{patch};
$data->{uncensored} = $data->{ani_ero} = 0 if $data->{minage} != 18;
$_->{qty} = $MEDIUM{$_->{medium}}{qty} ? $_->{qty}||1 : 0 for $data->{media}->@*;
$data->{notes} = bb_subst_links $data->{notes};
die "No VNs selected" if !$data->{vn}->@*;
+ die "Invalid resolution: ($data->{reso_x},$data->{reso_y})" if (!$data->{reso_x} && $data->{reso_y} > 1) || ($data->{reso_x} && !$data->{reso_y});
to_extlinks $e;
$e->{rtype} = delete $e->{type};
diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm
index de25258a..7b36a290 100644
--- a/lib/VNWeb/Releases/Lib.pm
+++ b/lib/VNWeb/Releases/Lib.pm
@@ -10,7 +10,7 @@ our @EXPORT = qw/enrich_release release_row_/;
# Assumption: Each release already has id, type, patch, released, gtin and enrich_extlinks().
sub enrich_release {
my($r) = @_;
- enrich_merge id => 'SELECT id, title, original, notes, minage, freeware, doujin, resolution, voiced, ani_story, ani_ero, uncensored FROM releases WHERE id IN', $r;
+ enrich_merge id => 'SELECT id, title, original, notes, minage, freeware, doujin, reso_x, reso_y, voiced, ani_story, ani_ero, uncensored FROM releases WHERE id IN', $r;
enrich_merge id => sql('SELECT rid as id, status as rlist_status FROM rlists WHERE uid =', \auth->uid, 'AND rid IN'), $r if auth;
enrich_flatten lang => id => id => sub { sql 'SELECT id, lang FROM releases_lang WHERE id IN', $_, 'ORDER BY id, lang' }, $r;
enrich_flatten platforms => id => id => sub { sql 'SELECT id, platform FROM releases_platforms WHERE id IN', $_, 'ORDER BY id, platform' }, $r;
@@ -68,11 +68,11 @@ sub release_row_ {
icon_ 'nonfree', 'Non-free' if !$r->{freeware};
icon_ 'doujin', 'Doujin' if !$r->{patch} && $r->{doujin};
icon_ 'commercial', 'Commercial' if !$r->{patch} && !$r->{doujin};
- if($r->{resolution} ne 'unknown') {
- my $type = $r->{resolution} eq 'nonstandard' ? 'custom' : $RESOLUTION{$r->{resolution}}{cat} eq 'widescreen' ? '16-9' : '4-3';
+ if($r->{reso_y}) {
+ my $type = $r->{reso_y} == 1 ? 'custom' : $r->{reso_x} / $r->{reso_y} > 4/3 ? '16-9' : '4-3';
# Ugly workaround: PC-98 has non-square pixels, thus not widescreen
$type = '4-3' if $type eq '16-9' && grep $_ eq 'p98', $r->{platforms}->@*;
- icon_ "resolution_$type", $RESOLUTION{$r->{resolution}}{txt};
+ icon_ "resolution_$type", resolution $r;
}
icon_ $MEDIUM{ $r->{media}[0]{medium} }{icon}, join ', ', map fmtmedia($_->{medium}, $_->{qty}), $r->{media}->@* if $r->{media}->@*;
icon_ 'uncensor', 'Uncensored' if $r->{uncensored};
diff --git a/lib/VNWeb/Releases/Page.pm b/lib/VNWeb/Releases/Page.pm
index 77a50f27..ccf4b6fb 100644
--- a/lib/VNWeb/Releases/Page.pm
+++ b/lib/VNWeb/Releases/Page.pm
@@ -14,6 +14,8 @@ sub enrich_item {
$r->{vn} = [ sort { $a->{title} cmp $b->{title} || $a->{vid} <=> $b->{vid} } $r->{vn}->@* ];
$r->{producers} = [ sort { $a->{name} cmp $b->{name} || $a->{pid} <=> $b->{pid} } $r->{producers}->@* ];
$r->{media} = [ sort { $a->{medium} cmp $b->{medium} || $a->{qty} <=> $b->{qty} } $r->{media}->@* ];
+
+ $r->{resolution} = resolution $r;
}
@@ -36,7 +38,7 @@ sub _rev_ {
[ notes => 'Notes' ],
[ platforms => 'Platforms', fmt => \%PLATFORM ],
[ media => 'Media', fmt => sub { txt_ fmtmedia $_->{medium}, $_->{qty}; } ],
- [ resolution => 'Resolution', fmt => \%RESOLUTION ],
+ [ resolution => 'Resolution' ],
[ voiced => 'Voiced', fmt => \%VOICED ],
[ ani_story => 'Story animation', fmt => \%ANIMATED ],
[ ani_ero => 'Ero animation', fmt => \%ANIMATED ],
@@ -119,8 +121,8 @@ sub _infotable_ {
tr_ sub {
td_ 'Resolution';
- td_ $RESOLUTION{$r->{resolution}}{txt};
- } if $r->{resolution} ne 'unknown';
+ td_ resolution $r;
+ } if $r->{reso_y};
tr_ sub {
td_ 'Voiced';