From 0f9dde3810a3b86e0769e6013a19ccf0faeba0a3 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 25 Dec 2020 17:27:57 +0100 Subject: add wagon images for IC and ICE 1/2/4 IC2, ICE 3 and ICE T will follow soon. --- lib/DBInfoscreen.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib/DBInfoscreen.pm') diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index 54078ea..a0e027d 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -123,6 +123,13 @@ sub startup { } ); + $self->attr( + dbdb_wagon => sub { + return JSON->new->utf8->decode( + scalar read_file('share/dbdb_wagen.json') ); + } + ); + $self->helper( hafas => sub { my ($self) = @_; @@ -165,6 +172,32 @@ sub startup { } ); + $self->helper( + wagon_image => sub { + my ( $self, $train_type, $wagon_type, $uic ) = @_; + my $ret; + if ( $train_type =~ m{IC(?!E)} + and $wagon_type + =~ m{ ^ [AB] R? k? [ipv] m m? b? d? s? z f? $ }x ) + { + $ret = $wagon_type; + } + elsif ( not $uic ) { + return; + } + elsif ( $train_type =~ m{ICE [12]} and $wagon_type !~ m{^I} ) { + $ret = substr( $uic, 5, 4 ); + } + elsif ( $train_type =~ m{ICE 4} ) { + $ret = substr( $uic, 4, 5 ); + } + if ( $ret and $self->app->dbdb_wagon->{$ret} ) { + return $ret; + } + return; + } + ); + $self->helper( 'handle_no_results' => sub { my ( $self, $backend, $station, $errstr ) = @_; @@ -418,6 +451,7 @@ sub startup { $r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung'); $r->get('/wr/:train')->to('wagenreihung#zugbildung_db'); + $r->get('/w/:wagon')->to('wagenreihung#wagen'); $r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route'); $r->get('/map/:tripid/:lineno')->to('map#route'); -- cgit v1.2.3