summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-02-13 18:26:18 +0100
committerYorhel <git@yorhel.nl>2020-02-13 18:26:22 +0100
commitc3cf4594086e1ebfb7023c147705f45c68fa46f3 (patch)
treecf2af47374a8c72acc13f2ffcbba9f555e46e22a
parentb95cccca4533846f5784007dea969629510e92f7 (diff)
Chars::Page: Only show spoiler & sexual traits settings when they do something
i.e. when there's something on the page that would be hidden with different settings. For individual fields, just knowing that something is a spoiler is in itself a spoiler. But when it comes to the entire page, I can't imagine a case where "there is a spoiler somewhere on this page" would by itself be a spoiler, so this should be safe enough. Better than clicking on spoiler settings that don't do anything.
-rw-r--r--lib/VNWeb/Chars/Page.pm36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/VNWeb/Chars/Page.pm b/lib/VNWeb/Chars/Page.pm
index 58323bcd..fe2edd03 100644
--- a/lib/VNWeb/Chars/Page.pm
+++ b/lib/VNWeb/Chars/Page.pm
@@ -220,6 +220,23 @@ TUWF::get qr{/$RE{crev}} => sub {
enrich_seiyuu undef, $c;
my $view = viewget;
+ my $inst_maxspoil = tuwf->dbVali('SELECT MAX(main_spoil) FROM chars WHERE NOT hidden AND main IN', [ $c->{id}, $c->{main}||() ]);
+
+ my $inst = !defined($inst_maxspoil) || ($c->{main} && $c->{main_spoil} > $view->{spoilers}) ? []
+ : fetch_chars undef, sql
+ # If this entry doesn't have a 'main', look for other entries with a 'main' referencing this entry
+ !$c->{main} ? ('main =', \$c->{id}, 'AND main_spoil <=', \$view->{spoilers}) :
+ # Otherwise, look for other entries with the same 'main', and also fetch the 'main' entry itself
+ ('(id <>', \$c->{id}, 'AND main =', \$c->{main}, 'AND main_spoil <=', \$view->{spoilers}, ') OR id =', \$c->{main});
+
+ my $max_spoil = max(
+ $inst_maxspoil||0,
+ (map $_->{spoil}, $c->{traits}->@*),
+ $c->{desc} =~ /\[spoiler\]/i ? 2 : 0, # crude
+ );
+ # Only display the sexual traits toggle when there are sexual traits within the current spoiler level.
+ my $has_sex = grep $_->{spoil} <= $view->{spoilers} && $_->{sexual}, map $_->{traits}->@*, $c, @$inst;
+
framework_ title => $c->{name}, index => !tuwf->capture('rev'), type => 'c', dbobj => $c, hiddenmsg => 1,
og => {
description => bb2text $c->{desc}
@@ -229,24 +246,19 @@ TUWF::get qr{/$RE{crev}} => sub {
div_ class => 'mainbox', sub {
itemmsg_ c => $c;
p_ class => 'mainopts', sub {
- a_ mkclass(checked => $view->{spoilers} == 0), href => '?view='.viewset(spoilers=>0), 'Hide spoilers';
- a_ mkclass(checked => $view->{spoilers} == 1), href => '?view='.viewset(spoilers=>1), 'Show minor spoilers';
- a_ mkclass(standout =>$view->{spoilers} == 2), href => '?view='.viewset(spoilers=>2), 'Spoil me!';
- b_ class => 'grayedout', ' | ';
- a_ mkclass(checked => $view->{traits_sexual}), href => '?view='.viewset(traits_sexual=>!$view->{traits_sexual}), 'Show sexual traits';
+ if($max_spoil) {
+ a_ mkclass(checked => $view->{spoilers} == 0), href => '?view='.viewset(spoilers=>0), 'Hide spoilers';
+ a_ mkclass(checked => $view->{spoilers} == 1), href => '?view='.viewset(spoilers=>1), 'Show minor spoilers';
+ a_ mkclass(standout =>$view->{spoilers} == 2), href => '?view='.viewset(spoilers=>2), 'Spoil me!' if $max_spoil == 2;
+ }
+ b_ class => 'grayedout', ' | ' if $has_sex && $max_spoil;
+ a_ mkclass(checked => $view->{traits_sexual}), href => '?view='.viewset(traits_sexual=>!$view->{traits_sexual}), 'Show sexual traits' if $has_sex;
};
h1_ sub { txt_ $c->{name}; debug_ $c };
h2_ class => 'alttitle', $c->{original} if length $c->{original};
chartable_ $c;
};
- my $inst = $c->{main} && $c->{main_spoil} > $view->{spoilers} ? []
- : fetch_chars undef, sql
- # If this entry doesn't have a 'main', look for other entries with a 'main' referencing this entry
- !$c->{main} ? ('main =', \$c->{id}, 'AND main_spoil <=', \$view->{spoilers}) :
- # Otherwise, look for other entries with the same 'main', and also fetch the 'main' entry itself
- ('(id <>', \$c->{id}, 'AND main =', \$c->{main}, 'AND main_spoil <=', \$view->{spoilers}, ') OR id =', \$c->{main});
-
div_ class => 'mainbox', sub {
h1_ 'Other instances';
chartable_ $_, 1, $_ != $inst->[0] for @$inst;