summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-11 16:31:57 +0200
committerYorhel <git@yorhel.nl>2019-09-11 16:31:57 +0200
commit82ade4157f86891c3d90336155a942976e1df934 (patch)
treefbe5b8dfa0b88a0d59fb67af36a56ad46334fb47 /lib
parent500d19bd7c5c2c3e6a73b8b5ae0aa5ab39182df7 (diff)
VNDB::Types: Convert vn_relations and prod_relations
Diffstat (limited to 'lib')
-rw-r--r--lib/Multi/RG.pm12
-rw-r--r--lib/VN3/ElmGen.pm4
-rw-r--r--lib/VN3/Producer/Page.pm2
-rw-r--r--lib/VN3/Types.pm45
-rw-r--r--lib/VN3/VN/Page.pm2
-rw-r--r--lib/VN3/Validation.pm4
-rw-r--r--lib/VNDB/Handler/Producers.pm12
-rw-r--r--lib/VNDB/Handler/VNEdit.pm6
-rw-r--r--lib/VNDB/Handler/VNPage.pm4
-rw-r--r--lib/VNDB/Types.pm28
10 files changed, 60 insertions, 59 deletions
diff --git a/lib/Multi/RG.pm b/lib/Multi/RG.pm
index d3637c4e..9a158f21 100644
--- a/lib/Multi/RG.pm
+++ b/lib/Multi/RG.pm
@@ -92,7 +92,7 @@ sub getrel { # id, res, time
my($xid, $xrel, $xoff) = @$_;
$xoff = 0 if $xoff && $xoff =~ /^f/;
- $C{rels}{$id.'-'.$xid} = [ $VNDB::S{ $C{type} eq 'v' ? 'vn_relations' : 'prod_relations' }{$xrel}[0], $xoff ] if $id < $xid;
+ $C{rels}{$id.'-'.$xid} = [ ($C{type} eq 'v' ? \%VN_RELATION : \%PRODUCER_RELATION)->{$xrel}{reverse}, $xoff ] if $id < $xid;
$C{rels}{$xid.'-'.$id} = [ $xrel, $xoff ] if $id > $xid;
# New node? Get its relations too.
@@ -198,10 +198,10 @@ sub gv_vnrels {
# [older game] -> [newer game]
if($_->[5] > $_->[4]) {
($_->[0], $_->[1]) = ($_->[1], $_->[0]);
- $_->[2] = $VNDB::S{vn_relations}{$_->[2]}[0];
+ $_->[2] = $VN_RELATION{$_->[2]}{reverse};
}
- my $rel = $VNDB::S{vn_relations}{$_->[2]}[1];
- my $rev = $VNDB::S{vn_relations}{ $VNDB::S{vn_relations}{$_->[2]}[0] }[1];
+ my $rel = $VN_RELATION{$_->[2]}{txt};
+ my $rev = $VN_RELATION{ $VN_RELATION{$_->[2]}{reverse} }{txt};
my $style = $_->[3] ? '' : ', style="dotted"';
my $label = $rev ne $rel
? qq|headlabel = "$rel" taillabel = "${rev}" $style|
@@ -245,8 +245,8 @@ sub gv_prodrels {
my $p1 = $prods->{$1};
my $p2 = $prods->{$2};
- my $rel = $VNDB::S{prod_relations}{$rels->{$_}[0]}[1];
- my $rev = $VNDB::S{prod_relations}{ $VNDB::S{prod_relations}{$rels->{$_}[0]}[0] }[1];
+ my $rel = $PRODUCER_RELATION{$rels->{$_}[0]}{txt};
+ my $rev = $PRODUCER_RELATION{ $PRODUCER_RELATION{$rels->{$_}[0]}{reverse} }{txt};
my $label = $rev ne $rel
? qq|headlabel = "$rev", taillabel = "$rel"|
: qq|label = "$rel"|;
diff --git a/lib/VN3/ElmGen.pm b/lib/VN3/ElmGen.pm
index e28e2ff6..accef5e8 100644
--- a/lib/VN3/ElmGen.pm
+++ b/lib/VN3/ElmGen.pm
@@ -167,8 +167,8 @@ my $perms = VN3::Auth::listPerms();
def urlStatic => String => string tuwf->conf->{url_static};
def userPerms => 'List (Int, String)' => list map tuple($perms->{$_}, string $_), sort keys %$perms;
def vnLengths => 'List (Int, String)' => list map tuple($_, string vn_length_display $_), 0..$#VN_LENGTHS;
-def vnRelations => 'List (String, String)' => list map tuple(string $_, string vn_relation_display $_), vn_relations;
-def producerRelations => 'List (String, String)' => list map tuple(string $_, string producer_relation_display $_), keys %PRODUCER_RELATIONS;
+def vnRelations => 'List (String, String)' => list map tuple(string $_, string vn_relation_display $_), keys %VN_RELATION;
+def producerRelations => 'List (String, String)' => list map tuple(string $_, string producer_relation_display $_), keys %PRODUCER_RELATION;
def creditType => 'List (String, String)' => list map tuple(string $_, string $CREDIT_TYPE{$_}), keys %CREDIT_TYPE;
def languages => 'List (String, String)' => list map tuple(string $_, string $LANGUAGE{$_}), sort { $LANGUAGE{$a} cmp $LANGUAGE{$b} } keys %LANGUAGE;
def platforms => 'List (String, String)' => list map tuple(string $_, string $PLATFORM{$_}), keys %PLATFORM;
diff --git a/lib/VN3/Producer/Page.pm b/lib/VN3/Producer/Page.pm
index 0e891fa8..ba52c8b1 100644
--- a/lib/VN3/Producer/Page.pm
+++ b/lib/VN3/Producer/Page.pm
@@ -68,7 +68,7 @@ sub DetailsTable {
}, @{$rel{$r}}
}
}
- } grep $rel{$_}, keys %PRODUCER_RELATIONS)
+ } grep $rel{$_}, keys %PRODUCER_RELATION)
);
Div class => 'row', sub {
diff --git a/lib/VN3/Types.pm b/lib/VN3/Types.pm
index d049f49b..e458c085 100644
--- a/lib/VN3/Types.pm
+++ b/lib/VN3/Types.pm
@@ -23,8 +23,8 @@ our @EXPORT = qw/
%CHAR_ROLES char_roles char_role_display
vote_display vote_string
date_display
- %VN_RELATIONS vn_relations vn_relation_reverse vn_relation_display
- %PRODUCER_RELATIONS producer_relation_reverse producer_relation_display
+ vn_relation_reverse vn_relation_display
+ producer_relation_reverse producer_relation_display
spoil_display
release_types
@MINAGE minage_display minage_display_full
@@ -179,40 +179,13 @@ sub date_display {
-our %VN_RELATIONS;
-tie %VN_RELATIONS, 'Tie::IxHash',
-# id reverse name
- seq => [ 'preq', 'Sequel' ],
- preq => [ 'seq', 'Prequel' ],
- set => [ 'set', 'Same setting' ],
- alt => [ 'alt', 'Alternative version' ],
- char => [ 'char', 'Shares characters' ],
- side => [ 'par', 'Side story' ],
- par => [ 'side', 'Parent story' ],
- ser => [ 'ser', 'Same series' ],
- fan => [ 'orig', 'Fandisc' ],
- orig => [ 'fan', 'Original game' ];
-
-sub vn_relations { keys %VN_RELATIONS }
-sub vn_relation_reverse { $VN_RELATIONS{$_[0]}[0] }
-sub vn_relation_display { $VN_RELATIONS{$_[0]}[1] }
-
-
-
-our %PRODUCER_RELATIONS;
-tie %PRODUCER_RELATIONS, 'Tie::IxHash',
-# id reverse name
- old => [ 'new', 'Formerly' ],
- new => [ 'old', 'Succeeded by' ],
- spa => [ 'ori', 'Spawned' ],
- ori => [ 'spa', 'Originated from' ],
- sub => [ 'par', 'Subsidiary' ],
- par => [ 'sub', 'Parent producer' ],
- imp => [ 'ipa', 'Imprint' ],
- ipa => [ 'imp', 'Parent brand' ];
-
-sub producer_relation_reverse { $PRODUCER_RELATIONS{$_[0]}[0] }
-sub producer_relation_display { $PRODUCER_RELATIONS{$_[0]}[1] }
+sub vn_relation_reverse { $VN_RELATION{$_[0]}{reverse} }
+sub vn_relation_display { $VN_RELATION{$_[0]}{txt} }
+
+
+
+sub producer_relation_reverse { $PRODUCER_RELATION{$_[0]}{reverse} }
+sub producer_relation_display { $PRODUCER_RELATION{$_[0]}{txt} }
diff --git a/lib/VN3/VN/Page.pm b/lib/VN3/VN/Page.pm
index 0624fb66..d71f1ac1 100644
--- a/lib/VN3/VN/Page.pm
+++ b/lib/VN3/VN/Page.pm
@@ -85,7 +85,7 @@ sub SidebarRel {
Dt 'Relations';
Dd sub {
Dl sub {
- for my $type (vn_relations) {
+ for my $type (keys %VN_RELATION) {
my @rel = grep $_->{relation} eq $type, @{$vn->{relations}};
next if !@rel;
Dt vn_relation_display $type;
diff --git a/lib/VN3/Validation.pm b/lib/VN3/Validation.pm
index 405452ff..1c9a1807 100644
--- a/lib/VN3/Validation.pm
+++ b/lib/VN3/Validation.pm
@@ -24,8 +24,8 @@ TUWF::set custom_validations => {
password => { length => [ 4, 500 ] },
editsum => { required => 1, length => [ 2, 5000 ] },
vn_length => { required => 0, default => 0, uint => 1, range => [ 0, $#VN_LENGTHS ] },
- vn_relation => { enum => \%VN_RELATIONS },
- producer_relation => { enum => \%PRODUCER_RELATIONS },
+ vn_relation => { enum => \%VN_RELATION },
+ producer_relation => { enum => \%PRODUCER_RELATION },
staff_role => { enum => \%CREDIT_TYPE },
char_role => { enum => \%CHAR_ROLES },
language => { enum => \%LANGUAGE },
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index db3f3a3d..75b2a6cd 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -76,7 +76,7 @@ sub page {
[ desc => 'Description', diff => qr/[ ,\n\.]/ ],
[ relations => 'Relations', join => '<br />', split => sub {
my @r = map sprintf('%s: <a href="/p%d" title="%s">%s</a>',
- $self->{prod_relations}{$_->{relation}}[1], $_->{id}, xml_escape($_->{original}||$_->{name}), xml_escape shorten $_->{name}, 40
+ $PRODUCER_RELATION{$_->{relation}}{txt}, $_->{id}, xml_escape($_->{original}||$_->{name}), xml_escape shorten $_->{name}, 40
), sort { $a->{id} <=> $b->{id} } @{$_[0]};
return @r ? @r : ('[empty]');
}],
@@ -109,9 +109,9 @@ sub page {
for (sort { $a->{name} cmp $b->{name} } @{$p->{relations}});
p class => 'center';
br;
- for my $r (keys %{$self->{prod_relations}}) {
+ for my $r (keys %PRODUCER_RELATION) {
next if !$rel{$r};
- txt $self->{prod_relations}{$r}[1].': ';
+ txt $PRODUCER_RELATION{$r}{txt}.': ';
for (@{$rel{$r}}) {
a href => "/p$_->{id}", title => $_->{original}||$_->{name}, shorten $_->{name}, 40;
txt ', ' if $_ ne $rel{$r}[$#{$rel{$r}}];
@@ -366,8 +366,8 @@ sub edit {
end;
td class => 'tc_rel';
Select;
- option value => $_, $self->{prod_relations}{$_}[1]
- for (keys %{$self->{prod_relations}});
+ option value => $_, $PRODUCER_RELATION{$_}{txt}
+ for (keys %PRODUCER_RELATION);
end;
end;
td class => 'tc_add';
@@ -389,7 +389,7 @@ sub _updreverse {
if(exists $$old{$_} and !exists $$new{$_}) {
$upd{$_} = undef;
} elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_} ne $$new{$_})) {
- $upd{$_} = $self->{prod_relations}{$$new{$_}}[0];
+ $upd{$_} = $PRODUCER_RELATION{$$new{$_}}{reverse};
}
}
return if !keys %upd;
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index dd19aa6a..bbf1f545 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -392,8 +392,8 @@ sub _form {
input type => 'checkbox', id => 'official', checked => 'checked';
label for => 'official', 'official';
Select;
- option value => $_, $self->{vn_relations}{$_}[1]
- for (keys %{$self->{vn_relations}});
+ option value => $_, $VN_RELATION{$_}{txt}
+ for (keys %VN_RELATION);
end;
txt ' of';
end;
@@ -452,7 +452,7 @@ sub _updreverse {
if(exists $$old{$_} and !exists $$new{$_}) {
$upd{$_} = undef;
} elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_}[0] ne $$new{$_}[0] || !$$old{$_}[1] != !$$new{$_}[1])) {
- $upd{$_} = [ $self->{vn_relations}{ $$new{$_}[0] }[0], $$new{$_}[1] ];
+ $upd{$_} = [ $VN_RELATION{ $$new{$_}[0] }{reverse}, $$new{$_}[1] ];
}
}
return if !keys %upd;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 347d65bc..b130ddc9 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -568,7 +568,7 @@ sub _revision {
}],
[ relations => 'Relations', join => '<br />', split => sub {
my @r = map sprintf('[%s] %s: <a href="/v%d" title="%s">%s</a>',
- $_->{official} ? 'official' : 'unofficial', $self->{vn_relations}{$_->{relation}}[1],
+ $_->{official} ? 'official' : 'unofficial', $VN_RELATION{$_->{relation}}{txt},
$_->{id}, xml_escape($_->{original}||$_->{title}), xml_escape shorten $_->{title}, 40
), sort { $a->{id} <=> $b->{id} } @{$_[0]};
return @r ? @r : ('[empty]');
@@ -652,7 +652,7 @@ sub _relations {
td class => 'relations';
dl;
for(sort keys %rel) {
- dt $self->{vn_relations}{$_}[1];
+ dt $VN_RELATION{$_}{txt};
dd;
for (@{$rel{$_}}) {
b class => 'grayedout', '[unofficial] ' if !$_->{official};
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 70204989..2d87b88a 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -104,6 +104,34 @@ hash PLATFORM =>
+# SQL: ENUM vn_relation
+hash VN_RELATION =>
+ seq => { reverse => 'preq', txt => 'Sequel' },
+ preq => { reverse => 'seq', txt => 'Prequel' },
+ set => { reverse => 'set', txt => 'Same setting' },
+ alt => { reverse => 'alt', txt => 'Alternative version' },
+ char => { reverse => 'char', txt => 'Shares characters' },
+ side => { reverse => 'par', txt => 'Side story' },
+ par => { reverse => 'side', txt => 'Parent story' },
+ ser => { reverse => 'ser', txt => 'Same series' },
+ fan => { reverse => 'orig', txt => 'Fandisc' },
+ orig => { reverse => 'fan', txt => 'Original game' };
+
+
+
+# SQL: ENUM producer_relation
+hash PRODUCER_RELATION =>
+ old => { reverse => 'new', txt => 'Formerly' },
+ new => { reverse => 'old', txt => 'Succeeded by' },
+ spa => { reverse => 'ori', txt => 'Spawned' },
+ ori => { reverse => 'spa', txt => 'Originated from' },
+ sub => { reverse => 'par', txt => 'Subsidiary' },
+ par => { reverse => 'sub', txt => 'Parent producer' },
+ imp => { reverse => 'ipa', txt => 'Imprint' },
+ ipa => { reverse => 'imp', txt => 'Parent brand ' };
+
+
+
# SQL: ENUM credit_type
hash CREDIT_TYPE =>
scenario => 'Scenario',