From c160933061f58a0f64a6037c1db8b79fb725b495 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 26 Sep 2009 10:59:18 +0200 Subject: Converted VN relations to ENUM data type and made them translatable OK, these are actually two separate things: to make the relations translatable they didn't necessarily have to be stored as enum, and I could've also converted them to enum but not have it translatable. Nevertheless, it was easier to just do both at the same time. Also note how I used the string "$____vnrel_____$" as identifier in the relation graphs while I could have used something a lot shorter ("$$" would have been fine, for example). This is done so that graphviz can make some space for those relations - the long identifier gives a slightly more realistic representation of the actual length of the relation titles. --- ChangeLog | 2 ++ data/global.pl | 26 +++++++++++++------------- data/lang.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/Multi/RG.pm | 22 +++++++--------------- lib/VNDB/Handler/VNEdit.pm | 15 +++++++-------- lib/VNDB/Handler/VNPage.pm | 6 ++++-- static/f/forms.js | 7 ++++--- util/updates/update_2.8.sql | 18 ++++++++++++++++++ 8 files changed, 98 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cb2bbd3..7f965f2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ git - ? - Converted relation graphs to use inline SVG - Relation graphs now use the color scheme of selected skin + - VN relations are translatable in both the interface and the graphs + - Converted VN relations to an enum data type 2.7 - 2009-09-24 - Improved styling of the threeboxes layout diff --git a/data/global.pl b/data/global.pl index 4ab04d5b..aff1c6e1 100644 --- a/data/global.pl +++ b/data/global.pl @@ -46,19 +46,19 @@ our %S = (%S, 'TV Special', 'Music Video', ], - vn_relations => [ - # Name, Reverse-- - [ 'Sequel', 0 ], - [ 'Prequel', 1 ], - [ 'Same setting', 0 ], - [ 'Alternative version', 0 ], - [ 'Shares characters', 0 ], - [ 'Side story', 0 ], - [ 'Parent story', 1 ], - [ 'Same series', 0 ], - [ 'Fandisc', 0 ], - [ 'Original game', 1 ], - ], + vn_relations => { + # id => [ order, reverse ] + seq => [ 0, 'preq' ], + preq => [ 1, 'seq' ], + set => [ 2, 'set' ], + alt => [ 3, 'alt' ], + char => [ 4, 'char' ], + side => [ 5, 'par' ], + par => [ 6, 'side' ], + ser => [ 7, 'ser' ], + fan => [ 8, 'orig' ], + orig => [ 9, 'fan' ], + }, age_ratings => { -1 => [ 'Unknown' ], 0 => [ 'All ages' ,'CERO A' ], diff --git a/data/lang.txt b/data/lang.txt index e7ae5cfc..45722c42 100644 --- a/data/lang.txt +++ b/data/lang.txt @@ -291,6 +291,49 @@ en : Other ru : Другая +# VN relations + +:_vnrel_seq +en : Sequel +ru*: + +:_vnrel_preq +en : Prequel +ru*: + +:_vnrel_set +en : Same setting +ru*: + +:_vnrel_alt +en : Alternative version +ru*: + +:_vnrel_char +en : Shares characters +ru*: + +:_vnrel_side +en : Side story +ru*: + +:_vnrel_par +en : Parent story +ru*: + +:_vnrel_ser +en : Same series +ru*: + +:_vnrel_fan +en : Fandisc +ru*: + +:_vnrel_orig +en : Original game +ru*: + + # producer types :_ptype_co diff --git a/lib/Multi/RG.pm b/lib/Multi/RG.pm index 4ae0516e..be12fd17 100644 --- a/lib/Multi/RG.pm +++ b/lib/Multi/RG.pm @@ -78,8 +78,8 @@ sub getrel { # num, res, vid $_[HEAP]{nodes}{$id} = 1; for($_[ARG0] > 0 ? @{$_[ARG1]} : ()) { - $_[HEAP]{rels}{$id.'-'.$_->{id}} = reverserel($_->{relation}) if $id < $_->{id}; - $_[HEAP]{rels}{$_->{id}.'-'.$id} = $_->{relation} if $id > $_->{id}; + $_[HEAP]{rels}{$id.'-'.$_->{id}} = $VNDB::S{vn_relations}{$_->{relation}}[1] if $id < $_->{id}; + $_[HEAP]{rels}{$_->{id}.'-'.$id} = $_->{relation} if $id > $_->{id}; if(!exists $_[HEAP]{nodes}{$_->{id}}) { $_[HEAP]{nodes}{$_->{id}} = 0; @@ -147,14 +147,13 @@ sub builddot { # num, res # [older game] -> [newer game] if($_->[4] > $_->[3]) { ($_->[0], $_->[1]) = ($_->[1], $_->[0]); - $_->[2] = reverserel($_->[2]); + $_->[2] = $VNDB::S{vn_relations}{$_->[2]}[1]; } + my $rev = $VNDB::S{vn_relations}{$_->[2]}[1]; my $label = - $VNDB::S{vn_relations}[$_->[2]][1] - ? qq|headlabel = "$VNDB::S{vn_relations}[$_->[2]][0]", taillabel = "$VNDB::S{vn_relations}[$_->[2]-1][0]"| : - $VNDB::S{vn_relations}[$_->[2]+1][1] - ? qq|headlabel = "$VNDB::S{vn_relations}[$_->[2]][0]", taillabel = "$VNDB::S{vn_relations}[$_->[2]+1][0]"| - : qq|label = " $VNDB::S{vn_relations}[$_->[2]][0]"|; + $rev ne $_->[2] + ? qq|headlabel = "\$____vnrel_$_->[2]____\$", taillabel = "\$____vnrel_${rev}____\$"| + : qq|label = "\$____vnrel_$_->[2]____\$"|; $gv .= qq|\tv$$_[1] -- v$$_[0] [ $label ]\n|; } @@ -258,12 +257,5 @@ sub proc_child { } - -# non-POE helper function -sub reverserel { # relation - return $VNDB::S{vn_relations}[$_[0]][1] ? $_[0]-1 : $VNDB::S{vn_relations}[$_[0]+1][1] ? $_[0]+1 : $_[0]; -} - - 1; diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index f09d6ddd..591e24a6 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -57,7 +57,7 @@ sub edit { if(!$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information my $anime = { map +($_=>1), grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} }; - my $relations = [ map { /^([0-9]+),([0-9]+),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3 ] : () } split /\|\|\|/, $frm->{relations} ]; + my $relations = [ map { /^([a-z]+),([0-9]+),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3 ] : () } split /\|\|\|/, $frm->{relations} ]; my $screenshots = [ map /^[0-9]+,[01],[0-9]+$/ ? [split /,/] : (), split / +/, $frm->{screenshots} ]; $frm->{anime} = join ' ', sort { $a <=> $b } keys %$anime; @@ -202,7 +202,8 @@ sub _form { td class => 'tc2'; txt ' is a '; Select; - option value => $_, $self->{vn_relations}[$_][0] for (0..$#{$self->{vn_relations}}); + option value => $_, mt "_vnrel_$_" + for (sort { $self->{vn_relations}{$a}[0] <=> $self->{vn_relations}{$b}[0] } keys %{$self->{vn_relations}}); end; txt ' of'; end; @@ -250,11 +251,9 @@ sub _updreverse { # compare %old and %new for (keys %$old, keys %$new) { if(exists $$old{$_} and !exists $$new{$_}) { - $upd{$_} = -1; - } elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_} != $$new{$_})) { - $upd{$_} = $$new{$_}; - if ($self->{vn_relations}[$upd{$_} ][1]) { $upd{$_}-- } - elsif($self->{vn_relations}[$upd{$_}+1][1]) { $upd{$_}++ } + $upd{$_} = undef; + } elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_} ne $$new{$_})) { + $upd{$_} = $self->{vn_relations}{$$new{$_}}[1]; } } @@ -264,7 +263,7 @@ sub _updreverse { for my $i (keys %upd) { my $r = $self->dbVNGet(id => $i, what => 'extended relations anime screenshots')->[0]; my @newrel = map $_->{id} != $vid ? [ $_->{relation}, $_->{id} ] : (), @{$r->{relations}}; - push @newrel, [ $upd{$i}, $vid ] if $upd{$i} != -1; + push @newrel, [ $upd{$i}, $vid ] if $upd{$i}; $self->dbVNEdit($i, relations => \@newrel, editsum => "Reverse relation update caused by revision v$vid.$rev", diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index f31b3eeb..a479bf64 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -58,6 +58,8 @@ sub rg { $self->htmlHeader(title => $title); *YAWF::XML::html = $sub; + $v->{svg} =~ s/\$___(_vnrel_[a-z]+)____\$/mt $1/eg; + $self->htmlMainTabs('v', $v, 'rg'); div class => 'mainbox'; h1 $title; @@ -228,7 +230,7 @@ sub _revision { }], [ relations => join => '
', split => sub { my @r = map sprintf('%s: %s', - $self->{vn_relations}[$_->{relation}][0], $_->{id}, xml_escape($_->{original}||$_->{title}), xml_escape shorten $_->{title}, 40 + mt("_vnrel_$_->{relation}"), $_->{id}, xml_escape($_->{original}||$_->{title}), xml_escape shorten $_->{title}, 40 ), sort { $a->{id} <=> $b->{id} } @{$_[0]}; return @r ? @r : (mt '_vndiff_none'); }], @@ -295,7 +297,7 @@ sub _relations { td class => 'relations'; dl; for(sort keys %rel) { - dt $self->{vn_relations}[$_][0]; + dt mt "_vnrel_$_"; dd; for (@{$rel{$_}}) { a href => "/v$_->{id}", title => $_->{original}||$_->{title}, shorten $_->{title}, 40; diff --git a/static/f/forms.js b/static/f/forms.js index ce9daab5..8c3e4e8b 100644 --- a/static/f/forms.js +++ b/static/f/forms.js @@ -199,7 +199,7 @@ function relLoad() { // fetch the relation types from the add new relation selectbox l = x('relation_new').getElementsByTagName('select')[0].options; for(i=0;i'+qq(relTypes[i])+''; t = document.createElement('td'); t.className = 'tc2'; @@ -289,10 +289,11 @@ function relSerialize() { var l = x('relation_tbl').getElementsByTagName('tr'); for(i=0;i