| 1 | package Games::Rezrov::ZIO_test; | ||||||||||||||
| 2 | # z-machine i/o for test model - meant for capturing output as part of a test | ||||||||||||||
| 3 | # - contributed by Neil Bowers, Aug 2004 | ||||||||||||||
| 4 | # - modified by Michael Edmonson: | ||||||||||||||
| 5 | # - stripped down even further. | ||||||||||||||
| 6 | # - avoid using ANY local system calls or external modules (GetKey/GetSize). | ||||||||||||||
| 7 | # This means single-key input will not work, but also "make test" | ||||||||||||||
| 8 | # might stop crashing in unusual configurations! :P | ||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | ▶ | use Games::Rezrov::ZIO_Generic; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | @Games::Rezrov::ZIO_test::ISA = qw(Games::Rezrov::ZIO_Generic); | |||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | my $rows = 25; | |||||||||||||
| 16 | 1 | my $columns = 80; | |||||||||||||
| 17 | 1 | my $abs_x = 0; | |||||||||||||
| 18 | 1 | my $abs_y = 0; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 1 | $|=1; | |||||||||||||
| 21 | |||||||||||||||
| 22 | 1 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||
| 23 | 1 | my ($type, %options) = @_; | |||||||||||||
| 24 | 1 | my $self = new Games::Rezrov::ZIO_Generic(%options); | |||||||||||||
| 25 | 1 | bless $self, $type; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 1 | ▶ | $columns = $options{columns} if $options{columns}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 1 | $self->zio_options(\%options); | |||||||||||||
| 29 | 1 | ($columns, $rows) = get_size(); | |||||||||||||
| 30 | |||||||||||||||
| 31 | 1 | return $self; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 1 | ▶ | sub get_size { | ||||||||||||
|
Subroutine
get_size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 35 | 1 | return ($columns, $rows); | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | sub get_key { | ||||||||||||
|
Subroutine
get_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 39 | # single-key input disabled! | ||||||||||||||
| 40 | 0 | return ""; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 24 | ▶ | sub write_string { | ||||||||||||
|
Subroutine
write_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 44 | 24 | my ($self, $string, $x, $y) = @_; | |||||||||||||
| 45 | # $self->absolute_move($x, $y) if defined($x) and defined($y); | ||||||||||||||
| 46 | 24 | print $string; | |||||||||||||
| 47 | 24 | $abs_x += length($string); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | ▶ | sub clear_to_eol { | ||||||||||||
|
Subroutine
clear_to_eol: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 51 | # do nothing | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | sub update { | ||||||||||||
|
Subroutine
update: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 3 | ▶ | sub can_split { | ||||||||||||
|
Subroutine
can_split: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 58 | # true or false: can this zio split the screen? | ||||||||||||||
| 59 | 3 | return 0; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | ▶ | sub set_version { | ||||||||||||
|
Subroutine
set_version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 63 | 1 | my ($self, $status_needed, $callback) = @_; | |||||||||||||
| 64 | 1 | Games::Rezrov::StoryFile::rows($rows); | |||||||||||||
| 65 | 1 | Games::Rezrov::StoryFile::columns($columns); | |||||||||||||
| 66 | 1 | return 0; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 4 | ▶ | sub absolute_move { | ||||||||||||
|
Subroutine
absolute_move: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 70 | 4 | ($abs_x, $abs_y) = @_[1,2]; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 28 | ▶ | sub newline { | ||||||||||||
|
Subroutine
newline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 74 | 28 | print "\n"; | |||||||||||||
| 75 | 28 | $abs_x = 0; | |||||||||||||
| 76 | # Games::Rezrov::StoryFile::register_newline(); | ||||||||||||||
| 77 | # never register newlines to the interpreter, | ||||||||||||||
| 78 | # so [MORE] prompt will never appear. | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | ▶ | sub write_zchar { | ||||||||||||
|
Subroutine
write_zchar: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 82 | 0 | ▶ | if ($_[0]->current_window() == Games::Rezrov::ZConst::LOWER_WIN) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 0 | print chr($_[1]); | |||||||||||||
| 84 | 0 | $abs_x++; | |||||||||||||
| 85 | } else { | ||||||||||||||
| 86 | # upper window character, ignore | ||||||||||||||
| 87 | # printf STDERR "ignoring char: %s\n", chr($_[1]); | ||||||||||||||
| 88 | } | ||||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | ▶ | sub get_input { | ||||||||||||
|
Subroutine
get_input: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 92 | 0 | my ($self, $max, $single_char, %options) = @_; | |||||||||||||
| 93 | 0 | ▶ | if ($single_char) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 0 | return get_key(); | |||||||||||||
| 95 | } else { | ||||||||||||||
| 96 | 0 | my $line; | |||||||||||||
| 97 | 0 | ▶ | if ($self->listening) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 98 | # speech recognition; disable for this interface? | ||||||||||||||
| 99 | 0 | $line = $self->recognize_line(); | |||||||||||||
| 100 | 0 | print "$line\n"; | |||||||||||||
| 101 | } elsif ($self->using_term_readline()) { | ||||||||||||||
| 102 | # Term::ReadLine enabled | ||||||||||||||
| 103 | 0 | $line = $self->readline($options{"-preloaded"}); | |||||||||||||
| 104 | } else { | ||||||||||||||
| 105 | 0 | $line = <STDIN>; | |||||||||||||
| 106 | # also doesn't work with v5+ preloaded input | ||||||||||||||
| 107 | } | ||||||||||||||
| 108 | 0 | ▶ | unless (defined $line) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | 0 | $line = ""; | |||||||||||||
| 110 | 0 | print "\n"; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | 0 | chomp $line; | |||||||||||||
| 113 | 0 | return $line; | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | } | ||||||||||||||
| 116 | |||||||||||||||
| 117 | 22 | ▶ | sub get_position { | ||||||||||||
|
Subroutine
get_position: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 118 | 22 | my ($self, $sub) = @_; | |||||||||||||
| 119 | 22 | ▶ | if ($sub) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | 3 | ▶ | return sub { }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||
| 121 | } else { | ||||||||||||||
| 122 | 19 | return ($abs_x, $abs_y); | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 2 | ▶ | sub clear_screen { | ||||||||||||
|
Subroutine
clear_screen: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 127 | # do nothing | ||||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | 4 | ▶ | sub set_window { | ||||||||||||
|
Subroutine
set_window: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 131 | 4 | my ($self, $window) = @_; | |||||||||||||
| 132 | 4 | $self->SUPER::set_window($window); | |||||||||||||
| 133 | } | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | ▶ | sub erase_chars { | ||||||||||||
|
Subroutine
erase_chars: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 136 | # do nothing | ||||||||||||||
| 137 | } | ||||||||||||||
| 138 | |||||||||||||||
| 139 | 1 | 1; | |||||||||||||