| 1 | package Games::Rezrov::ZIO_Generic; | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # shared/skeleton z-machine i/o, options, and speech | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # FIX ME: provide abstract stub methods which die() w/message | ||||||||||||||||||||||||||||
| 6 | # requiring implementation | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Games::Rezrov::ZIO_Tools; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Games::Rezrov::ZConst; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Games::Rezrov::Speech; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Games::Rezrov::MethodMaker qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | current_window | ||||||||||||||||||||||||||||
| 16 | zio_options | ||||||||||||||||||||||||||||
| 17 | using_term_readline | ||||||||||||||||||||||||||||
| 18 | 1 | ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | @Games::Rezrov::ZIO_Generic::ISA = qw(Games::Rezrov::Speech); | |||||||||||||||||||||||||||
| 21 | # additional ZIO methods | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | my $buffer = ""; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 1 | my ($type, %options) = @_; | |||||||||||||||||||||||||||
| 27 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 28 | 1 | bless $self, $type; | |||||||||||||||||||||||||||
| 29 | 1 | $self->zio_options(\%options); | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | $self->init_speech_synthesis() if $options{"speak"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $self->init_speech_recognition() if $options{"listen"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | return $self; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub can_split { | ||||||||||||||||||||||||||
|
Subroutine
can_split: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | # true or false: can this zio split the screen? | ||||||||||||||||||||||||||||
| 37 | 0 | return 1; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub groks_font_3 { | ||||||||||||||||||||||||||
|
Subroutine
groks_font_3: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | # true or false: can this zio handle graphical "font 3" z-characters? | ||||||||||||||||||||||||||||
| 42 | 1 | return 0; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 19 | ▶ | sub fixed_font_default { | ||||||||||||||||||||||||||
|
Subroutine
fixed_font_default: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | # true or false: does this zio use a fixed-width font? | ||||||||||||||||||||||||||||
| 47 | 19 | return 1; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub can_change_title { | ||||||||||||||||||||||||||
|
Subroutine
can_change_title: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | # true or false: can this zio change title? | ||||||||||||||||||||||||||||
| 52 | 0 | return set_xterm_title(); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub can_use_color { | ||||||||||||||||||||||||||
|
Subroutine
can_use_color: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 2 | return 0; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | sub split_window {} | ||||||||||||||||||||||||||
|
Subroutine
split_window: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 7 | ▶ | sub set_text_style {} | ||||||||||||||||||||||||||
|
Subroutine
set_text_style: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub clear_screen {} | ||||||||||||||||||||||||||
|
Subroutine
clear_screen: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub color_change_notify {} | ||||||||||||||||||||||||||
|
Subroutine
color_change_notify: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub set_game_title { | ||||||||||||||||||||||||||
|
Subroutine
set_game_title: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | set_xterm_title($_[1]); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub manual_status_line { | ||||||||||||||||||||||||||
|
Subroutine
manual_status_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | # true or false: does this zio want to draw the status line itself? | ||||||||||||||||||||||||||||
| 70 | 0 | return 0; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 29 | ▶ | sub get_buffer { | ||||||||||||||||||||||||||
|
Subroutine
get_buffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | # get buffered text; fix me: return a ref? | ||||||||||||||||||||||||||||
| 75 | # print STDERR "get_buf: $buffer\n"; | ||||||||||||||||||||||||||||
| 76 | 29 | return $buffer; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 29 | ▶ | sub reset_buffer { | ||||||||||||||||||||||||||
|
Subroutine
reset_buffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 29 | $buffer = ""; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 35 | ▶ | sub buffer_zchunk { | ||||||||||||||||||||||||||
|
Subroutine
buffer_zchunk: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | # receive a z-code string; newlines may be present. | ||||||||||||||||||||||||||||
| 85 | 35 | my $nl = chr(Games::Rezrov::ZConst::Z_NEWLINE); | |||||||||||||||||||||||||||
| 86 | 35 | foreach (unpack "a" x length ${$_[1]}, ${$_[1]}) { | |||||||||||||||||||||||||||
| 87 | # this unpack() seems a little faster than a split(). | ||||||||||||||||||||||||||||
| 88 | # Any better way ??? | ||||||||||||||||||||||||||||
| 89 | 812 | ▶ | if ($_ eq $nl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 6 | Games::Rezrov::StoryFile::flush(); | |||||||||||||||||||||||||||
| 91 | 6 | $_[0]->newline(); | |||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 806 | $buffer .= $_; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 12 | ▶ | sub buffer_zchar { | ||||||||||||||||||||||||||
|
Subroutine
buffer_zchar: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 12 | $buffer .= chr($_[1]); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub set_font { | ||||||||||||||||||||||||||
|
Subroutine
set_font: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | # print STDERR "set_font $_[1]\n"; | ||||||||||||||||||||||||||||
| 104 | 0 | return 0; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub play_sound_effect { | ||||||||||||||||||||||||||
|
Subroutine
play_sound_effect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $effect) = @_; | |||||||||||||||||||||||||||
| 109 | # flash(); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 4 | ▶ | sub set_window { | ||||||||||||||||||||||||||
|
Subroutine
set_window: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 4 | $_[0]->current_window($_[1]); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | sub cleanup { | ||||||||||||||||||||||||||
|
Subroutine
cleanup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | # in case of a crash, make sure we exit politely | ||||||||||||||||||||||||||||
| 121 | 0 | $_[0]->cleanup(); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub fatal_error { | ||||||||||||||||||||||||||
|
Subroutine
fatal_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||
| 126 | 0 | $self->write_string("Fatal error: " . $msg); | |||||||||||||||||||||||||||
| 127 | 0 | $self->newline(); | |||||||||||||||||||||||||||
| 128 | 0 | $self->get_input(1,1); | |||||||||||||||||||||||||||
| 129 | 0 | $self->cleanup(); | |||||||||||||||||||||||||||
| 130 | 0 | exit 1; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub set_background_color { | ||||||||||||||||||||||||||
|
Subroutine
set_background_color: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 134 | # set the background to the current background color. | ||||||||||||||||||||||||||||
| 135 | # That's the *whole* background, not just for the next characters | ||||||||||||||||||||||||||||
| 136 | # to print (some games switch background colors before clearing | ||||||||||||||||||||||||||||
| 137 | # the screen, which should reset the entire background to that | ||||||||||||||||||||||||||||
| 138 | # color); eg "photopia.z5". | ||||||||||||||||||||||||||||
| 139 | # | ||||||||||||||||||||||||||||
| 140 | # "That's the *whole* bass..." | ||||||||||||||||||||||||||||
| 141 | 0 | 1; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub readline_init { | ||||||||||||||||||||||||||
|
Subroutine
readline_init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | # | ||||||||||||||||||||||||||||
| 146 | # try to initialize Term::Readline if desired and available | ||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||
| 148 | # FIX ME: rather than ->{readline}, ZOptions.pm? | ||||||||||||||||||||||||||||
| 149 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($self->zio_options->{readline} and find_module('Term::ReadLine')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->zio_options->{"readline"} and find_module("Term::ReadLine")
MC/DC0%0/2
$self->zio_options->{"readline"} and find_module("Term::ReadLine")
$self->zio_options->{"readline"}
find_module("Term::ReadLine")
Truth table0%0/3
A and B
A= $self->zio_options->{"readline"}B= find_module("Term::ReadLine")
| |||||||||||||||||||||||||||||
| 151 | 0 | require Term::ReadLine; | |||||||||||||||||||||||||||
| 152 | 0 | my $tr = new Term::ReadLine "what?", \*main::STDIN, \*main::STDOUT; | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | unless (ref $tr eq "Term::ReadLine::Stub") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | $tr->ornaments(0); | |||||||||||||||||||||||||||
| 155 | 0 | $self->using_term_readline($tr); | |||||||||||||||||||||||||||
| 156 | # only set if available and active | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub readline { | ||||||||||||||||||||||||||
|
Subroutine
readline: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | # read a line via Term::ReadLine | ||||||||||||||||||||||||||||
| 163 | # readline insists on resetting the line so we need to give it | ||||||||||||||||||||||||||||
| 164 | # everything up to the cursor position. | ||||||||||||||||||||||||||||
| 165 | 0 | my ($self, $preloaded) = @_; | |||||||||||||||||||||||||||
| 166 | # FIX ME: preloaded input does NOT work with Term::ReadLine! | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | my $line; | |||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 171 | # disable warnings for readline call. | ||||||||||||||||||||||||||||
| 172 | # Term::ReadLine::Perl spews undef messages when passed an | ||||||||||||||||||||||||||||
| 173 | # undef prompt (e.g. when "Plundered Hearts" starts) | ||||||||||||||||||||||||||||
| 174 | 0 | my $rl_ref = $_[0]->using_term_readline(); | |||||||||||||||||||||||||||
| 175 | 0 | my $prompt = Games::Rezrov::StoryFile::prompt_buffer(); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($prompt and $rl_ref->ReadLine eq "Term::ReadLine::Gnu") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prompt and $rl_ref->ReadLine eq "Term::ReadLine::Gnu"
MC/DC0%0/2
$prompt and $rl_ref->ReadLine eq "Term::ReadLine::Gnu"
$prompt
$rl_ref->ReadLine eq "Term::ReadLine::Gnu"
Truth table0%0/3
A and B
A= $promptB= $rl_ref->ReadLine eq "Term::ReadLine::Gnu"
| |||||||||||||||||||||||||||||
| 178 | # HACK: | ||||||||||||||||||||||||||||
| 179 | # Term::ReadLine::Perl seems to erase line before prompt, | ||||||||||||||||||||||||||||
| 180 | # but Term::ReadLine::Gnu doesn't. Since the prompt has already | ||||||||||||||||||||||||||||
| 181 | # been displayed before ReadLine is called, when using Gnu | ||||||||||||||||||||||||||||
| 182 | # version we need to erase it so we don't wind up with two. | ||||||||||||||||||||||||||||
| 183 | 0 | $self->write_string(pack('c', Games::Rezrov::ZConst::ASCII_BS) x | |||||||||||||||||||||||||||
| 184 | length($prompt)); | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | $line = $rl_ref->readline($prompt); | |||||||||||||||||||||||||||
| 188 | # this doesn't work with v5+ preloaded input | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 0 | return $line; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||||||||||