blib/lib/Games/Axmud/WizWin.pm untested

filter: Statementstmt 0.0% 0 / 1807 Branchbran 0.0% 0 / 616 Conditioncond 0.0% 0 / 366 MC/DCmcdc 0.0% 0 / 204 Subroutinesub 0.0% 0 / 94 Podpod 0.0% 0 / 88 totaltotal 0.0% 0 / 3175 CC 309 SCAR 58.9
CC
309
Cov
0%
analyseComponent
1482.0
saveChanges
992.0
analysisPage
812.0
CRAP 360.8
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::WizWin::XXX
16 # Handles all 'wiz' windows, inheriting from GA::Generic::WizWin
17  
18 { package Games::Axmud::WizWin::Setup;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(
27 Games::Axmud::Generic::WizWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
28 Games::Axmud
29 );
30  
31 ##################
32 # Constructors
33  
34 sub new {
35  
36 # Called by GA::Generic::Win->createFreeWin
37 # Creates a new instance of the Setup 'wiz' window, created by GA::Client->start when Axmud
38 # first runs, to let the user specify some initialisation settings
39 #
40 # Expected arguments
41 # $number - Unique number for this window object
42 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
43 # should be created
44 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
45 # 'free' window object. When this window opens/closes, the owner is
46 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
47 # functions
48 #
49 # Optional arguments
50 # $session - The GA::Session from which this function was called. 'undef' if the
51 # calling function didn't specify a session and $owner's ->session IV
52 # is also 'undef'
53 # $title - A string to use as the window title. If 'undef', a generic title is
54 # used
55 # $editObj - Ignored if set
56 # $tempFlag - Ignored if set
57 # %configHash - Hash containing any number of key-value pairs needed for this
58 # particular 'wiz' window; for example, for example,
59 # GA::PrefWin::TaskStart uses it to specify a task name and type.
60 # Set to an empty hash if not required
61 # - This type of window object recognises these initialisation settings:
62 #
63 # ...
64 #
65 # Return values
66 # 'undef' on improper arguments or if the window can't be created
67 # Blessed reference to the newly-created object on success
68  
69 my (
70 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
71 %configHash,
72 ) = @_;
73  
74 # Check for improper arguments
75 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
76  
77 return $axmud::CLIENT->writeImproper($class . '->new', @_);
78 }
79  
80 # This window must only be opened when GA::Client->start wants to open it
81 if (! $axmud::CLIENT->showSetupWizWinFlag || $axmud::CLIENT->sessionCount) {
82  
83 return undef;
84 }
85  
86 # Set the values to use for some standard window IVs
87 if (! $title) {
88  
89 $title = $axmud::SCRIPT . ' setup wizard';
90 }
91  
92 # Setup
93 my $self = {
94 _objName => 'wiz_win_' . $number,
95 _objClass => $class,
96 _parentFile => undef, # No parent file object
97 _parentWorld => undef, # No parent file object
98 _privFlag => TRUE, # All IVs are private
99  
100 # Standard window object IVs
101 # --------------------------
102  
103 # Unique number for this window object
104 number => $number,
105 # The window category - 'grid' or 'free'
106 winCategory => 'free',
107 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
108 winType => 'wiz',
109 # A name for the window (for 'config' windows, the same as the window type)
110 winName => 'setup_wiz',
111 # The GA::Obj::Workspace object for the workspace in which this window is created
112 workspaceObj => $workspaceObj,
113 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
114 # object. When this window opens/closes, the owner is informed via calls to its
115 # ->add_childFreeWin / ->del_childFreeWin functions
116 owner => $owner,
117 # The GA::Session from which this function was called. 'undef' if the calling function
118 # didn't specify a session and $owner's ->session IV is also 'undef'
119 session => $session,
120 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
121 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
122 # displayed in a 'dialogue' window)
123 pseudoCmdMode => 'win_error',
124  
125 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
126 # parent 'main' window's Gtk3::Window
127 # The code should use this IV when it wants to do something to the window itself
128 # (minimise it, make it active, etc)
129 winWidget => undef,
130 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
131 # the parent GA::Table::PseudoWin table object
132 # The code should use this IV when it wants to add, modify or remove widgets inside the
133 # window itself
134 winBox => undef,
135 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
136 # FALSE if not
137 enabledFlag => FALSE,
138 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
139 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
140 visibleFlag => TRUE,
141 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
142 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
143 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
144 childFreeWinHash => {},
145 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
146 # window is informed via a call to $self->del_childFreeWin
147 # When the child is destroyed, this window might want to call some of its own functions
148 # to update various widgets and/or IVs, in which case this window adds an entry to
149 # this hash; a hash in the form
150 # $childDestroyHash{unique_number} = list_reference
151 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
152 # reference to a list in groups of 2, in the form
153 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
154 childDestroyHash => {},
155  
156 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
157 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
158 # area)
159 packingBox => undef, # Gtk3::VBox
160  
161 # Standard IVs for 'free' windows
162  
163 # The window's default size, in pixels
164 widthPixels => $axmud::CLIENT->customFreeWinWidth,
165 heightPixels => $axmud::CLIENT->customFreeWinHeight,
166 # Default border/item spacing sizes used in the window, in pixels
167 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
168 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
169  
170 # A string to use as the window title. If 'undef', a generic title is used
171 title => $title,
172 # Hash containing any number of key-value pairs needed for this particular 'config'
173 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
174 # name and type. Set to an empty hash if not required
175 configHash => {%configHash},
176  
177 # Standard IVs for 'wiz' windows
178  
179 # Widgets
180  
181 # A vertical pane, with the main area above, and a button strip below
182 scroller => undef, # Gtk3::ScrolledWindow
183 hAdjustment => undef, # Gtk3::Adjustment
184 vAdjustment => undef, # Gtk3::Adjustment
185 grid => undef, # Gtk3::Grid
186 hBox => undef, # Gtk3::HBox
187 nextButton => undef, # Gtk3::Button
188 previousButton => undef, # Gtk3::Button
189 cancelButton => undef, # Gtk3::Button
190  
191 # Three flags that can be set by any page, to prevent one of three buttons from being
192 # made sensitive (temporarily)
193 disableNextButtonFlag => FALSE,
194 disablePreviousButtonFlag => FALSE,
195 disableCancelButtonFlag => FALSE,
196  
197 # The names of pages, in order of appearance
198 pageList => [
199 'intro',
200 'mainWin',
201 'zonemap',
202 'world',
203 'task',
204 'sigil',
205 'last',
206 ],
207 # The number of the current page (first page is 0)
208 currentPage => 0,
209  
210 # Two hashes for using the 'Next' / 'Previous' buttons to skip around the pages, rather
211 # than going to the actual next or previous page (as normal)
212 # The current page should add an entry to the hash, if necessary; the entry is removed
213 # by ->buttonPrevious or ->buttonNext as soon as either button is clicked
214 # Hashes in the form
215 # $hash{current_page_number} = page_number_if_button_clicked
216 # NB The first page's number is 0, so the fourth page will be page 3, not page 4
217 specialNextButtonHash => {},
218 specialPreviousButtonHash => {},
219  
220 # IVs for this type of 'wiz' window
221  
222 # Corresponds to same IV in GA::Client
223 shareMainWinFlag => TRUE,
224 # Default zonemap for the first workspace, stored in GA::Client->initWorkspaceHash -
225 # 'basic', 'extended', 'widescreen', 'horizontal2', 'vertical2' or, representing
226 # GA::Client->activateGridFlag = TRUE, the value 'none'
227 zonemap => 'basic',
228 # Flag set to TRUE if $self->zonemapPage decides to switch the zonemap to 'widescreen',
229 # so that this happens only once (i.e. if the Previous button is clicked, we don't
230 # want to switch the zonemap back to widescreen a second time)
231 widescreenFlag => FALSE,
232  
233 # The GA::Obj::SimpleList containing a list of pre-configured worlds
234 slWidget => undef,
235  
236 # Pre-configured worlds, in the order they're
237 # Initial tasks
238 taskInitHash => {
239 'status' => TRUE,
240 'locator' => TRUE,
241 'attack' => FALSE,
242 'compass' => FALSE,
243 'channels' => FALSE,
244 'divert' => FALSE,
245 'inventory' => FALSE,
246 'launch' => FALSE,
247 'notepad' => FALSE,
248 },
249 # Initial task settings
250 taskSettingHash => {
251 'status_win' => TRUE,
252 'status_gauge' => TRUE,
253 'locator_win' => TRUE,
254 },
255 # Instruction sigils
256 sigilHash => {
257 'echo' => FALSE,
258 'perl' => FALSE,
259 'script' => FALSE,
260 'multi' => FALSE,
261 'speed' => FALSE,
262 'bypass' => FALSE,
263 },
264 };
265  
266 # Bless the object into existence
267 bless $self, $class;
268  
269 return $self;
270 }
271  
272 ##################
273 # Methods
274  
275 # Standard window object functions
276  
277 sub winSetup {
278  
279 # Called by GA::Generic::Win->createFreeWin, after the call to $self->new
280 # Creates the Gtk3::Window itself
281 #
282 # Expected arguments
283 # (none besides $self)
284 #
285 # Return values
286 # 'undef' on improper arguments or if the window can't be opened
287 # 1 on success
288  
289 my ($self, $check) = @_;
290  
291 # Local variables
292 my ($hAdjust, $vAdjust, $ratioX, $ratioY, $newX, $newY);
293  
294 # Check for improper arguments
295 if (defined $check) {
296  
297 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
298 }
299  
300 # Most of the code is in the generic function
301 if (! $self->Games::Axmud::Generic::FreeWin::winSetup()) {
302  
303 return undef;
304 }
305  
306 # Some desktop managers use a bigger font than the author's desktop manager; as a result,
307 # 'free' windows like this one will be too small for comfort
308 # This window is (usually) only seen the first time Axmud is run. If the user's destkop
309 # manager font is too big, this window's Gtk3::ScrolledWindow will contain scrollbars
310 # If the scrollbars are present, we can increase the size of default 'free' windows to
311 # compensate, which removes the scrollbars in this window and (hopefully) most other
312 # 'free' windows, too
313 # Typically, this process makes the default 'free' window size slightly larger than it
314 # strictly needs to be, but that's still better than a Connections window with none of
315 # the 'Connect' buttons visible
316  
317 # Drawing the window early makes the scrollbars testable (->winShowAll() is normally first
318 # called by $self->winEnable)
319 $self->winShowAll($self->_objClass . '->winSetup');
320  
321 # Detect the presence of any scrollbars and decide by which ratio the window's size should
322 # be increased
323 $hAdjust = $self->scroller->get_hadjustment();
324 if ($hAdjust->get_upper() != $hAdjust->get_page_size()) {
325 $ratioX = $hAdjust->get_upper() / $hAdjust->get_page_size();
326 } else {
327 $ratioX = 1;
328 }
329  
330 $vAdjust = $self->scroller->get_vadjustment();
331 if ($vAdjust->get_upper() != $vAdjust->get_page_size()) {
332 $ratioY = $vAdjust->get_upper() / $vAdjust->get_page_size();
333 } else {
334 $ratioY = 1;
335 }
336  
337 if ($ratioX != 1 || $ratioY != 1) {
338  
339 # One (or both) scrollbars detected
340 $newX = int($self->widthPixels * $ratioX);
341 $newY = int($self->heightPixels * $ratioY);
342  
343 # Adjust the size of this window to compensate
344 $self->winWidget->resize($newX, $newY);
345 # Adjust the default size of future 'free' windows to compensate
346 $axmud::CLIENT->set_customFreeWinSize($newX, $newY);
347 }
348  
349 return 1;
350 }
351  
352 # sub winEnable {} # Inherited from GA::Generic::WizWin
353  
354 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
355  
356 sub winDestroy {
357  
358 # Can be called by anything
359 # Updates IVs
360 #
361 # Expected arguments
362 # (none besides $self)
363 #
364 # Return values
365 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
366 # been destroyed
367 # 1 on success
368  
369 my ($self, $check) = @_;
370  
371 # Local variables
372 my $result;
373  
374 # Check for improper arguments
375 if (defined $check) {
376  
377 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
378 }
379  
380 # Most of the code is in the generic function
381 $result = $self->Games::Axmud::Generic::WizWin::winDestroy();
382 if ($result) {
383  
384 # Window closed. The Connections window must now be opened
385 $axmud::CLIENT->mainWin->quickFreeWin('Games::Axmud::OtherWin::Connect');
386 }
387  
388 return $result;
389 }
390  
391 # sub winShowAll {} # Inherited from GA::Generic::Win
392  
393 # sub drawWidgets {} # Inherited from GA::Generic::WizWin
394  
395 # sub redrawWidgets {} # Inherited from GA::Generic::Win
396  
397 # ->signal_connects
398  
399 # Other functions
400  
401 sub saveChanges {
402  
403 # Called by $self->buttonNext when the user clicks the 'Finish' button
404 # Saves changes to the current world profile and/or current dictionary, before closing the
405 # window
406 #
407 # Expected arguments
408 # (none besides $self)
409 #
410 # Return values
411 # 'undef' on improper arguments
412 # 1 otherwise
413  
414 my ($self, $check) = @_;
415  
416 # Local variables
417 my (
418 $zonemapObj, $slWidget, $initStatusObj, $initLocatorObj,
419 @taskList,
420 %checkHash,
421 );
422  
423 # Check for improper arguments
424 if (defined $check) {
425  
426 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
427 }
428  
429 # Update Client IVs
430 if (! $self->shareMainWinFlag) {
431 $axmud::CLIENT->set_shareMainWinFlag(FALSE);
432 } else {
433 $axmud::CLIENT->set_shareMainWinFlag(TRUE);
434 }
435  
436 if ($self->zonemap eq 'none') {
437  
438 $axmud::CLIENT->set_activateGridFlag(TRUE);
439 $axmud::CLIENT->desktopObj->defaultWorkspaceObj->disableWorkspaceGrids();
440 $axmud::CLIENT->desktopObj->defaultWorkspaceObj->reset_defaultZonemap();
441  
442 } else {
443  
444 $axmud::CLIENT->ivAdd('initWorkspaceHash', 0, $self->zonemap);
445 $zonemapObj = $axmud::CLIENT->ivShow('zonemapHash', $self->zonemap);
446 if ($zonemapObj) {
447  
448 $axmud::CLIENT->desktopObj->defaultWorkspaceObj->set_defaultZonemap($zonemapObj);
449 }
450 }
451  
452 # In v1.2.0, window tiling was enabled for MSWin users. For those users with existing Axmud
453 # installations, this 'wiz' window is called a second time
454 # For that reason, check that Locator/Status tasks don't already exist in the global
455 # tasklist. If they do, update their settings, rather than creating a new task
456 foreach my $initTaskObj ($axmud::CLIENT->ivValues('initTaskHash')) {
457  
458 if ($initTaskObj->name eq 'status_task') {
459 $initStatusObj = $initTaskObj;
460 } elsif ($initTaskObj->name eq 'locator_task') {
461 $initLocatorObj = $initTaskObj;
462 }
463  
464 # While we're at it, compile a hash of global initial tasks, containing only the first
465 # instance of each type of task
466 $checkHash{$initTaskObj->name} = undef;
467 }
468  
469 # Remove pre-configured worlds, as required
470 $slWidget = $self->slWidget;
471 OUTER: foreach my $listRef (@{$slWidget->{data}}) {
472  
473 my ($worldObj, $fileObj);
474  
475 # $listRef is in the form [remove_flag, profile_name...]
476 if ($$listRef[0]) {
477  
478 # Remove this world profile
479 $worldObj = $axmud::CLIENT->ivShow('worldProfHash', $$listRef[1]);
480 if ($worldObj) {
481  
482 # (It should not be possible for any session to be running, but in case someone
483 # is testing this window, we'll check anyway)
484 INNER: foreach my $session ($axmud::CLIENT->listSessions()) {
485  
486 if (defined $session->currentWorld && $session->currentWorld eq $worldObj) {
487  
488 # (Not a fatal error)
489 $axmud::CLIENT->writeWarning(
490 'Could not delete world profile \'' . $worldObj->name
491 . '\' - it is in use by a session',
492 $self->_objClass . '->saveChanges',
493 );
494  
495 next OUTER;
496 }
497 }
498  
499 # Delete the world's data files. First find the file object
500 $fileObj = $axmud::CLIENT->ivShow('fileObjHash', $worldObj->name);
501 if (! $fileObj) {
502  
503 # (Not a fatal error)
504 $axmud::CLIENT->writeWarning(
505 'Could not delete world profile \'' . $worldObj->name
506 . '\' - file object is missing',
507 $self->_objClass . '->saveChanges',
508 );
509 }
510  
511 # Delete the whole directory used for that world (e.g. /data/worlds/WORLD_NAME)
512 if (! $fileObj->destroyStandardDir()) {
513  
514 # (Not a fatal error)
515 $axmud::CLIENT->writeWarning(
516 'Could not delete data files for the world profile \'' . $worldObj->name
517 . '\'',
518 $self->_objClass . '->saveChanges',
519 );
520 }
521  
522 # Update the GA::Client registries
523 $axmud::CLIENT->del_worldProf($worldObj);
524 $axmud::CLIENT->del_fileObj($fileObj);
525 }
526 }
527 }
528  
529 # Add initial tasks (if any) in a set order
530 @taskList = qw(status locator attack compass channels divert inventory launch notepad);
531 foreach my $name (@taskList) {
532  
533 my $taskObj;
534  
535 if ($self->ivShow('taskInitHash', $name)) {
536  
537 if ($name eq 'status' && $initStatusObj) {
538  
539 $taskObj = $initStatusObj;
540  
541 } elsif ($name eq 'locator' && $initLocatorObj) {
542  
543 $taskObj = $initLocatorObj;
544  
545 } elsif (! exists $checkHash{$name . '_task'}) {
546  
547 # e.g. 'status_task'
548 $taskObj = $axmud::CLIENT->addGlobalInitTask($name . '_task');
549 }
550  
551 if ($taskObj) {
552  
553 if ($name eq 'status') {
554  
555 if (! $self->ivShow('taskSettingHash', 'status_win')) {
556 $taskObj->set_startWithWinFlag(FALSE);
557 } else {
558 $taskObj->set_startWithWinFlag(TRUE);
559 }
560  
561 if (! $self->ivShow('taskSettingHash', 'status_gauge')) {
562 $taskObj->set_gaugeFlag(FALSE);
563 } else {
564 $taskObj->set_gaugeFlag(TRUE);
565 }
566  
567 } elsif ($name eq 'locator') {
568  
569 if (! $self->ivShow('taskSettingHash', 'locator_win')) {
570 $taskObj->set_startWithWinFlag(FALSE);
571 } else {
572 $taskObj->set_startWithWinFlag(TRUE);
573 }
574 }
575 }
576 }
577 }
578  
579 # Enable instruction sigils, in no particular order
580 foreach my $sigil ($self->ivKeys('sigilHash')) {
581  
582 if ($self->ivShow('sigilHash', $sigil)) {
583  
584 $axmud::CLIENT->toggle_sigilFlag($sigil);
585 }
586 }
587  
588 # All changes made. Close the window
589 $self->winDestroy();
590  
591 return 1;
592 }
593  
594 # Standard callbacks
595  
596 sub buttonCancel {
597  
598 # 'Cancel' button callback
599 #
600 # Expected arguments
601 # (none besides $self)
602 #
603 # Return values
604 # 'undef' on improper arguments
605 # 1 otherwise
606  
607 my ($self, $check) = @_;
608  
609 # Local variables
610 my $taskObj;
611  
612 # Check for improper arguments
613 if (defined $check) {
614  
615 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonCancel', @_);
616 }
617  
618 # Close the window
619 $self->winDestroy();
620  
621 # Do the average user a favour by adding the Status and Locator tasks to the global initial
622 # tasklist, even if they clicked the 'Cancel' button
623 # (Of course, if the user closed the window some other way, no initial tasks are added)
624 $taskObj = $axmud::CLIENT->addGlobalInitTask('status_task');
625 if ($taskObj) {
626  
627 $taskObj->set_gaugeFlag(TRUE);
628 }
629  
630 $axmud::CLIENT->addGlobalInitTask('locator_task');
631  
632 return 1;
633 }
634  
635 # Window pages
636  
637 sub introPage {
638  
639 # Intro page - called by $self->setupGrid or ->updateGrid
640 #
641 # Expected arguments
642 # (none besides $self)
643 #
644 # Return values
645 # 'undef' on improper arguments
646 # 1 otherwise
647  
648 my ($self, $check) = @_;
649  
650 # Local variables
651 my @spacingList;
652  
653 # Check for improper arguments
654 if (defined $check) {
655  
656 return $axmud::CLIENT->writeImproper($self->_objClass . '->introPage', @_);
657 }
658  
659 # Intro
660 $self->addLabel($self->grid, '<b>Setup wizard (' . $self->getPageString() . ')</b>',
661 0, 12, 0, 1);
662  
663 $self->addSimpleImage(
664 $self->grid,
665 $axmud::CLIENT->getDialogueIcon('large'),
666 undef,
667 1, 6, 1, 12);
668  
669 # (Empty labels for spacing)
670 my $label = $self->addLabel($self->grid, '',
671 7, 10, 1, 4);
672 $label->set_vexpand(TRUE);
673  
674 $self->addLabel($self->grid, '<b>Welcome to ' . $axmud::SCRIPT . '!</b>',
675 7, 10, 4, 5);
676 $self->addLabel(
677 $self->grid,
678 '<i>Please take a few moments to set up your new MUD client</i>',
679 7, 10, 5, 6);
680  
681 my $button = $self->addButton(
682 $self->grid,
683 undef,
684 "Ok, let's get started!",
685 "Move on to the next page",
686 7, 10, 6, 7);
687 $button->set_vexpand(TRUE);
688 $button->signal_connect('clicked' => sub {
689  
690 # (The same as clicking the 'Next' button at the bottom of the window)
691 $self->buttonNext();
692 });
693  
694 my $button2 = $self->addButton(
695 $self->grid,
696 undef,
697 "Use recommended settings for my system",
698 "Close this window and use recommended settings",
699 7, 10, 7, 8);
700 $button2->set_vexpand(TRUE);
701 $button2->signal_connect('clicked' => sub {
702  
703 # The only change that the widgets on the following pages make is to set the zonemap...
704 if (
705 defined $self->workspaceObj->currentWidth
706 && $self->workspaceObj->currentWidth >= 1800
707 ) {
708 $self->ivPoke('zonemap', 'widescreen');
709 }
710  
711 # All other system-dependent changes are already specified by this object's IVs, so we
712 # can call the function as if the user had clicked the 'Save' button at the bottom of
713 # the window
714 $self->saveChanges();
715 });
716  
717 my $button3 = $self->addButton(
718 $self->grid,
719 undef,
720 "Just use default settings",
721 "Close this window and use default settings",
722 7, 10, 8, 9);
723 $button3->set_vexpand(TRUE);
724 $button3->signal_connect('clicked' => sub {
725  
726 # (The same as clicking the 'Cancel' button at the bottom of the window)
727 $self->buttonCancel();
728 });
729  
730 # (Empty labels for spacing)
731 my $label2 = $self->addLabel($self->grid, '',
732 7, 10, 9, 12);
733 $label2->set_vexpand(TRUE);
734  
735 return 1;
736 }
737  
738 sub mainWinPage {
739  
740 # 'Main' window page - called by $self->setupGrid or ->updateGrid
741 #
742 # Expected arguments
743 # (none besides $self)
744 #
745 # Return values
746 # 'undef' on improper arguments
747 # 1 otherwise
748  
749 my ($self, $check) = @_;
750  
751 # Local variables
752 my @spacingList;
753  
754 # Check for improper arguments
755 if (defined $check) {
756  
757 return $axmud::CLIENT->writeImproper($self->_objClass . '->mainWinPage', @_);
758 }
759  
760 # 'Main' windows
761 $self->addLabel($self->grid, '<b>\'Main\' windows (' . $self->getPageString() . ')</b>',
762 0, 12, 0, 1);
763 $self->addLabel(
764 $self->grid,
765 "<i>Choose how Axmud handles multiple simultaneous connections.</i>",
766 1, 12, 1, 2);
767  
768 $self->addSimpleImage(
769 $self->grid,
770 $axmud::SHARE_DIR . '/icons/setup/shared.png',
771 undef,
772 1, 3, 3, 5);
773  
774 my ($radioButton, $radioButton2, $group);
775 ($group, $radioButton) = $self->addRadioButton(
776 $self->grid,
777 undef,
778 undef,
779 undef,
780 FALSE,
781 TRUE,
782 4, 5, 3, 4);
783  
784 $self->addLabel(
785 $self->grid,
786 "All connections <b>share</b> a single \'main\' window.",
787 5, 12, 3, 4);
788  
789 $self->addLabel(
790 $self->grid,
791 "<i>This is a good choice if you have a small monitor, or if you often connect\n"
792 . "to several worlds at a time. You can click the tabs at the top of each\n"
793 . "window to switch between connections.</i>",
794 5, 12, 4, 5);
795  
796 # (Empty labels for spacing)
797 $self->addLabel($self->grid, '',
798 1, 12, 5, 6);
799  
800 $self->addSimpleImage(
801 $self->grid,
802 $axmud::SHARE_DIR . '/icons/setup/single.png',
803 undef,
804 1, 3, 6, 8);
805  
806 ($group, $radioButton2) = $self->addRadioButton(
807 $self->grid,
808 undef,
809 $group,
810 undef,
811 FALSE,
812 TRUE,
813 4, 5, 6, 7);
814  
815 $self->addLabel(
816 $self->grid,
817 "All connections have <b>their own</b> \'main\' window.",
818 5, 12, 6, 7);
819  
820 $self->addLabel(
821 $self->grid,
822 "<i>This is a good choice if you have a large monitor (or several monitors),\n"
823 . "or if you rarely connect to more than one world at a time.</i>",
824 5, 12, 7, 8);
825  
826 # (->signal_connects from above)
827 if ($self->shareMainWinFlag) {
828 $radioButton->set_active(TRUE);
829 } else {
830 $radioButton2->set_active(TRUE);
831 }
832  
833 $radioButton->signal_connect('toggled' => sub {
834  
835 if ($radioButton->get_active()) {
836  
837 $self->ivPoke('shareMainWinFlag', TRUE);
838 $self->ivPoke('zonemap', 'basic');
839 }
840 });
841  
842 $radioButton2->signal_connect('toggled' => sub {
843  
844 if ($radioButton2->get_active()) {
845  
846 $self->ivPoke('shareMainWinFlag', FALSE);
847 $self->ivPoke('zonemap', 'horizontal');
848 }
849 });
850  
851 # (Empty labels for spacing)
852 my $label = $self->addLabel($self->grid, '',
853 1, 12, 9, 10);
854 $label->set_vexpand(TRUE);
855  
856 return 1;
857 }
858  
859 sub zonemapPage {
860  
861 # Zonemap page - called by $self->setupGrid or ->updateGrid
862 #
863 # Expected arguments
864 # (none besides $self)
865 #
866 # Return values
867 # 'undef' on improper arguments
868 # 1 otherwise
869  
870 my ($self, $check) = @_;
871  
872 # Local variables
873 my @spacingList;
874  
875 # Check for improper arguments
876 if (defined $check) {
877  
878 return $axmud::CLIENT->writeImproper($self->_objClass . '->zonemapPage', @_);
879 }
880  
881 # Zonemaps
882 $self->addLabel($self->grid, '<b>Zonemaps (' . $self->getPageString() . ')</b>',
883 0, 12, 0, 1);
884 $self->addLabel(
885 $self->grid,
886 "<i>A zonemap is a plan for arranging windows on the desktop. Select the best zonemap"
887 . " for your system.</i>",
888 1, 12, 1, 2);
889  
890 if ($self->shareMainWinFlag) {
891  
892 $self->addSimpleImage(
893 $self->grid,
894 $axmud::SHARE_DIR . '/icons/setup/basic_zonemap.png',
895 undef,
896 1, 4, 2, 5);
897  
898 my ($radioButton, $radioButton2, $radioButton3, $group);
899 ($group, $radioButton) = $self->addRadioButton(
900 $self->grid,
901 undef,
902 undef,
903 'Basic',
904 FALSE,
905 TRUE,
906 4, 6, 3, 4);
907  
908 $self->addSimpleImage(
909 $self->grid,
910 $axmud::SHARE_DIR . '/icons/setup/extended_zonemap.png',
911 undef,
912 7, 10, 2, 5);
913  
914 ($group, $radioButton2) = $self->addRadioButton(
915 $self->grid,
916 undef,
917 $group,
918 'Extended',
919 FALSE,
920 TRUE,
921 10, 12, 3, 4);
922  
923 # (Empty labels for spacing)
924 $self->addLabel($self->grid, '',
925 1, 12, 5, 6);
926  
927 $self->addSimpleImage(
928 $self->grid,
929 $axmud::SHARE_DIR . '/icons/setup/widescreen_zonemap.png',
930 undef,
931 1, 4, 6, 9);
932  
933 ($group, $radioButton3) = $self->addRadioButton(
934 $self->grid,
935 undef,
936 $group,
937 'Widescreen',
938 FALSE,
939 TRUE,
940 4, 6, 7, 8);
941  
942 # (->signal_connects from above)
943  
944 # As a convenience for users, auto-set the 'widescreen' zonemap (but only do this once,
945 # otherwise widescreen will be re-selected if the 'Previous' button is clicked)
946 # Use 1800, rather than 1920, as the test in case there are desktop panels on the
947 # left and/or right sides
948  
949 if (
950 defined $self->workspaceObj->currentWidth
951 && $self->workspaceObj->currentWidth >= 1800
952 && ! $self->widescreenFlag
953 ) {
954 $radioButton3->set_active(TRUE);
955 $self->ivPoke('zonemap', 'widescreen');
956 $self->ivPoke('widescreenFlag', TRUE);
957  
958 } elsif ($self->zonemap eq 'basic') {
959  
960 $radioButton->set_active(TRUE);
961  
962 } elsif ($self->zonemap eq 'extended') {
963  
964 $radioButton2->set_active(TRUE);
965  
966 } else {
967  
968 $radioButton3->set_active(TRUE);
969 }
970  
971 $radioButton->signal_connect('toggled' => sub {
972  
973 if ($radioButton->get_active()) {
974  
975 $self->ivPoke('zonemap', 'basic');
976 }
977 });
978  
979 $radioButton2->signal_connect('toggled' => sub {
980  
981 if ($radioButton2->get_active()) {
982  
983 $self->ivPoke('zonemap', 'extended');
984 }
985 });
986  
987 $radioButton3->signal_connect('toggled' => sub {
988  
989 if ($radioButton3->get_active()) {
990  
991 $self->ivPoke('zonemap', 'widescreen');
992 }
993 });
994  
995 } else {
996  
997 $self->addSimpleImage(
998 $self->grid,
999 $axmud::SHARE_DIR . '/icons/setup/horizontal_zonemap.png',
1000 undef,
1001 1, 4, 2, 5);
1002  
1003 my ($radioButton, $radioButton2, $radioButton3, $group);
1004 ($group, $radioButton) = $self->addRadioButton(
1005 $self->grid,
1006 undef,
1007 $group,
1008 'Horizontal',
1009 FALSE,
1010 TRUE,
1011 4, 6, 3, 4);
1012  
1013 $self->addSimpleImage(
1014 $self->grid,
1015 $axmud::SHARE_DIR . '/icons/setup/vertical_zonemap.png',
1016 undef,
1017 7, 10, 2, 5);
1018  
1019 ($group, $radioButton2) = $self->addRadioButton(
1020 $self->grid,
1021 undef,
1022 $group,
1023 'Vertical',
1024 FALSE,
1025 TRUE,
1026 10, 12, 3, 4);
1027  
1028 # (Empty labels for spacing)
1029 $self->addLabel($self->grid, '',
1030 1, 12, 5, 6);
1031  
1032 $self->addSimpleImage(
1033 $self->grid,
1034 $axmud::SHARE_DIR . '/icons/setup/no_zonemap.png',
1035 undef,
1036 1, 4, 6, 9);
1037  
1038 ($group, $radioButton3) = $self->addRadioButton(
1039 $self->grid,
1040 undef,
1041 $group,
1042 'No zonemap',
1043 FALSE,
1044 TRUE,
1045 4, 6, 7, 8);
1046  
1047 # (->signal_connects from above)
1048 if ($self->zonemap eq 'horizontal') {
1049 $radioButton->set_active(TRUE);
1050 } elsif ($self->zonemap eq 'vertical') {
1051 $radioButton2->set_active(TRUE);
1052 } else {
1053 $radioButton3->set_active(TRUE);
1054 }
1055  
1056 $radioButton->signal_connect('toggled' => sub {
1057  
1058 if ($radioButton->get_active()) {
1059  
1060 $self->ivPoke('zonemap', 'horizontal2');
1061 }
1062 });
1063  
1064 $radioButton2->signal_connect('toggled' => sub {
1065  
1066 if ($radioButton2->get_active()) {
1067  
1068 $self->ivPoke('zonemap', 'vertical2');
1069 }
1070 });
1071  
1072 $radioButton3->signal_connect('toggled' => sub {
1073  
1074 if ($radioButton3->get_active()) {
1075  
1076 $self->ivPoke('zonemap', 'none');
1077 }
1078 });
1079 }
1080  
1081 # (Empty labels for spacing)
1082 my $label = $self->addLabel($self->grid, '',
1083 1, 12, 9, 10);
1084 $label->set_vexpand(TRUE);
1085  
1086 return 1;
1087 }
1088  
1089 sub worldPage {
1090  
1091 # World page - called by $self->setupGrid or ->updateGrid
1092 #
1093 # Expected arguments
1094 # (none besides $self)
1095 #
1096 # Return values
1097 # 'undef' on improper arguments
1098 # 1 otherwise
1099  
1100 my ($self, $check) = @_;
1101  
1102 # Local variables
1103 my (
1104 $count,
1105 @columnList, @dataList,
1106 );
1107  
1108 # Check for improper arguments
1109 if (defined $check) {
1110  
1111 return $axmud::CLIENT->writeImproper($self->_objClass . '->worldPage', @_);
1112 }
1113  
1114 # Pre-configured worlds
1115 $self->addLabel(
1116 $self->grid, '<b>Pre-configured worlds (' . $self->getPageString() . ')</b>',
1117 0, 12, 0, 1);
1118 $self->addLabel(
1119 $self->grid,
1120 '<i>If you don\'t want a lot of pre-configured worlds, you can remove some of them'
1121 . ' here.</i>',
1122 1, 12, 1, 2);
1123  
1124 # Add a simple list
1125 @columnList = (
1126 'Remove', 'bool_editable',
1127 'Profile', 'text',
1128 'Pre-configured world', 'text',
1129 'Host', 'text',
1130 'Port', 'int',
1131 );
1132  
1133 $count = $axmud::CLIENT->ivPairs('worldProfHash');
1134 foreach my $worldObj (
1135 sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('worldProfHash'))
1136 ) {
1137 push (@dataList,
1138 FALSE, # Don't delete the world profile, unless the user selects it
1139 $worldObj->name,
1140 $worldObj->longName,
1141 $worldObj->dns,
1142 $worldObj->port,
1143 );
1144 }
1145  
1146 my $slWidget = $self->addSimpleList($self->grid, \@columnList, \@dataList,
1147 1, 12, 2, 11);
1148  
1149 my $button = $self->addButton(
1150 $self->grid,
1151 undef,
1152 'Remove all', 'Remove all pre-configured worlds',
1153 1, 6, 11, 12);
1154 $button->signal_connect('clicked' => sub {
1155  
1156 for (my $i = 0; $i < $count; $i++) {
1157  
1158 ${$slWidget->{data}}[$i][0] = TRUE;
1159 }
1160 });
1161  
1162 my $button2 = $self->addButton(
1163 $self->grid,
1164 undef,
1165 'Remove none', 'Retain all pre-configured worlds',
1166 6, 12, 11, 12);
1167 $button2->signal_connect('clicked' => sub {
1168  
1169 for (my $i = 0; $i < $count; $i++) {
1170  
1171 ${$slWidget->{data}}[$i][0] = FALSE;
1172 }
1173 });
1174  
1175 # Update IVs
1176 $self->ivPoke('slWidget', $slWidget);
1177  
1178 return 1;
1179 }
1180  
1181 sub taskPage {
1182  
1183 # Task page - called by $self->setupGrid or ->updateGrid
1184 #
1185 # Expected arguments
1186 # (none besides $self)
1187 #
1188 # Return values
1189 # 'undef' on improper arguments
1190 # 1 otherwise
1191  
1192 my ($self, $check) = @_;
1193  
1194 # Local variables
1195 my (
1196 $noneFlag,
1197 @signalList, @signalList2,
1198 );
1199  
1200 # Check for improper arguments
1201 if (defined $check) {
1202  
1203 return $axmud::CLIENT->writeImproper($self->_objClass . '->taskPage', @_);
1204 }
1205  
1206 # Tasks
1207 $self->addLabel($self->grid, '<b>Tasks (' . $self->getPageString() . ')</b>',
1208 0, 12, 0, 1);
1209 $self->addLabel(
1210 $self->grid,
1211 "<i>Choose which of " . $axmud::SCRIPT . "'s built-in tasks (if any) should start at"
1212 . " the beginning of every session.</i>",
1213 1, 10, 1, 2);
1214 my $button = $self->addButton(
1215 $self->grid,
1216 undef,
1217 'Select all', 'Select/deselect all tasks',
1218 10, 12, 1, 2);
1219  
1220 # Recommended tasks
1221 $self->addLabel($self->grid, '<u>Recommended tasks</u>',
1222 1, 12, 2, 3);
1223  
1224 $self->addSimpleImage(
1225 $self->grid,
1226 $axmud::SHARE_DIR . '/icons/setup/status_task.png',
1227 undef,
1228 1, 2, 3, 5);
1229  
1230 my $checkButton = $self->addCheckButton(
1231 $self->grid,
1232 'Status task',
1233 undef,
1234 $self->ivShow('taskInitHash', 'status'),
1235 TRUE,
1236 2, 6, 3, 4);
1237 my $checkButton2 = $self->addCheckButton(
1238 $self->grid,
1239 'Show task window',
1240 undef,
1241 $self->ivShow('taskSettingHash', 'status_win'),
1242 TRUE,
1243 2, 4, 4, 5);
1244 my $checkButton3 = $self->addCheckButton(
1245 $self->grid,
1246 'Show gauges',
1247 undef,
1248 $self->ivShow('taskSettingHash', 'status_gauge'),
1249 TRUE,
1250 4, 6, 4, 5);
1251  
1252 $self->addLabel(
1253 $self->grid,
1254 "<i>Tracks information about the character, such as their\n"
1255 . "health and energy points. It's essential for the gauges\n"
1256 . "that appear near the bottom of the 'main' window.</i>",
1257 1, 6, 6, 7);
1258  
1259 $self->addSimpleImage(
1260 $self->grid,
1261 $axmud::SHARE_DIR . '/icons/setup/locator_task.png',
1262 undef,
1263 7, 8, 3, 5);
1264  
1265 my $checkButton4 = $self->addCheckButton(
1266 $self->grid,
1267 'Locator task',
1268 undef,
1269 $self->ivShow('taskInitHash', 'locator'),
1270 TRUE,
1271 8, 12, 3, 4);
1272 my $checkButton5 = $self->addCheckButton(
1273 $self->grid,
1274 'Show task window',
1275 undef,
1276 $self->ivShow('taskSettingHash', 'locator_win'),
1277 TRUE,
1278 8, 12, 4, 5);
1279  
1280 $self->addLabel(
1281 $self->grid,
1282 "<i>Tracks the character\'s position in the world. It\'s essential\n"
1283 . "for the automapper, but neither the Locator nor Status\n"
1284 . "task windows actually need to be open.</i>",
1285 7, 12, 6, 7);
1286  
1287 # Optional tasks
1288 $self->addLabel($self->grid, '<u>Optional tasks</u>',
1289 1, 12, 7, 8);
1290  
1291 $self->addSimpleImage(
1292 $self->grid,
1293 $axmud::SHARE_DIR . '/icons/setup/attack_task.png',
1294 undef,
1295 1, 2, 8, 9);
1296  
1297 my $checkButton6 = $self->addCheckButton(
1298 $self->grid,
1299 'Attack task',
1300 undef,
1301 $self->ivShow('taskInitHash', 'attack'),
1302 TRUE,
1303 2, 6, 8, 9);
1304 $self->addLabel(
1305 $self->grid,
1306 "<i>Tracks the character\'s fights and interactions,\n"
1307 . "updating current profiles as it goes.</i>",
1308 2, 6, 9, 10);
1309  
1310 $self->addSimpleImage(
1311 $self->grid,
1312 $axmud::SHARE_DIR . '/icons/setup/compass_task.png',
1313 undef,
1314 1, 2, 10, 11);
1315  
1316 my $checkButton7 = $self->addCheckButton(
1317 $self->grid,
1318 'Compass task',
1319 undef,
1320 $self->ivShow('taskInitHash', 'compass'),
1321 TRUE,
1322 2, 6, 10, 11);
1323 $self->addLabel(
1324 $self->grid,
1325 "<i>A convenient way to enable and disable keypad\n"
1326 . "macros for moving around the world.</i>",
1327 2, 6, 11, 12);
1328  
1329 $self->addSimpleImage(
1330 $self->grid,
1331 $axmud::SHARE_DIR . '/icons/setup/divert_task.png',
1332 undef,
1333 1, 2, 12, 13);
1334  
1335 my $checkButton8 = $self->addCheckButton(
1336 $self->grid,
1337 'Channels task, or',
1338 undef,
1339 $self->ivShow('taskInitHash', 'divert'),
1340 TRUE,
1341 2, 4, 12, 13);
1342 my $checkButton9 = $self->addCheckButton(
1343 $self->grid,
1344 'Divert task',
1345 undef,
1346 $self->ivShow('taskInitHash', 'divert'),
1347 TRUE,
1348 4, 6, 12, 13);
1349 $self->addLabel(
1350 $self->grid,
1351 "<i>Diverts social messages and tells to a separate\n"
1352 . "task window. Channels tasks have multiple tabs.</i>",
1353 2, 6, 13, 14);
1354  
1355 # (Right column)
1356 $self->addSimpleImage(
1357 $self->grid,
1358 $axmud::SHARE_DIR . '/icons/setup/inventory_task.png',
1359 undef,
1360 7, 8, 8, 9);
1361  
1362 my $checkButton10 = $self->addCheckButton(
1363 $self->grid,
1364 'Inventory task',
1365 undef,
1366 $self->ivShow('taskInitHash', 'inventory'),
1367 TRUE,
1368 8, 12, 8, 9);
1369 $self->addLabel(
1370 $self->grid,
1371 "<i>Keeps track of the character's inventory and\n"
1372 . "displays a summary in its own task window.</i>",
1373 8, 12, 9, 10);
1374  
1375 $self->addSimpleImage(
1376 $self->grid,
1377 $axmud::SHARE_DIR . '/icons/setup/launch_task.png',
1378 undef,
1379 7, 8, 10, 11);
1380  
1381 my $checkButton11 = $self->addCheckButton(
1382 $self->grid,
1383 'Launch task',
1384 undef,
1385 $self->ivShow('taskInitHash', 'launch'),
1386 TRUE,
1387 8, 12, 10, 11);
1388 $self->addLabel(
1389 $self->grid,
1390 "<i>A convenient method for selecting and running\n"
1391 . $axmud::BASIC_NAME . " scripts.</i>",
1392 8, 12, 11, 12);
1393  
1394 $self->addSimpleImage(
1395 $self->grid,
1396 $axmud::SHARE_DIR . '/icons/setup/notepad_task.png',
1397 undef,
1398 7, 8, 12, 13);
1399  
1400 my $checkButton12 = $self->addCheckButton(
1401 $self->grid,
1402 'Notepad task',
1403 undef,
1404 $self->ivShow('taskInitHash', 'notepad'),
1405 TRUE,
1406 8, 12, 12, 13);
1407 $self->addLabel(
1408 $self->grid,
1409 "<i>Write your notes here. They will be waiting for\n"
1410 . "you, the next time you connect to the world.</i>",
1411 8, 12, 13, 14);
1412  
1413 # (->signal_connects from above)
1414 $button->signal_connect('clicked' => sub {
1415  
1416 if (! $noneFlag) {
1417  
1418 # 'Select all'
1419 $checkButton->set_active(TRUE);
1420 $checkButton4->set_active(TRUE);
1421 $checkButton6->set_active(TRUE);
1422 $checkButton7->set_active(TRUE);
1423 $checkButton8->set_active(TRUE);
1424 $checkButton9->set_active(FALSE);
1425 $checkButton10->set_active(TRUE);
1426 $checkButton11->set_active(TRUE);
1427 $checkButton12->set_active(TRUE);
1428  
1429 # Next button click is 'Select none'
1430 $button->set_label('Select none');
1431 $noneFlag = TRUE;
1432  
1433 } else {
1434  
1435 # 'Select none'
1436 $checkButton->set_active(FALSE);
1437 $checkButton2->set_active(FALSE);
1438 $checkButton3->set_active(FALSE);
1439 $checkButton4->set_active(FALSE);
1440 $checkButton5->set_active(FALSE);
1441 $checkButton6->set_active(FALSE);
1442 $checkButton7->set_active(FALSE);
1443 $checkButton8->set_active(FALSE);
1444 $checkButton9->set_active(FALSE);
1445 $checkButton10->set_active(FALSE);
1446 $checkButton11->set_active(FALSE);
1447 $checkButton12->set_active(FALSE);
1448  
1449 # Next button click is 'Select all'
1450 $button->set_label('Select all');
1451 $noneFlag = FALSE;
1452 }
1453 });
1454  
1455 @signalList = (
1456 $checkButton => 'status',
1457 $checkButton4 => 'locator',
1458 $checkButton6 => 'attack',
1459 $checkButton7 => 'compass',
1460 $checkButton8 => 'channels',
1461 $checkButton9 => 'divert',
1462 $checkButton10 => 'inventory',
1463 $checkButton11 => 'launch',
1464 $checkButton12 => 'notepad',
1465 );
1466  
1467 do {
1468  
1469 my ($widget, $key);
1470  
1471 $widget = shift @signalList;
1472 $key = shift @signalList;
1473  
1474 $widget->signal_connect('toggled' => sub {
1475  
1476 if (! $widget->get_active()) {
1477  
1478 $self->ivAdd('taskInitHash', $key, FALSE);
1479  
1480 if ($key eq 'status' && $widget eq $checkButton) {
1481  
1482 # If no Status task, don't show task window or gauges
1483 $checkButton2->set_active(FALSE);
1484 $checkButton3->set_active(FALSE);
1485  
1486 } elsif ($key eq 'locator' && $widget eq $checkButton4) {
1487  
1488 # If not Locator task, don't show task window
1489 $checkButton5->set_active(FALSE);
1490 }
1491  
1492 } else {
1493  
1494 if ($key eq 'channels' && $widget eq $checkButton8) {
1495  
1496 # If Channels selected, don't select Divert
1497 $checkButton9->set_active(FALSE);
1498 $self->ivAdd('taskInitHash', 'channels', TRUE);
1499 $self->ivAdd('taskInitHash', 'divert', FALSE);
1500  
1501 } elsif ($key eq 'divert' && $widget eq $checkButton9) {
1502  
1503 $checkButton8->set_active(FALSE);
1504 $self->ivAdd('taskInitHash', 'divert', TRUE);
1505 $self->ivAdd('taskInitHash', 'channels', FALSE);
1506  
1507 } else {
1508  
1509 $self->ivAdd('taskInitHash', $key, TRUE);
1510 }
1511 }
1512 });
1513  
1514 } until (! @signalList);
1515  
1516 @signalList2 = (
1517 $checkButton2 => 'status_win',
1518 $checkButton3 => 'status_gauge',
1519 $checkButton5 => 'locator_win',
1520 );
1521  
1522 do {
1523  
1524 my ($widget, $key);
1525  
1526 $widget = shift @signalList2;
1527 $key = shift @signalList2;
1528  
1529 $widget->signal_connect('toggled' => sub {
1530  
1531 if (! $widget->get_active()) {
1532 $self->ivAdd('taskSettingHash', $key, FALSE);
1533 } else {
1534 $self->ivAdd('taskSettingHash', $key, TRUE);
1535 }
1536 });
1537  
1538 } until (! @signalList2);
1539  
1540 return 1;
1541 }
1542  
1543 sub sigilPage {
1544  
1545 # Sigil page - called by $self->setupGrid or ->updateGrid
1546 #
1547 # Expected arguments
1548 # (none besides $self)
1549 #
1550 # Return values
1551 # 'undef' on improper arguments
1552 # 1 otherwise
1553  
1554 my ($self, $check) = @_;
1555  
1556 # Local variables
1557 my (
1558 $noneFlag,
1559 @signalList,
1560 );
1561  
1562 # Check for improper arguments
1563 if (defined $check) {
1564  
1565 return $axmud::CLIENT->writeImproper($self->_objClass . '->sigilPage', @_);
1566 }
1567  
1568 # Commands
1569 $self->addLabel($self->grid, '<b>Commands (' . $self->getPageString() . ')</b>',
1570 0, 12, 0, 1);
1571 $self->addLabel(
1572 $self->grid,
1573 "<i>Some types of command start with a special character (sigil). Choose which sigils"
1574 . " to enable.</i>",
1575 1, 10, 1, 2);
1576 my $button = $self->addButton(
1577 $self->grid,
1578 undef,
1579 'Select all', 'Select/deselect all sigils',
1580 10, 12, 1, 2);
1581  
1582 # Compulsory sigils
1583 $self->addLabel($self->grid, '<u>Compulsory sigils</u>',
1584 1, 12, 2, 3);
1585  
1586 $self->addSimpleImage(
1587 $self->grid,
1588 $axmud::SHARE_DIR . '/icons/setup/client_sigil.png',
1589 undef,
1590 1, 2, 3, 4);
1591  
1592 my $checkButton = $self->addCheckButton($self->grid, 'Client commands', undef, TRUE, FALSE,
1593 2, 6, 3, 4);
1594  
1595 $self->addLabel(
1596 $self->grid,
1597 "<i>Client commands are processed by " . $axmud::SCRIPT . " directly,\n"
1598 . "not sent to the world.</i>",
1599 1, 6, 4, 5);
1600  
1601 $self->addSimpleImage(
1602 $self->grid,
1603 $axmud::SHARE_DIR . '/icons/setup/forced_sigil.png',
1604 undef,
1605 7, 8, 3, 4);
1606  
1607 my $checkButton2 = $self->addCheckButton(
1608 $self->grid, 'Forced world commands', undef, TRUE, FALSE,
1609 8, 12, 3, 4);
1610  
1611 $self->addLabel(
1612 $self->grid,
1613 "<i>Everything after the commas is sent directly to the world;\n"
1614 . "useful for world commands beginning with an " . $axmud::SCRIPT . " sigil.</i>",
1615 7, 12, 4, 5);
1616  
1617 # Optional sigils
1618 $self->addLabel($self->grid, '<u>Optional sigils</u>',
1619 1, 12, 5, 6);
1620  
1621 $self->addSimpleImage(
1622 $self->grid,
1623 $axmud::SHARE_DIR . '/icons/setup/echo_sigil.png',
1624 undef,
1625 1, 2, 6, 7);
1626  
1627 my $checkButton3 = $self->addCheckButton(
1628 $self->grid,
1629 'Echo commands',
1630 undef,
1631 $self->ivShow('sigilHash', 'echo'),
1632 TRUE,
1633 2, 6, 6, 7);
1634 $self->addLabel(
1635 $self->grid,
1636 "<i>Everything after the quote is displayed in the\n"
1637 . "'main' window as a system message.</i>",
1638 2, 6, 7, 8);
1639  
1640 $self->addSimpleImage(
1641 $self->grid,
1642 $axmud::SHARE_DIR . '/icons/setup/perl_sigil.png',
1643 undef,
1644 1, 2, 8, 9);
1645  
1646 my $checkButton4 = $self->addCheckButton(
1647 $self->grid,
1648 'Perl commands',
1649 undef,
1650 $self->ivShow('sigilHash', 'perl'),
1651 TRUE,
1652 2, 6, 8, 9);
1653 $self->addLabel(
1654 $self->grid,
1655 "<i>Everything after the forward slash is executed\n"
1656 . "as a mini-Perl programme.</i>",
1657 2, 6, 9, 10);
1658  
1659 $self->addSimpleImage(
1660 $self->grid,
1661 $axmud::SHARE_DIR . '/icons/setup/script_sigil.png',
1662 undef,
1663 1, 2, 10, 11);
1664  
1665 my $checkButton5 = $self->addCheckButton(
1666 $self->grid,
1667 'Script commands',
1668 undef,
1669 $self->ivShow('sigilHash', 'script'),
1670 TRUE,
1671 2, 6, 10, 11);
1672 $self->addLabel(
1673 $self->grid,
1674 "<i>A quick way to run " . $axmud::BASIC_NAME . " scripts. Everything\n"
1675 . "after the ampersand is the name of the script.</i>",
1676 2, 6, 11, 12);
1677  
1678 # (Right column)
1679 $self->addSimpleImage(
1680 $self->grid,
1681 $axmud::SHARE_DIR . '/icons/setup/multi_sigil.png',
1682 undef,
1683 7, 8, 6, 7);
1684  
1685 my $checkButton6 = $self->addCheckButton(
1686 $self->grid,
1687 'Multi commands',
1688 undef,
1689 $self->ivShow('sigilHash', 'multi'),
1690 TRUE,
1691 8, 12, 6, 7);
1692 $self->addLabel(
1693 $self->grid,
1694 "<i>Sends a world command to every session (or every\n"
1695 . "session connected to the same world.)</i>",
1696 8, 12, 7, 8);
1697  
1698 $self->addSimpleImage(
1699 $self->grid,
1700 $axmud::SHARE_DIR . '/icons/setup/speedwalk_sigil.png',
1701 undef,
1702 7, 8, 8, 9);
1703  
1704 my $checkButton7 = $self->addCheckButton(
1705 $self->grid,
1706 'Speedwalk commands',
1707 undef,
1708 $self->ivShow('sigilHash', 'speed'),
1709 TRUE,
1710 8, 12, 8, 9);
1711 $self->addLabel(
1712 $self->grid,
1713 "<i>Speedwalk commands can be simple, e.g. <b>.3n</b>\n"
1714 . "or complex, e.g. <b>3[close]wO(sw)(sw)</b></i>",
1715 8, 12, 9, 10);
1716  
1717 $self->addSimpleImage(
1718 $self->grid,
1719 $axmud::SHARE_DIR . '/icons/setup/bypass_sigil.png',
1720 undef,
1721 7, 8, 10, 11);
1722  
1723 my $checkButton8 = $self->addCheckButton(
1724 $self->grid,
1725 'Bypass commands',
1726 undef,
1727 $self->ivShow('sigilHash', 'bypass'),
1728 TRUE,
1729 8, 12, 10, 11);
1730 $self->addLabel(
1731 $self->grid,
1732 "<i>Sends a command to the world immediately,\n"
1733 . "bypassing any queued world commands.</i>",
1734 8, 12, 11, 12);
1735  
1736 # (->signal_connects from above)
1737 $button->signal_connect('clicked' => sub {
1738  
1739 if (! $noneFlag) {
1740  
1741 # 'Select all'
1742 $checkButton3->set_active(TRUE);
1743 $checkButton4->set_active(TRUE);
1744 $checkButton5->set_active(TRUE);
1745 $checkButton6->set_active(TRUE);
1746 $checkButton7->set_active(TRUE);
1747 $checkButton8->set_active(TRUE);
1748  
1749 # Next button click is 'Select none'
1750 $button->set_label('Select none');
1751 $noneFlag = TRUE;
1752  
1753 } else {
1754  
1755 # 'Select none'
1756 $checkButton3->set_active(FALSE);
1757 $checkButton4->set_active(FALSE);
1758 $checkButton5->set_active(FALSE);
1759 $checkButton6->set_active(FALSE);
1760 $checkButton7->set_active(FALSE);
1761 $checkButton8->set_active(FALSE);
1762  
1763 # Next button click is 'Select all'
1764 $button->set_label('Select all');
1765 $noneFlag = FALSE;
1766 }
1767 });
1768  
1769 @signalList = (
1770 $checkButton3 => 'echo',
1771 $checkButton4 => 'perl',
1772 $checkButton5 => 'script',
1773 $checkButton6 => 'multi',
1774 $checkButton7 => 'speed',
1775 $checkButton8 => 'bypass',
1776 );
1777  
1778 do {
1779  
1780 my ($widget, $key);
1781  
1782 $widget = shift @signalList;
1783 $key = shift @signalList;
1784  
1785 $widget->signal_connect('toggled' => sub {
1786  
1787 if (! $widget->get_active()) {
1788 $self->ivAdd('sigilHash', $key, FALSE);
1789 } else {
1790 $self->ivAdd('sigilHash', $key, TRUE);
1791 }
1792 });
1793  
1794 } until (! @signalList);
1795  
1796 return 1;
1797 }
1798  
1799 sub lastPage {
1800  
1801 # Last page - called by $self->setupGrid or ->updateGrid
1802 #
1803 # Expected arguments
1804 # (none besides $self)
1805 #
1806 # Return values
1807 # 'undef' on improper arguments
1808 # 1 otherwise
1809  
1810 my ($self, $check) = @_;
1811  
1812 # Local variables
1813 my (@verboseList, @shortList, @briefList);
1814  
1815 # Check for improper arguments
1816 if (defined $check) {
1817  
1818 return $axmud::CLIENT->writeImproper($self->_objClass . '->lastPage', @_);
1819 }
1820  
1821 $self->addLabel($self->grid, '<b>Finished (' . $self->getPageString() . ')</b>',
1822 0, 12, 0, 1);
1823 $self->addLabel(
1824 $self->grid,
1825 "<i>" . $axmud::SCRIPT . " isn't like other MUD clients. Click the help icon at any"
1826 . " time to read about its most important features.</i>",
1827 1, 12, 1, 2);
1828  
1829 $self->addSimpleImage(
1830 $self->grid,
1831 $axmud::SHARE_DIR . '/icons/setup/help.png',
1832 undef,
1833 1, 12, 2, 11);
1834  
1835 $self->addLabel(
1836 $self->grid,
1837 "<b>Click the Finish button to get started!</b>",
1838 1, 12, 11, 12,
1839 0.5, 0.5);
1840  
1841 return 1;
1842 }
1843  
1844 # Support functions
1845  
1846 ##################
1847 # Accessors - set
1848  
1849 ##################
1850 # Accessors - get
1851  
1852 sub shareMainWinFlag
1853 { $_[0]->{shareMainWinFlag} }
1854 sub zonemap
1855 { $_[0]->{zonemap} }
1856 sub widescreenFlag
1857 { $_[0]->{widescreenFlag} }
1858  
1859 sub slWidget
1860 { $_[0]->{slWidget} }
1861  
1862 sub taskInitHash
1863 { my $self = shift; return %{$self->{taskInitHash}}; }
1864 sub taskSettingHash
1865 { my $self = shift; return %{$self->{taskSettingHash}}; }
1866 sub sigilHash
1867 { my $self = shift; return %{$self->{sigilHash}}; }
1868 }
1869  
1870 { package Games::Axmud::WizWin::Locator;
1871  
1872 use strict;
1873 use warnings;
1874 # use diagnostics;
1875  
1876 use Glib qw(TRUE FALSE);
1877  
1878 our @ISA = qw(
1879 Games::Axmud::Generic::WizWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
1880 Games::Axmud
1881 );
1882  
1883 ##################
1884 # Constructors
1885  
1886 sub new {
1887  
1888 # Called by GA::Generic::Win->createFreeWin
1889 # Creates a new instance of the Locator 'wiz' window, which assists with setting up world
1890 # profile IVs used mostly by the Locator task
1891 #
1892 # Expected arguments
1893 # $number - Unique number for this window object
1894 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
1895 # should be created
1896 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
1897 # 'free' window object. When this window opens/closes, the owner is
1898 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
1899 # functions
1900 #
1901 # Optional arguments
1902 # $session - The GA::Session from which this function was called. 'undef' if the
1903 # calling function didn't specify a session and $owner's ->session IV
1904 # is also 'undef'
1905 # $title - A string to use as the window title. If 'undef', a generic title is
1906 # used
1907 # $editObj - Ignored if set
1908 # $tempFlag - Ignored if set
1909 # %configHash - Hash containing any number of key-value pairs needed for this
1910 # particular 'wiz' window; for example, for example,
1911 # GA::PrefWin::TaskStart uses it to specify a task name and type.
1912 # Set to an empty hash if not required
1913 # - This type of window object recognises these initialisation settings:
1914 #
1915 # ...
1916 #
1917 # Return values
1918 # 'undef' on improper arguments
1919 # Blessed reference to the newly-created object on success
1920  
1921 my (
1922 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
1923 %configHash,
1924 ) = @_;
1925  
1926 # Check for improper arguments
1927 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
1928  
1929 return $axmud::CLIENT->writeImproper($class . '->new', @_);
1930 }
1931  
1932 # Set the values to use for some standard window IVs
1933 if (! $title) {
1934  
1935 $title = 'Locator wizard';
1936 }
1937  
1938 # Setup
1939 my $self = {
1940 _objName => 'wiz_win_' . $number,
1941 _objClass => $class,
1942 _parentFile => undef, # No parent file object
1943 _parentWorld => undef, # No parent file object
1944 _privFlag => TRUE, # All IVs are private
1945  
1946 # Standard window object IVs
1947 # --------------------------
1948  
1949 # Unique number for this window object
1950 number => $number,
1951 # The window category - 'grid' or 'free'
1952 winCategory => 'free',
1953 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
1954 winType => 'wiz',
1955 # A name for the window (for 'config' windows, the same as the window type)
1956 winName => 'locator_wiz',
1957 # The GA::Obj::Workspace object for the workspace in which this window is created
1958 workspaceObj => $workspaceObj,
1959 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
1960 # object. When this window opens/closes, the owner is informed via calls to its
1961 # ->add_childFreeWin / ->del_childFreeWin functions
1962 owner => $owner,
1963 # The GA::Session from which this function was called. 'undef' if the calling function
1964 # didn't specify a session and $owner's ->session IV is also 'undef'
1965 session => $session,
1966 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
1967 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
1968 # displayed in a 'dialogue' window)
1969 pseudoCmdMode => 'win_error',
1970  
1971 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
1972 # parent 'main' window's Gtk3::Window
1973 # The code should use this IV when it wants to do something to the window itself
1974 # (minimise it, make it active, etc)
1975 winWidget => undef,
1976 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
1977 # the parent GA::Table::PseudoWin table object
1978 # The code should use this IV when it wants to add, modify or remove widgets inside the
1979 # window itself
1980 winBox => undef,
1981 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
1982 # FALSE if not
1983 enabledFlag => FALSE,
1984 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
1985 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
1986 visibleFlag => TRUE,
1987 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
1988 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
1989 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
1990 childFreeWinHash => {},
1991 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
1992 # window is informed via a call to $self->del_childFreeWin
1993 # When the child is destroyed, this window might want to call some of its own functions
1994 # to update various widgets and/or IVs, in which case this window adds an entry to
1995 # this hash; a hash in the form
1996 # $childDestroyHash{unique_number} = list_reference
1997 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
1998 # reference to a list in groups of 2, in the form
1999 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
2000 childDestroyHash => {},
2001  
2002 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
2003 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
2004 # area)
2005 packingBox => undef, # Gtk3::VBox
2006  
2007 # Standard IVs for 'free' windows
2008  
2009 # The window's default size, in pixels
2010 widthPixels => $axmud::CLIENT->customFreeWinWidth,
2011 heightPixels => $axmud::CLIENT->customFreeWinHeight,
2012 # Default border/item spacing sizes used in the window, in pixels
2013 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
2014 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
2015  
2016 # A string to use as the window title. If 'undef', a generic title is used
2017 title => $title,
2018 # Hash containing any number of key-value pairs needed for this particular 'config'
2019 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
2020 # name and type. Set to an empty hash if not required
2021 configHash => {%configHash},
2022  
2023 # Standard IVs for 'wiz' windows
2024  
2025 # Widgets
2026  
2027 # A vertical pane, with the main area above, and a button strip below
2028 scroller => undef, # Gtk3::ScrolledWindow
2029 hAdjustment => undef, # Gtk3::Adjustment
2030 vAdjustment => undef, # Gtk3::Adjustment
2031 grid => undef, # Gtk3::Grid
2032 hBox => undef, # Gtk3::HBox
2033 nextButton => undef, # Gtk3::Button
2034 previousButton => undef, # Gtk3::Button
2035 cancelButton => undef, # Gtk3::Button
2036  
2037 # Three flags that can be set by any page, to prevent one of three buttons from being
2038 # made sensitive (temporarily)
2039 disableNextButtonFlag => FALSE,
2040 disablePreviousButtonFlag => FALSE,
2041 disableCancelButtonFlag => FALSE,
2042  
2043 # The names of pages, in order of appearance
2044 pageList => [
2045 'intro', # Corresponds to function $self->introPage
2046 'directions',
2047 'dictionary',
2048 'statements',
2049 'capture',
2050 'analysis',
2051 'analysis2',
2052 'last',
2053 ],
2054 # The number of the current page (first page is 0)
2055 currentPage => 0,
2056  
2057 # Two hashes for using the 'Next' / 'Previous' buttons to skip around the pages, rather
2058 # than going to the actual next or previous page (as normal)
2059 # The current page should add an entry to the hash, if necessary; the entry is removed
2060 # by ->buttonPrevious or ->buttonNext as soon as either button is clicked
2061 # Hashes in the form
2062 # $hash{current_page_number} = page_number_if_button_clicked
2063 # NB The first page's number is 0, so the fourth page will be page 3, not page 4
2064 specialNextButtonHash => {},
2065 specialPreviousButtonHash => {},
2066  
2067 # IVs for this type of 'wiz' window
2068  
2069 # A hash of custom primary directions, in the form
2070 # $hash{standard_primary_direction} = custom_primary_direction
2071 customPrimaryDirHash => {}, # Set below
2072 # A hash of custom abbreviated primary directions, in the form
2073 # $hash{standard_primary_direction} = custom_primary_abbreviated_direction
2074 customPrimaryAbbrevHash => {}, # Set below
2075 # NB For both these hashes, if the user empties an entry box, the value is set to
2076 # 'undef' - in that case, the value stored in the current dictionary isn't changed
2077  
2078 # Lists of definite/indefinite articles, to be stored in the current dictionary
2079 # (replacing the contents of the same IVs)
2080 definiteList => [],
2081 indefiniteList => [],
2082 # List of words for 'and'/'or', to be stored in the current dictionary (replacing the
2083 # contents of the same IVs)
2084 andList => [],
2085 orList => [],
2086 # A list of numbers from 1-10, which replaces key-value pairs in the current
2087 # dictionary's ->numberHash
2088 numberList => [],
2089 # A list of contents markers initially imported from
2090 # GA::Profile::World->contentPatternList
2091 markerList => [],
2092  
2093 # Hash to show which of the IVs above have been changed by the user, in the form
2094 # $hash{iv} = flag
2095 # where 'flag' is TRUE if the IV has been changed, FALSE if not
2096 # $self->updateTextView modifies the hash for a number of IVs, but only the 7 IVs above
2097 # are checked at the end of the setup process
2098 ivChangeHash => {},
2099  
2100 # Hash of room statement component types. Includes components specified by
2101 # GA::Profile::World, as well as one components used by this 'wiz' window only:
2102 # 'outside_statement'. Hash in the form
2103 # $hash{component_type} = short_description
2104 componentTypeHash => {
2105 # Component used by this window only
2106 'outside_statement' => 'Line outside the statement',
2107 # Components specified by GA::Profile::World
2108 # 'anchor' => 'Line is the anchor line', # Not required here
2109 'ignore_line' => 'Ignore this line',
2110 'verb_title' => 'Room title (verbose)',
2111 'verb_descrip' => 'Description (verbose)',
2112 'verb_exit' => 'Exit list (verbose)',
2113 'verb_content' => 'Contents list (verbose)',
2114 'verb_special' => 'Special contents list',
2115 'brief_title' => 'Room title (brief)',
2116 'brief_exit' => 'Exit list (brief)',
2117 'brief_title_exit' => 'Room title/exit list (brief)',
2118 'brief_exit_title' => 'Exit list/room title (brief)',
2119 'brief_content' => 'Contents list (brief)',
2120 # 'mudlib_path' => 'Path to the mudlib file' # Not required here
2121 # 'custom' => 'Custom component', # Not required here
2122 },
2123 # A list of verbose room statement components - a selection of the keys in
2124 # $self->componentTypeHash
2125 verboseComponentList => [
2126 'outside_statement',
2127 'ignore_line',
2128 'verb_title',
2129 'verb_descrip',
2130 'verb_special',
2131 'verb_exit',
2132 'verb_content',
2133 ],
2134 # A list of short verbose room statement components - a selection of the keys in
2135 # $self->componentTypeHash
2136 shortComponentList => [
2137 'outside_statement',
2138 'ignore_line',
2139 'verb_title',
2140 'verb_special',
2141 'verb_exit',
2142 'verb_content',
2143 ],
2144 # A list of brief room statement components - a selection of the keys in
2145 # $self->componentTypeHash
2146 briefComponentList => [
2147 'outside_statement',
2148 'ignore_line',
2149 'brief_title',
2150 'brief_exit',
2151 'brief_title_exit',
2152 'brief_exit_title',
2153 'brief_content',
2154 ],
2155  
2156 # A list of consecutive GA::Buffer::Display objects for analysis
2157 bufferObjList => [],
2158 # A corresponding list specifying to which type of component each buffer object in
2159 # $self->bufferObjList belongs (matches keys in $self->componentTypeHash)
2160 bufferTypeList => [],
2161  
2162 # How many analyses have been completed
2163 analysisCount => 0,
2164 # The current analysis is of which type? ('verbose', 'short' or 'brief')
2165 analysisType => 'verbose',
2166 # How many recently-received lines to analyse, by default
2167 analysisLength => 9,
2168 # The minimum and maximum number of recently-received lines to analyse (the maximum
2169 # length of a GA::Obj::Component is 256 lines)
2170 analysisMinLength => 6,
2171 analysisMaxLength => 256,
2172 # How many lines to increase/decrease this number at a time
2173 analysisInc => 3,
2174 # A hash containing an analysis of ->bufferObjList, compiled by
2175 # $self->collectComponentGroups, in the form
2176 # $hash{component_name} = reference_to_list_of_lines
2177 # ...where 'reference_to_list_of_lines' contains a list of indexes in ->bufferObjList
2178 # in the range 0 to ($self->analysisLength - 1)
2179 analysisHash => {},
2180  
2181 # After an analysis is complete, the list of new GA::Obj::Component objects created
2182 # (the IV used depends on the current value of $self->analysisType)
2183 verboseComponentObjList => [],
2184 shortComponentObjList => [],
2185 briefComponentObjList => [],
2186  
2187 # IVs which are set by various pages, which are transferred directly to the current
2188 # world profile when the setup process is complete. A hash in the form
2189 # $profUpdateHash{iv} = scalar
2190 # $profUpdateHash{iv} = list_reference
2191 profUpdateHash => {},
2192  
2193 # A list of exit names ('north', 'up', etc) extracted from the 'verb_exit' component
2194 # during the analysis
2195 analysisExitList => [],
2196 # Some values extracted from the 'brief_title_exit' and 'brief_exit_title' components,
2197 # stored by $self->analyseComponent and retrieved by $self->analysisPage
2198 tempStartText => undef,
2199 tempStopText => undef,
2200 tempDelimList => [],
2201  
2202 # The languages set by buttons in the first two pages, matching the ->name IV of a
2203 # phrasebook object (Games::Axmud::Obj::Phrasebook)
2204 # Set to 'undef' if no language button was used, or if the 'reset' button is clicked
2205 dirPageLang => undef,
2206 dictPageLang => undef,
2207 # When directions are displayed by $self->directionsPage, the directions don't appear in
2208 # the same order they appear in a phrasebook object (Games::Axmud::Obj::Phrasebook).
2209 # This hash converts indexes in a phrasebook object's ->primaryDirList and
2210 # ->primaryAbbrevDirList into an entry box number
2211 indexConvertHash => {
2212 0 => 0, # n / n
2213 1 => 10, # nne / ne
2214 2 => 1, # ne / e
2215 3 => 11, # ene / se
2216 4 => 2, # e / s
2217 5 => 12, # ese / sw
2218 6 => 3, # se / w
2219 7 => 13, # sse / nw
2220 8 => 4, # s / u
2221 9 => 14, # ssw / d
2222 10 => 5, # sw / nne
2223 11 => 15, # wsw / ene
2224 12 => 6, # w / ese
2225 13 => 16, # wnw / sse
2226 14 => 7, # nw / ssw
2227 15 => 17, # nnw / wsw
2228 16 => 8, # u / wnw
2229 17 => 9, # d / nnw
2230 },
2231 };
2232  
2233 # Bless the object into existence
2234 bless $self, $class;
2235  
2236 # Set up the direction IVs using the current dictionary
2237 $self->resetDirs();
2238 # Set the other word/phrase IVs using the current dictonary
2239 $self->resetOtherWords();
2240 # Set the initial list of contents markers
2241 $self->ivPoke('markerList', $self->session->currentWorld->contentPatternList);
2242  
2243 return $self;
2244 }
2245  
2246 ##################
2247 # Methods
2248  
2249 # Standard window object functions
2250  
2251 # sub winSetup {} # Inherited from GA::Generic::FreeWin
2252  
2253 # sub winEnable {} # Inherited from GA::Generic::WizWin
2254  
2255 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
2256  
2257 # sub winDestroy {} # Inherited from GA::Generic::WizWin
2258  
2259 # sub winShowAll {} # Inherited from GA::Generic::Win
2260  
2261 # sub drawWidgets {} # Inherited from GA::Generic::WizWin
2262  
2263 # sub redrawWidgets {} # Inherited from GA::Generic::Win
2264  
2265 # ->signal_connects
2266  
2267 # Other functions
2268  
2269 sub saveChanges {
2270  
2271 # Called by $self->buttonNext when the user clicks the 'Finish' button
2272 # Saves changes to the current world profile and/or current dictionary, before closing the
2273 # window
2274 #
2275 # Expected arguments
2276 # (none besides $self)
2277 #
2278 # Return values
2279 # 'undef' on improper arguments
2280 # 1 otherwise
2281  
2282 my ($self, $check) = @_;
2283  
2284 # Local variables
2285 my (
2286 $profObj, $dictObj, $declineString, $choice, $string, $pbObjDir, $pbObjDict, $dictFlag,
2287 @numberList, @comboList,
2288 %primaryHash, %abbrevHash,
2289 );
2290  
2291 # Check for improper arguments
2292 if (defined $check) {
2293  
2294 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
2295 }
2296  
2297 # Save changes to the current world profile
2298 $profObj = $self->session->currentWorld;
2299  
2300 # Component lists
2301 if ($self->verboseComponentObjList) {
2302  
2303 $profObj->ivEmpty('verboseComponentList');
2304  
2305 foreach my $componentObj ($self->verboseComponentObjList) {
2306  
2307 # Add the component object itself to the profile
2308 $profObj->ivAdd('componentHash', $componentObj->name, $componentObj);
2309  
2310 # For 'verb_content' and 'brief_content' components, the marker patterns stored in
2311 # GA::Profile::World->contentPatternList must also be added to the component
2312 # itself
2313 $self->updateContentComponent($componentObj);
2314  
2315 # The special 'anchor' component must be inserted before the component which
2316 # contains exits (which acts as our anchor line)
2317 $self->insertAnchor($profObj, 'verboseComponentList', $componentObj->type);
2318 $profObj->ivPush('verboseComponentList', $componentObj->name);
2319 }
2320 }
2321  
2322 if ($self->shortComponentObjList) {
2323  
2324 $profObj->ivEmpty('shortComponentList');
2325  
2326 foreach my $componentObj ($self->shortComponentObjList) {
2327  
2328 $profObj->ivAdd('componentHash', $componentObj->name, $componentObj);
2329  
2330 $self->insertAnchor($profObj, 'shortComponentList', $componentObj->type);
2331 $profObj->ivPush('shortComponentList', $componentObj->name);
2332 }
2333 }
2334  
2335 if ($self->briefComponentObjList) {
2336  
2337 $profObj->ivEmpty('briefComponentList');
2338  
2339 foreach my $componentObj ($self->briefComponentObjList) {
2340  
2341 $profObj->ivAdd('componentHash', $componentObj->name, $componentObj);
2342  
2343 $self->insertAnchor($profObj, 'briefComponentList', $componentObj->type);
2344 $profObj->ivPush('briefComponentList', $componentObj->name);
2345 }
2346 }
2347  
2348 # IVs stored in $self->profUpdateHash
2349 foreach my $key ($self->ivKeys('profUpdateHash')) {
2350  
2351 my (
2352 $value,
2353 @list,
2354 );
2355  
2356 $value = $self->ivShow('profUpdateHash', $key);
2357  
2358 # For list IVs, $value is a reference to a list. De-reference it
2359 if (substr($key, -4) eq 'List') {
2360  
2361 @list = @$value;
2362 }
2363  
2364 # Set scalar IVs
2365 if (
2366 $key eq 'verboseAnchorOffset' || $key eq 'shortAnchorOffset'
2367 || $key eq 'briefAnchorOffset'
2368 ) {
2369 $profObj->ivPoke($key, $value);
2370  
2371 # Replace some list IVs...
2372 } elsif ($key eq 'verboseExitDelimiterList' || $key eq 'briefExitDelimiterList') {
2373  
2374 $profObj->ivPoke($key, @list);
2375  
2376 # ...update other list IVs, adding new values to old ones (but not adding duplicates)
2377 } elsif (
2378 $key eq 'verboseAnchorPatternList' || $key eq 'shortAnchorPatternList'
2379 || $key eq 'briefAnchorPatternList' || $key eq 'verboseExitLeftMarkerList'
2380 || $key eq 'verboseExitRightMarkerList' || $key eq 'briefExitLeftMarkerList'
2381 || $key eq 'briefExitRightMarkerList'
2382 ) {
2383 $self->updateProfileList($profObj, $key, @list);
2384 }
2385 }
2386  
2387 # IVs stored in $self->markerList (replace the current contents of the world profile's IV
2388 if ($self->markerList) {
2389  
2390 $profObj->ivPoke('contentPatternList', $self->markerList);
2391 }
2392  
2393 # Check the world profile's ->verboseExitNonDelimiterList, and remove any items that have
2394 # been added to ->verboseExitDelimiterList
2395 $self->checkDelimiters($profObj, 'verboseExitDelimiterList', 'verboseExitNonDelimiterList');
2396 # Check the world profile's ->briefExitNonDelimiterList, and remove any items that have been
2397 # added to ->briefExitDelimiterList
2398 $self->checkDelimiters($profObj, 'briefExitDelimiterList', 'briefExitNonDelimiterList');
2399  
2400 # Save changes to the current dictionary
2401 $dictObj = $self->session->currentDict;
2402 # Import lists/hashes for simplicity
2403 %primaryHash = $self->customPrimaryDirHash;
2404 %abbrevHash = $self->customPrimaryAbbrevHash;
2405 @numberList = $self->numberList;
2406  
2407 foreach my $standardDir (keys %primaryHash) {
2408  
2409 # If the value in the key-value pair is defined, the user has changed it
2410 if (defined $primaryHash{$standardDir}) {
2411  
2412 $dictObj->ivAdd('primaryDirHash', $standardDir, $primaryHash{$standardDir});
2413 $dictFlag = TRUE;
2414 }
2415 }
2416  
2417 foreach my $standardDir (keys %abbrevHash) {
2418  
2419 if (defined $abbrevHash{$standardDir}) {
2420  
2421 $dictObj->ivAdd('primaryAbbrevHash', $standardDir, $abbrevHash{$standardDir});
2422 $dictFlag = TRUE;
2423 }
2424 }
2425  
2426 if ($dictFlag) {
2427  
2428 # Update the dictionary's ->primaryOppHash and ->primaryOppAbbrevHash IVs
2429 $dictObj->updateOppDirHash();
2430 }
2431  
2432 if ($self->ivShow('ivChangeHash', 'definiteList')) {
2433  
2434 $dictObj->ivPoke('definiteList', $self->definiteList);
2435 }
2436  
2437 if ($self->ivShow('ivChangeHash', 'indefiniteList')) {
2438  
2439 $dictObj->ivPoke('indefiniteList', $self->indefiniteList);
2440 }
2441  
2442 if ($self->ivShow('ivChangeHash', 'andList')) {
2443  
2444 $dictObj->ivPoke('andList', $self->andList);
2445 }
2446  
2447 if ($self->ivShow('ivChangeHash', 'orList')) {
2448  
2449 $dictObj->ivPoke('orList', $self->orList);
2450 }
2451  
2452 if ($self->ivShow('ivChangeHash', 'numberList')) {
2453  
2454 if (@numberList && (scalar @numberList) == 10) {
2455  
2456 for (my $num = 1; $num <= 10; $num++) {
2457  
2458 $dictObj->ivAdd(
2459 'numberHash',
2460 shift @numberList,
2461 $num,
2462 );
2463 }
2464 }
2465 }
2466  
2467 # If the user clicked one of the language buttons in either of the first two windows, ask
2468 # them if they'd like to set the dictionary's language
2469 # $self->dirPageLang and ->dictPageLang, if set, are the names of the equivalent phrasebook
2470 # objects
2471 if ($self->dirPageLang) {
2472  
2473 $pbObjDir = $axmud::CLIENT->ivShow('constPhrasebookHash', $self->dirPageLang);
2474 }
2475  
2476 if ($self->dictPageLang) {
2477  
2478 $pbObjDict = $axmud::CLIENT->ivShow('constPhrasebookHash', $self->dirPageLang);
2479 }
2480  
2481 if ($pbObjDir && $pbObjDict && $pbObjDir->name ne $pbObjDict->name) {
2482  
2483 # Open a 'dialogue' window with a combobox, so the user can choose between the languages
2484 $declineString = 'Don\'t change the language';
2485  
2486 # @comboList should only contain languages that aren't the current dictionary's language
2487 push (@comboList, $declineString);
2488  
2489 if ($pbObjDir->targetName ne $dictObj->language) {
2490  
2491 push (@comboList, $pbObjDir->targetName);
2492 }
2493  
2494 if ($pbObjDict->targetName ne $dictObj->language) {
2495  
2496 push (@comboList, $pbObjDict->targetName);
2497 }
2498  
2499 # Prompt the user
2500 $choice = $self->showComboDialogue(
2501 'Change dictionary language',
2502 'Do you want to change the current dictionary\'s language?',
2503 \@comboList,
2504 );
2505  
2506 if ($choice && $choice ne $declineString) {
2507  
2508 $dictObj->ivPoke('language', $choice);
2509 # Also set the dictionary's noun-adjective word order, while we're at it
2510 if ($pbObjDir->targetName eq $choice) {
2511 $dictObj->ivPoke('nounPosn', $pbObjDir->nounPosn);
2512 } else {
2513 $dictObj->ivPoke('nounPosn', $pbObjDict->nounPosn);
2514 }
2515 }
2516  
2517 } elsif ($pbObjDir || $pbObjDict) {
2518  
2519 # Open a 'dialogue' window with yes/no buttons, so the user can choose a language
2520 if ($pbObjDir) {
2521 $string = $pbObjDir->targetName;
2522 } else {
2523 $string = $pbObjDict->targetName;
2524 }
2525  
2526 $choice = $self->showMsgDialogue(
2527 'Change dictionary language',
2528 'question',
2529 'Do you want to change the current dictionary\'s language to \'' . $string . '\'?',
2530 'yes-no',
2531 );
2532  
2533 if ($choice && $choice eq 'yes') {
2534  
2535 $dictObj->ivPoke('language', $string);
2536 if ($pbObjDir->targetName eq $choice) {
2537 $dictObj->ivPoke('nounPosn', $pbObjDir->nounPosn);
2538 } else {
2539 $dictObj->ivPoke('nounPosn', $pbObjDict->nounPosn);
2540 }
2541 }
2542 }
2543  
2544 # All changes made. Reset the Locator task, if it's open, which will hopefully work now;
2545 # then close the window
2546 if ($self->session->locatorTask) {
2547  
2548 $self->session->pseudoCmd('resetlocatortask', $self->pseudoCmdMode);
2549 }
2550  
2551 $self->winDestroy();
2552  
2553 return 1;
2554 }
2555  
2556 # Window pages
2557  
2558 sub introPage {
2559  
2560 # Intro page - called by $self->setupGrid or ->updateGrid
2561 #
2562 # Expected arguments
2563 # (none besides $self)
2564 #
2565 # Return values
2566 # 'undef' on improper arguments
2567 # 1 otherwise
2568  
2569 my ($self, $check) = @_;
2570  
2571 # Local variables
2572 my @list;
2573  
2574 # Check for improper arguments
2575 if (defined $check) {
2576  
2577 return $axmud::CLIENT->writeImproper($self->_objClass . '->introPage', @_);
2578 }
2579  
2580 # Intro
2581 $self->addLabel($self->grid, '<b>Locator wizard (' . $self->getPageString() . ')</b>',
2582 0, 12, 0, 1);
2583  
2584 my $image = $self->addSimpleImage(
2585 $self->grid,
2586 $axmud::SHARE_DIR . '/icons/system/mapper_medium.png',
2587 undef,
2588 1, 6, 3, 10);
2589  
2590 $self->addLabel(
2591 $self->grid,
2592 "This wizard teaches the current world profile and the\ncurrent dictionary how to read"
2593 . " room statements (also\ncalled \'room descriptions\') in the game world.",
2594 7, 12, 3, 4);
2595  
2596 $self->addLabel(
2597 $self->grid,
2598 "The Locator task and the Automapper window <b>won\'t work\nat all</b> until the wizard"
2599 . " has finished (unless you are using a\npre-configured world).",
2600 7, 12, 5, 6);
2601  
2602 $self->addLabel(
2603 $self->grid,
2604 "Use the <b>Next</b> and <b>Previous</b> buttons to navigate between\npages.",
2605 7, 12, 7, 8);
2606  
2607 $self->addLabel(
2608 $self->grid,
2609 "(You can also configure world profiles and dictionaries\nby using their 'edit'"
2610 . " windows.)",
2611 7, 12, 9, 10);
2612  
2613 # Add a few empty labels to get the spacing right
2614 @list = (1, 2, 10, 11);
2615 foreach my $row (@list) {
2616  
2617 $self->addLabel($self->grid, '',
2618 1, 12, $row, ($row + 1));
2619 }
2620  
2621 return 1;
2622 }
2623  
2624 sub directionsPage {
2625  
2626 # Directions page - called by $self->setupGrid or ->updateGrid
2627 #
2628 # Expected arguments
2629 # (none besides $self)
2630 #
2631 # Return values
2632 # 'undef' on improper arguments
2633 # 1 otherwise
2634  
2635 my ($self, $check) = @_;
2636  
2637 # Local variables
2638 my (
2639 $row,
2640 @phrasebookList, @entryList, @entryAbbrevList, @dirList,
2641 );
2642  
2643 # Check for improper arguments
2644 if (defined $check) {
2645  
2646 return $axmud::CLIENT->writeImproper($self->_objClass . '->directionsPage', @_);
2647 }
2648  
2649 # Get a sorted list of phrasebook objects
2650 @phrasebookList = sort {$a->targetName cmp $b->targetName}
2651 ($axmud::CLIENT->ivValues('constPhrasebookHash'));
2652  
2653 # Primary directions
2654 $self->addLabel($self->grid, '<b>Primary directions (' . $self->getPageString() . ')</b>',
2655 0, 12, 0, 1);
2656  
2657 $self->addLabel(
2658 $self->grid,
2659 $axmud::SCRIPT . "\'s primary directions are the eight usual cardinal directions"
2660 . " (\'north\', \'east\', \'southwest\'\nand so on), the eight lesser-used cardinal"
2661 . " directions (\'eastnortheast\', \'southsouthwest\' and\nso on) plus the directions"
2662 . " \'up\' and \'down\'.",
2663 1, 12, 1, 2);
2664 $self->addLabel(
2665 $self->grid,
2666 "The Automapper window draws all exits as one of these primary directions. An exit"
2667 . " called\n\'north\' is always drawn pointing towards the top of the map,"
2668 . " but you can choose how exits\ncalled \'enter\', \'out\' and \'portal\' are drawn.",
2669 1, 12, 2, 3);
2670 $self->addLabel(
2671 $self->grid,
2672 "If the world\'s language is not English, or if it uses a different set of primary"
2673 . " directions, you\ncan set them below. Otherwise, just click the <b>Next</b> button.",
2674 1, 12, 3, 4);
2675  
2676 # Column titles, used twice so that 'northnortheast' (etc) appear towards the bottom
2677 $self->addLabel($self->grid, '<u>Primary direction</u>',
2678 1, 3, 4, 5);
2679 $self->addLabel($self->grid, '<u>Custom primary direction</u>',
2680 3, 6, 4, 5);
2681 $self->addLabel($self->grid, '<u>Custom abbreviation</u>',
2682 6, 9, 4, 5);
2683 $self->addLabel($self->grid, '<u>Primary direction</u>',
2684 1, 3, 15, 16);
2685 $self->addLabel($self->grid, '<u>Custom primary direction</u>',
2686 3, 6, 15, 16);
2687 $self->addLabel($self->grid, '<u>Custom abbreviation</u>',
2688 6, 9, 15, 16);
2689  
2690 # Entry boxes for each custom direction. Compose a list of directions, using the usual
2691 # eight cardinal directions first, then up/down, then the rarer cardinal directions
2692 @dirList = $axmud::CLIENT->constShortPrimaryDirList;
2693 foreach my $dir ($axmud::CLIENT->constPrimaryDirList) {
2694  
2695 if (! $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $dir)) {
2696  
2697 push (@dirList, $dir);
2698 }
2699 }
2700  
2701 $row = 4;
2702 foreach my $standardDir (@dirList) {
2703  
2704 $row++;
2705 # Leave a gap between up/down and the rarer cardinal directions
2706 if ($standardDir eq 'northnortheast') {
2707  
2708 $row++;
2709 }
2710  
2711 $self->addLabel($self->grid, $standardDir,
2712 1, 3, $row, ($row + 1));
2713  
2714 my $entry = $self->addEntry(
2715 $self->grid,
2716 undef,
2717 $self->ivShow('customPrimaryDirHash', $standardDir),
2718 TRUE,
2719 3, 6, $row, ($row + 1));
2720 $entry->signal_connect('changed' => sub {
2721  
2722 my $text = $entry->get_text();
2723  
2724 if ($text) {
2725  
2726 $self->ivAdd('customPrimaryDirHash', $standardDir, $text);
2727  
2728 } else {
2729  
2730 # Don't overwrite the current dictionary's stored direction
2731 $self->ivAdd('customPrimaryDirHash', $standardDir, undef);
2732 }
2733  
2734 # Mark the IV as having been changed
2735 $self->ivAdd('ivChangeHash', 'customPrimaryDirHash', TRUE);
2736 });
2737 push (@entryList, $entry);
2738  
2739 my $entry2 = $self->addEntry(
2740 $self->grid,
2741 undef,
2742 $self->ivShow('customPrimaryAbbrevHash', $standardDir),
2743 TRUE,
2744 6, 9, $row, ($row + 1),
2745 8); # Restrict entry box width
2746 $entry2->signal_connect('changed' => sub {
2747  
2748 my $text = $entry2->get_text();
2749  
2750 if ($text) {
2751  
2752 $self->ivAdd('customPrimaryAbbrevHash', $standardDir, $text);
2753  
2754 } else {
2755  
2756 # Don't overwrite the current dictionary's stored direction
2757 $self->ivAdd('customPrimaryAbbrevHash', $standardDir, undef);
2758 }
2759  
2760 # Mark the IV as having been changed
2761 $self->ivAdd('ivChangeHash', 'customPrimaryAbbrevHash', TRUE);
2762 });
2763 push (@entryAbbrevList, $entry2);
2764 }
2765  
2766 # Reset directions button
2767 my $button = $self->addButton(
2768 $self->grid,
2769 undef,
2770 'Reset directions', 'Reset the lists of primary directions',
2771 9, 12, 4, 5);
2772 # ->signal_connect appears further down...
2773  
2774 $row = 4;
2775 foreach my $pbObj (@phrasebookList) {
2776  
2777 $row++;
2778  
2779 my $button2 = $self->addButton(
2780 $self->grid,
2781 undef,
2782 $pbObj->targetName,
2783 'Use ' . ucfirst($pbObj->name) . ' language directions',
2784 9, 12, $row, ($row + 1));
2785  
2786 $button2->signal_connect('clicked' => sub {
2787  
2788 $self->ivPoke('dirPageLang', $pbObj->name);
2789  
2790 for (my $count = 0; $count < 18; $count++) {
2791  
2792 my $index = $self->ivShow('indexConvertHash', $count);
2793  
2794 # Update the entry boxes, which automatically updates stored IVs
2795 $entryList[$index]->set_text($pbObj->ivIndex('primaryDirList', $count));
2796 $entryAbbrevList[$index]->set_text(
2797 $pbObj->ivIndex('primaryAbbrevDirList', $count),
2798 );
2799 }
2800 });
2801 }
2802  
2803 # ->signal_connect for the 'reset' button
2804 $button->signal_connect('clicked' => sub {
2805  
2806 my $index;
2807  
2808 # Reset the IVs ->customPrimaryDirHash and ->customPrimaryAbbrevHash
2809 $self->resetDirs();
2810  
2811 # Reset the language
2812 $self->ivUndef('dirPageLang');
2813  
2814 # There are eighteen (standard) primary directions
2815 $index = -1;
2816 foreach my $standardDir (@dirList) {
2817  
2818 $index++;
2819  
2820 # Update the entry boxes, which automatically updates stored IVs
2821 if (defined $self->ivShow('customPrimaryDirHash', $standardDir)) {
2822  
2823 $entryList[$index]->set_text(
2824 $self->ivShow('customPrimaryDirHash', $standardDir),
2825 );
2826 }
2827  
2828 if (defined $self->ivShow('customPrimaryAbbrevHash', $standardDir)) {
2829  
2830 $entryAbbrevList[$index]->set_text(
2831 $self->ivShow('customPrimaryAbbrevHash', $standardDir),
2832 );
2833 }
2834 }
2835  
2836 # Mark the IVs as not having been changed
2837 $self->ivAdd('ivChangeHash', 'customPrimaryDirHash', FALSE);
2838 $self->ivAdd('ivChangeHash', 'customPrimaryAbbrevHash', FALSE);
2839 });
2840  
2841 return 1;
2842 }
2843  
2844 sub dictionaryPage {
2845  
2846 # Dictionary page - called by $self->setupGrid or ->updateGrid
2847 #
2848 # Expected arguments
2849 # (none besides $self)
2850 #
2851 # Return values
2852 # 'undef' on improper arguments
2853 # 1 otherwise
2854  
2855 my ($self, $check) = @_;
2856  
2857 # Local variables
2858 my (
2859 $row,
2860 @phrasebookList,
2861 );
2862  
2863 # Check for improper arguments
2864 if (defined $check) {
2865  
2866 return $axmud::CLIENT->writeImproper($self->_objClass . '->dictionaryPage', @_);
2867 }
2868  
2869 # Get a sorted list of phrasebook objects
2870 @phrasebookList = sort {$a->targetName cmp $b->targetName}
2871 ($axmud::CLIENT->ivValues('constPhrasebookHash'));
2872  
2873 # Dictionary words
2874 $self->addLabel($self->grid, '<b>Dictionary words (' . $self->getPageString() . ')</b>',
2875 0, 12, 0, 1);
2876 $self->addLabel(
2877 $self->grid,
2878 "In order to work out what\'s in the current room, " . $axmud::SCRIPT
2879 . " tries to analyse lines like these:",
2880 1, 12, 1, 2);
2881 $self->addLabel(
2882 $self->grid,
2883 '<i>Three orcs, two lamps and a giraffe are here.</i>',
2884 2, 12, 2, 3);
2885 $self->addLabel(
2886 $self->grid,
2887 "Many worlds use the exact words \'five\', \'the\' and \'or\', but if this world"
2888 . " uses another set of\nwords, you can enter them below. Otherwise, just click the"
2889 . " <b>Next</b> button.",
2890 1, 12, 3, 4);
2891 $self->addLabel(
2892 $self->grid,
2893 "<b>Hint:</b> Each box should contain one word (or phrase) per line.",
2894 1, 12, 4, 5);
2895  
2896 # First column
2897 $self->addLabel($self->grid, '<u>Articles</u>',
2898 1, 3, 5, 6);
2899 $self->addLabel($self->grid, '<i>\'the\'</i>',
2900 1, 3, 6, 7);
2901 my $textView = $self->addTextView($self->grid, undef, undef, undef, TRUE,
2902 1, 3, 7, 11);
2903 my $buffer = $textView->get_buffer();
2904 if ($self->definiteList) {
2905  
2906 $buffer->set_text(join("\n", $self->definiteList));
2907 }
2908 $self->textViewSignalConnect($buffer, 'definiteList');
2909  
2910 $self->addLabel($self->grid, '<i>\'a / an\'</i>',
2911 1, 3, 11, 12);
2912 my $textView2 = $self->addTextView($self->grid, undef, undef, undef, TRUE,
2913 1, 3, 12, 16);
2914 my $buffer2 = $textView2->get_buffer();
2915 if ($self->indefiniteList) {
2916  
2917 $buffer2->set_text(join("\n", $self->indefiniteList));
2918 }
2919 $self->textViewSignalConnect($buffer2, 'indefiniteList');
2920  
2921 # Second column
2922 $self->addLabel($self->grid, '<u>Conjunctions</u>',
2923 3, 6, 5, 6);
2924 $self->addLabel($self->grid, '<i>\'and\'</i>',
2925 3, 6, 6, 7);
2926 my $textView3 = $self->addTextView($self->grid, undef, undef, undef, TRUE,
2927 3, 6, 7, 11);
2928 my $buffer3 = $textView3->get_buffer();
2929 if ($self->andList) {
2930  
2931 $buffer3->set_text(join("\n", $self->andList));
2932 }
2933 $self->textViewSignalConnect($buffer3, 'andList');
2934  
2935 $self->addLabel($self->grid, '<i>\'or\'</i>',
2936 3, 6, 11, 12);
2937 my $textView4 = $self->addTextView($self->grid, undef, undef, undef, TRUE,
2938 3, 6, 12, 16);
2939 my $buffer4 = $textView4->get_buffer();
2940 if ($self->orList) {
2941  
2942 $buffer4->set_text(join("\n", $self->orList));
2943 }
2944 $self->textViewSignalConnect($buffer4, 'orList');
2945  
2946 # Third column
2947 $self->addLabel($self->grid, '<u>Numbers</u>',
2948 6, 9, 5, 6);
2949 $self->addLabel($self->grid, '<i>\'one\' - \'ten\'</i>',
2950 6, 9, 6, 7);
2951 my $textView5 = $self->addTextView($self->grid, undef, undef, undef, TRUE,
2952 6, 9, 7, 16);
2953 my $buffer5 = $textView5->get_buffer();
2954 if ($self->numberList) {
2955  
2956 $buffer5->set_text(join("\n", $self->numberList));
2957 }
2958 $self->textViewSignalConnect($buffer5, 'numberList');
2959  
2960 # Fourth column
2961  
2962 # Reset list button
2963 my $button = $self->addButton(
2964 $self->grid,
2965 undef,
2966 'Reset words',
2967 'Reset the lists of words and phrases',
2968 9, 12, 5, 6);
2969 # ->signal_connect appears further down...
2970  
2971 # Add one button for each language supported by this object
2972 $row = 6;
2973 foreach my $pbObj (@phrasebookList) {
2974  
2975 $row++;
2976  
2977 my $button2 = $self->addButton(
2978 $self->grid,
2979 undef,
2980 $pbObj->targetName,
2981 'Use ' . ucfirst($pbObj->name) . ' language terms',
2982 9, 12, $row, ($row + 1));
2983  
2984 $button2->signal_connect('clicked' => sub {
2985  
2986 $self->ivPoke('dictPageLang', $pbObj->name);
2987  
2988 # Update the textviews
2989 $buffer->set_text(join("\n", $pbObj->definiteList));
2990 $buffer2->set_text(join("\n", $pbObj->indefiniteList));
2991 $buffer3->set_text(join("\n", $pbObj->andList));
2992 $buffer4->set_text(join("\n", $pbObj->orList));
2993 $buffer5->set_text(join("\n", $pbObj->numberList));
2994 });
2995 }
2996  
2997 # ->signal_connect for the 'reset' button
2998 $button->signal_connect('clicked' => sub {
2999  
3000 # Reset the IVs ->definiteList, ->indefiniteList, ->andList, ->orList and ->numberList
3001 $self->resetOtherWords();
3002  
3003 # Reset the language
3004 $self->ivUndef('dictPageLang');
3005  
3006 # Update the textviews
3007 $buffer->set_text(join("\n", $self->definiteList));
3008 $buffer2->set_text(join("\n", $self->indefiniteList));
3009 $buffer3->set_text(join("\n", $self->andList));
3010 $buffer4->set_text(join("\n", $self->orList));
3011 $buffer5->set_text(join("\n", $self->numberList));
3012  
3013 # Update the hash of changed IVs
3014 $self->ivAdd('ivChangeHash', 'definiteList', FALSE);
3015 $self->ivAdd('ivChangeHash', 'indefiniteList', FALSE);
3016 $self->ivAdd('ivChangeHash', 'andList', FALSE);
3017 $self->ivAdd('ivChangeHash', 'orList', FALSE);
3018 $self->ivAdd('ivChangeHash', 'numberList', FALSE);
3019 });
3020  
3021 return 1;
3022 }
3023  
3024 sub statementsPage {
3025  
3026 # Statements page - called by $self->setupGrid or ->updateGrid
3027 #
3028 # Expected arguments
3029 # (none besides $self)
3030 #
3031 # Return values
3032 # 'undef' on improper arguments
3033 # 1 otherwise
3034  
3035 my ($self, $check) = @_;
3036  
3037 # Check for improper arguments
3038 if (defined $check) {
3039  
3040 return $axmud::CLIENT->writeImproper($self->_objClass . '->statementsPage', @_);
3041 }
3042  
3043 $self->addLabel($self->grid, '<b>Room statements (' . $self->getPageString() . ')</b>',
3044 0, 12, 0, 1);
3045 $self->addLabel(
3046 $self->grid,
3047 "In " . $axmud::SCRIPT . " terminology, a \'room statement\' is a complete description"
3048 . " of a room. Each statement\nconsists of several different components which occur"
3049 . " in a predictable order.",
3050 1, 12, 1, 2);
3051 $self->addLabel(
3052 $self->grid,
3053 $axmud::SCRIPT . " distinguishes between \'verbose\', \'short verbose\' and \'brief\'"
3054 . " statements. The components\nof a \'verbose\' room statement usually include:",
3055 1, 12, 2, 3);
3056  
3057 # Example room taken from the DeadSouls mudlib
3058 $self->addLabel($self->grid, "<b>The room title</b>",
3059 1, 4, 3, 4);
3060 $self->addLabel($self->grid, "<i>Village Road Intersection</i>",
3061 5, 12, 3, 4);
3062  
3063 $self->addLabel($self->grid, "<b>The room description</b>",
3064 1, 4, 4, 5);
3065 $self->addLabel(
3066 $self->grid,
3067 "<i>You are in the main intersection of the village. Saquivor\nroad extends north and"
3068 . " south, intersected east to west\nby a road that leads west toward a wilderness, and"
3069 . " east\ntoward shore.</i>",
3070 5, 12, 4, 5);
3071  
3072 $self->addLabel($self->grid, "<b>The special contents list</b>",
3073 1, 4, 5, 6);
3074 $self->addLabel($self->grid, "<i>There is a sign here you can read.</i>",
3075 5, 12, 5, 6);
3076  
3077 $self->addLabel($self->grid, "<b>The exit list</b>",
3078 1, 4, 6, 7);
3079 $self->addLabel($self->grid, "<i>Obvious exits: south, north, east, west</i>",
3080 5, 12, 6, 7);
3081  
3082 $self->addLabel($self->grid, "<b>The contents list</b>",
3083 1, 4, 7, 8);
3084 $self->addLabel($self->grid, "<i>A great clock tower is here.</i>",
3085 5, 12, 7, 8);
3086  
3087 $self->addLabel(
3088 $self->grid,
3089 "A \'brief\' room statement often includes the following components:",
3090 1, 12, 8, 9);
3091  
3092 # Imaginary example
3093 $self->addLabel($self->grid, "<b>Room title/exit list</b>",
3094 1, 4, 9, 10);
3095 $self->addLabel($self->grid, "<i>Main intersection [s, n, e, w]</i>",
3096 5, 12, 9, 10);
3097  
3098 $self->addLabel($self->grid, "<b>The contents list</b>",
3099 1, 4, 10, 11);
3100 $self->addLabel($self->grid, "<i>A great clock tower is here.</i>",
3101 5, 12, 10, 11);
3102  
3103 $self->addLabel(
3104 $self->grid,
3105 "Alternatively, some worlds allow you to use \'short verbose\' room statements, which"
3106 . " are usually\njust like \'verbose\' room statements, but without the room"
3107 . " description component.",
3108 1, 12, 11, 12);
3109  
3110 $self->addLabel(
3111 $self->grid,
3112 "<b>You should now type the world\'s \'look\' command (or simply move to another room)"
3113 . "\nso that a <u>whole room statement</u> is visible - when you\'re ready, click on"
3114 . " \'Next\'.</b>",
3115 1, 12, 12, 13);
3116  
3117 return 1;
3118 }
3119  
3120 sub capturePage {
3121  
3122 # Capture page - called by $self->setupGrid or ->updateGrid
3123 #
3124 # Expected arguments
3125 # (none besides $self)
3126 #
3127 # Return values
3128 # 'undef' on improper arguments
3129 # 1 otherwise
3130  
3131 my ($self, $check) = @_;
3132  
3133 # Local variables
3134 my (
3135 $row,
3136 @labelList, @entryList, @comboList,
3137 );
3138  
3139 # Check for improper arguments
3140 if (defined $check) {
3141  
3142 return $axmud::CLIENT->writeImproper($self->_objClass . '->capturePage', @_);
3143 }
3144  
3145 # Add initial labels
3146 $self->addLabel(
3147 $self->grid,
3148 '<b>Room statement capture (' . $self->getPageString() . ')</b>',
3149 0, 12, 0, 1);
3150 $self->addLabel(
3151 $self->grid,
3152 "Starting from the top, please identify the component to which every line belongs.",
3153 1, 12, 1, 2);
3154  
3155 # Add some widgets immediately below the labels
3156 my $button = $self->addButton(
3157 $self->grid,
3158 undef,
3159 'Update lines',
3160 'Use the most recently-received lines',
3161 1, 3, 2, 3);
3162 my $button2 = $self->addButton(
3163 $self->grid,
3164 undef,
3165 'More lines',
3166 'Use more lines',
3167 3, 5, 2, 3);
3168 my $button3 = $self->addButton(
3169 $self->grid,
3170 undef,
3171 'Fewer lines',
3172 'Use fewer lines',
3173 5, 7, 2, 3);
3174  
3175 my ($radioButton, $radioButton2, $radioButton3, $group);
3176 ($group, $radioButton) = $self->addRadioButton(
3177 $self->grid,
3178 undef,
3179 undef,
3180 'Verbose',
3181 FALSE,
3182 TRUE,
3183 8, 10, 2, 3);
3184 ($group, $radioButton2) = $self->addRadioButton(
3185 $self->grid,
3186 undef,
3187 $group,
3188 'Short verbose',
3189 FALSE,
3190 TRUE,
3191 10, 11, 2, 3);
3192 ($group, $radioButton3) = $self->addRadioButton(
3193 $self->grid,
3194 undef,
3195 $group,
3196 'Brief',
3197 FALSE,
3198 TRUE,
3199 11, 12, 2, 3);
3200  
3201 # ->signal_connects appear further down...
3202 if ($self->analysisType eq 'short') {
3203 $radioButton2->set_active(TRUE);
3204 } elsif ($self->analysisType eq 'brief') {
3205 $radioButton3->set_active(TRUE);
3206 }
3207  
3208 # Set the row at which the remaining widgets start to be drawn
3209 $row = 3;
3210  
3211 # Add a list of entry and comboboxes, one for each line of recently-received text
3212 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3213  
3214 # If no capture has yet been performed, set their initial values
3215 if (! $self->bufferObjList) {
3216  
3217 # No capture has yet been performed, so set their initial values
3218 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3219  
3220 } else {
3221  
3222 # Show data in the entries and comboboxes from the previous capture
3223 $self->capturePage_updateWidgets(\@entryList, \@comboList);
3224 }
3225  
3226 # Give the comboboxes their own ->signal_connect methods
3227 $self->capturePage_connectCombos(\@comboList);
3228  
3229 # Here's the ->signal_connect methods from earlier
3230 $button->signal_connect('clicked' => sub {
3231  
3232 # 'Update list' button. Reset the list of lines recently received from the world
3233 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3234 $self->capturePage_connectCombos(\@comboList);
3235 });
3236  
3237 $button2->signal_connect('clicked' => sub {
3238  
3239 # 'More lines' button. Add more lines to the number displayed, then re-draw the entries
3240 # and comboboxes.
3241 $self->ivPoke('analysisLength', $self->analysisLength + $self->analysisInc);
3242  
3243 # Prevent the user from setting more lines than the maximum by desensitising the button
3244 if (
3245 $self->analysisLength >= $self->analysisMaxLength
3246 || (
3247 $self->analysisLength > $self->analysisMinLength
3248 && $self->analysisLength >= $self->session->displayBufferCount
3249 )
3250 ) {
3251 $button2->set_sensitive(FALSE);
3252 } else {
3253 $button2->set_sensitive(TRUE);
3254 }
3255  
3256 # (The opposite button must be sensitised)
3257 $button3->set_sensitive(TRUE);
3258  
3259 # Redraw the entries and comboboxes
3260 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3261 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3262 $self->capturePage_connectCombos(\@comboList);
3263  
3264 # Make the changes visible
3265 $self->winShowAll($self->_objClass . '->capturePage');
3266 });
3267  
3268 $button3->signal_connect('clicked' => sub {
3269  
3270 # 'Fewer lines' button. Remove more lines to the number displayed, then re-draw the
3271 # entries and comboboxes.
3272 $self->ivPoke('analysisLength', $self->analysisLength - $self->analysisInc);
3273  
3274 # Prevent the user setting fewer lines than the minimum by desensitising the button
3275 if ($self->analysisLength <= $self->analysisMinLength) {
3276 $button3->set_sensitive(FALSE);
3277 } else {
3278 $button3->set_sensitive(TRUE);
3279 }
3280  
3281 # (The opposite button must be sensitised)
3282 $button2->set_sensitive(TRUE);
3283  
3284 # Redraw the entries and comboboxes
3285 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3286 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3287 $self->capturePage_connectCombos(\@comboList);
3288  
3289 # Make the changes visible
3290 $self->winShowAll($self->_objClass . '->capturePage');
3291 });
3292  
3293 $radioButton->signal_connect('toggled' => sub {
3294  
3295 if ($radioButton->get_active()) {
3296  
3297 $self->ivPoke('analysisType', 'verbose');
3298 }
3299  
3300 # Redraw the entries and comboboxes
3301 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3302 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3303 $self->capturePage_connectCombos(\@comboList);
3304  
3305 # Make the changes visible
3306 $self->winShowAll($self->_objClass . '->capturePage');
3307 });
3308  
3309 $radioButton2->signal_connect('toggled' => sub {
3310  
3311 if ($radioButton2->get_active()) {
3312  
3313 $self->ivPoke('analysisType', 'short');
3314 }
3315  
3316 # Redraw the entries and comboboxes
3317 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3318 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3319 $self->capturePage_connectCombos(\@comboList);
3320  
3321 # Make the changes visible
3322 $self->winShowAll($self->_objClass . '->capturePage');
3323 });
3324  
3325 $radioButton3->signal_connect('toggled' => sub {
3326  
3327 if ($radioButton3->get_active()) {
3328  
3329 $self->ivPoke('analysisType', 'brief');
3330 }
3331  
3332 # Redraw the entries and comboboxes
3333 $self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
3334 $self->capturePage_resetWidgets(\@entryList, \@comboList);
3335 $self->capturePage_connectCombos(\@comboList);
3336  
3337 # Make the changes visible
3338 $self->winShowAll($self->_objClass . '->capturePage');
3339 });
3340  
3341 return 1;
3342 }
3343  
3344 sub capturePage_drawWidgets {
3345  
3346 # Called by $self->capturePage
3347 # Draws a Gtk3::Entry and a Gtk3::Combobox, one for each line in the display buffer
3348 # displayed on this page
3349 #
3350 # Expected arguments
3351 # $startRow - The row on which the first entry/combobox is drawn
3352 # $labelListRef - Reference to a list of Gtk3::Labels at the beginning of each line
3353 # (an empty list if none have been drawn yet)
3354 # $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
3355 # lines (an empty list if none have been drawn yet)
3356 # $comboListRef - Reference to a list of Gtk3::ComboBoxes in which to display components
3357 # (an empty list if none have been drawn yet)
3358 #
3359 # Return values
3360 # 'undef' on improper arguments
3361 # 1 otherwise
3362  
3363 my ($self, $startRow, $labelListRef, $entryListRef, $comboListRef, $check) = @_;
3364  
3365 # Local variables
3366 my $row;
3367  
3368 # Check for improper arguments
3369 if (
3370 ! defined $startRow || ! defined $labelListRef || ! defined $entryListRef
3371 || ! defined $comboListRef || defined $check
3372 ) {
3373 return $axmud::CLIENT->writeImproper(
3374 $self->_objClass . '->capturePage_drawWidgets',
3375 @_,
3376 );
3377 }
3378  
3379 # If any labels/entries/combo boxes have already been drawn, remove them from the grid
3380 if (@$labelListRef) {
3381  
3382 foreach my $label (@$labelListRef) {
3383  
3384 $axmud::CLIENT->desktopObj->removeWidget($self->grid, $label);
3385 }
3386  
3387 @$labelListRef = ();
3388  
3389 foreach my $entry (@$entryListRef) {
3390  
3391 $axmud::CLIENT->desktopObj->removeWidget($self->grid, $entry);
3392 }
3393  
3394 @$entryListRef = ();
3395  
3396 foreach my $comboBox (@$comboListRef) {
3397  
3398 $axmud::CLIENT->desktopObj->removeWidget($self->grid, $comboBox);
3399 }
3400  
3401 @$comboListRef = ();
3402 }
3403  
3404 # Add a list of entry boxes, one for each line
3405 $row = $startRow;
3406 for (my $line = 0; $line < $self->analysisLength; $line++) {
3407  
3408 $row++;
3409  
3410 my $label = $self->addLabel($self->grid, '#' . ($line + 1),
3411 1, 2, $row, ($row + 1));
3412  
3413 push (@$labelListRef, $label);
3414  
3415 my $entry = $self->addEntry($self->grid, undef, undef, TRUE,
3416 2, 9, $row, ($row + 1),
3417 40); # Fixed width
3418 # (Rather than desensitising the entry boxes, just make them un-editable)
3419 $entry->set_editable(FALSE);
3420  
3421 push (@$entryListRef, $entry);
3422 }
3423  
3424 # Add combo boxes, one for each entry box
3425 $row = $startRow;
3426 for (my $line = 0; $line < $self->analysisLength; $line++) {
3427  
3428 my (@componentList, @comboList);
3429  
3430 $row++;
3431  
3432 # The comboboxes show the default list of components (for verbose, short verbose or
3433 # brief statements)
3434 if ($self->analysisType eq 'verbose') {
3435 @componentList = $self->verboseComponentList;
3436 } elsif ($self->analysisType eq 'short') {
3437 @componentList = $self->shortComponentList;
3438 } elsif ($self->analysisType eq 'brief') {
3439 @componentList = $self->briefComponentList;
3440 }
3441  
3442 foreach my $component (@componentList) {
3443  
3444 push (@comboList, $self->ivShow('componentTypeHash', $component));
3445 }
3446  
3447 my $comboBox = $self->addComboBox($self->grid, undef, \@comboList, undef,
3448 9, 12, $row, ($row + 1));
3449  
3450 push (@$comboListRef, $comboBox);
3451 }
3452  
3453 return 1;
3454 }
3455  
3456 sub capturePage_resetWidgets {
3457  
3458 # Called by $self->capturePage, sometimes after a call to $self->capturePage_drawWidgets
3459 # Resets the entry/combo boxes (one for each line in the display buffer displayed on this
3460 # page)
3461 #
3462 # Expected arguments
3463 # $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
3464 # lines
3465 # $comboListRef - Reference to a list of Gtk3::ComboBox-s in which to display components
3466 #
3467 # Return values
3468 # An empty list on improper arguments
3469 # Otherwise, returns the list of lines displayed
3470  
3471 my ($self, $entryListRef, $comboListRef, $check) = @_;
3472  
3473 # Local variables
3474 my (
3475 $startLine, $stopLine, $count,
3476 @emptyList, @entryList, @lineList,
3477 );
3478  
3479 # Check for improper arguments
3480 if (! defined $entryListRef || ! defined $comboListRef || defined $check) {
3481  
3482 $axmud::CLIENT->writeImproper($self->_objClass . '->capturePage_resetWidgets', @_);
3483 return @emptyList;
3484 }
3485  
3486 $self->ivEmpty('bufferObjList');
3487 $self->ivEmpty('bufferTypeList');
3488  
3489 # Show the last $self->analysisLength lines received by the world, but don't exceed the
3490 # boundaries of the display buffer
3491 if ($self->session->displayBufferCount) {
3492  
3493 $stopLine = $self->session->displayBufferLast;
3494 $startLine = $self->session->displayBufferLast - ($self->analysisLength - 1);
3495  
3496 if ($startLine < $self->session->displayBufferFirst) {
3497  
3498 # Don't look before the first line in the buffer
3499 $startLine = $self->session->displayBufferFirst;
3500 }
3501  
3502 $count = -1;
3503  
3504 for (my $line = $startLine; $line <= $stopLine; $line++) {
3505  
3506 my ($bufferObj, $text, $entry);
3507  
3508 $count++;
3509  
3510 $bufferObj = $self->session->ivShow('displayBufferHash', $line);
3511 $text = $bufferObj->modLine;
3512  
3513 # Set the value displayed in the entry box numbered $count
3514 $entry = $$entryListRef[$count];
3515 $entry->set_text($text);
3516 push (@lineList, $text);
3517  
3518 # Update the record stored in the IV
3519 $self->ivPush('bufferObjList', $bufferObj);
3520 }
3521 }
3522  
3523 # Reset the comboboxes to contain the first component in the component list (which is
3524 # 'outside_statement' for verbose, short verbose and brief statements)
3525 foreach my $comboBox (@$comboListRef) {
3526  
3527 $comboBox->set_active(0);
3528  
3529 if ($self->analysisType eq 'verbose') {
3530 $self->ivPush('bufferTypeList', $self->ivFirst('verboseComponentList'));
3531 } elsif ($self->analysisType eq ' short') {
3532 $self->ivPush('bufferTypeList', $self->ivFirst('shortComponentList'));
3533 } else {
3534 $self->ivPush('bufferTypeList', $self->ivFirst('briefComponentList'));
3535 }
3536 }
3537  
3538 return @lineList;
3539 }
3540  
3541 sub capturePage_updateWidgets {
3542  
3543 # Called by $self->capturePage
3544 # Updates the entry/combo boxes (one for each line in the display buffer displayed on this
3545 # page) after the initial call to ->capturePage, in order to display data from the last
3546 # capture
3547 #
3548 # Expected arguments
3549 # $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
3550 # lines
3551 # $comboListRef - Reference to a list of Gtk3::ComboBox-s in which to display components
3552 #
3553 # Return values
3554 # 'undef' on improper arguments
3555 # 1 otherwise
3556  
3557 my ($self, $entryListRef, $comboListRef, $check) = @_;
3558  
3559 # Local variables
3560 my (
3561 $count,
3562 @bufferObjList,
3563 );
3564  
3565 # Check for improper arguments
3566 if (! defined $entryListRef || ! defined $comboListRef || defined $check) {
3567  
3568 return $axmud::CLIENT->writeImproper(
3569 $self->_objClass . '->capturePage_updateWidgets',
3570 @_,
3571 );
3572 }
3573  
3574 # Import the previously-captured list of display buffer objects
3575 @bufferObjList = $self->bufferObjList;
3576  
3577 # Update the entry boxes
3578 $count = -1;
3579 foreach my $bufferObj (@bufferObjList) {
3580  
3581 my $entry;
3582  
3583 $count++;
3584  
3585 $entry = $$entryListRef[$count];
3586 $entry->set_text($bufferObj->modLine);
3587 }
3588  
3589 # Update the combos
3590 $count = -1;
3591 OUTER: foreach my $component ($self->bufferTypeList) {
3592  
3593 my ($combo, $posn);
3594  
3595 $count++;
3596 $combo = $$comboListRef[$count];
3597  
3598 if (defined $combo) {
3599  
3600 # Find the position of the component in the ordered list
3601 if ($self->analysisType eq 'verbose') {
3602 $posn = $self->ivFind('verboseComponentList', $component);
3603 } elsif ($self->analysisType eq 'short') {
3604 $posn = $self->ivFind('shortComponentList', $component);
3605 } else {
3606 $posn = $self->ivFind('briefComponentList', $component);
3607 }
3608  
3609 # Set the combobox to that position (if it was found)
3610 if (defined $posn) {
3611  
3612 $combo->set_active($posn);
3613 }
3614 }
3615 }
3616  
3617 return 1;
3618 }
3619  
3620 sub capturePage_connectCombos {
3621  
3622 # Called by $self->capturePage, usually after a call to ->capturePage_drawWidgets
3623 # Gives each combobox a ->signal_connect method
3624 #
3625 # Expected arguments
3626 # $comboListRef - Reference to a list of Gtk3::ComboBoxes in which to display components
3627 #
3628 # Return values
3629 # 'undef' on improper arguments
3630 # 1 otherwise
3631  
3632 my ($self, $comboListRef, $check) = @_;
3633  
3634 # Check for improper arguments
3635 if (! defined $comboListRef || defined $check) {
3636  
3637 return $axmud::CLIENT->writeImproper(
3638 $self->_objClass . '->capturePage_connectCombos',
3639 @_,
3640 );
3641 }
3642  
3643 OUTER: foreach my $comboBox (@$comboListRef) {
3644  
3645 $comboBox->signal_connect('changed' => sub {
3646  
3647 my ($textIndex, $match, $updateFlag);
3648  
3649 $textIndex = $comboBox->get_active();
3650  
3651 # Find the index of this combobox, as stored in $comboListRef
3652 INNER: for (my $count = 0; $count < $self->analysisLength; $count++) {
3653  
3654 if ($$comboListRef[$count] eq $comboBox) {
3655  
3656 $match = $count;
3657 last INNER;
3658 }
3659 }
3660  
3661 # Update the record stored in the IV
3662 if ($self->analysisType eq 'verbose') {
3663  
3664 $self->ivReplace(
3665 'bufferTypeList',
3666 $match,
3667 $self->ivIndex('verboseComponentList', $textIndex),
3668 );
3669  
3670 } elsif ($self->analysisType eq 'short') {
3671  
3672 $self->ivReplace(
3673 'bufferTypeList',
3674 $match,
3675 $self->ivIndex('shortComponentList', $textIndex),
3676 );
3677  
3678 } else {
3679  
3680 $self->ivReplace(
3681 'bufferTypeList',
3682 $match,
3683 $self->ivIndex('briefComponentList', $textIndex),
3684 );
3685 }
3686  
3687 # Change the contents of every combobox beneath this one to match
3688 if ($match < ($self->analysisLength - 1)) {
3689  
3690 $$comboListRef[$match + 1]->set_active($textIndex);
3691 }
3692 });
3693 }
3694  
3695 return 1;
3696 }
3697  
3698 sub analysisPage {
3699  
3700 # Analysis page - called by $self->setupGrid or ->updateGrid
3701 #
3702 # Expected arguments
3703 # (none besides $self)
3704 #
3705 # Return values
3706 # 'undef' on improper arguments
3707 # 1 otherwise
3708  
3709 my ($self, $check) = @_;
3710  
3711 # Local variables
3712 my ($result, $msg, $row, $string, $listRef, $bufferObj);
3713  
3714 # Check for improper arguments
3715 if (defined $check) {
3716  
3717 return $axmud::CLIENT->writeImproper($self->_objClass . '->analysisPage', @_);
3718 }
3719  
3720 $self->addLabel($self->grid, '<b>Analysis (' . $self->getPageString() . ')</b>',
3721 0, 12, 0, 1);
3722  
3723 # Perform the analysis of the data gathered in the previous page
3724 ($result, $msg) = $self->analyseLines();
3725  
3726 # Analysis failed
3727 if (! $result) {
3728  
3729 $self->addLabel($self->grid, 'Room statement analysis <u>FAILED</u>. Failure message:',
3730 1, 12, 1, 2);
3731 $self->addLabel($self->grid, '<i>' . $msg . '</i>',
3732 1, 12, 2, 3);
3733 $self->addLabel(
3734 $self->grid,
3735 "Try analysing a different room statement. Send your character to the new room,"
3736 . " then click\nthe <b>\'Previous\'</b> button to return to the previous page.",
3737 1, 12, 3, 4);
3738 $self->addLabel(
3739 $self->grid,
3740 "(N.B. The wizard uses a set of rules which are stricter than the normal rules. If"
3741 . " you want to\ndo something that\'s not allowed here, you can try editing the"
3742 . " world profile directly\nusing its 'edit' window.)",
3743 1, 12, 4, 5);
3744  
3745 # If the user had already analysed a room statement, allow them to move on to the last
3746 # page (skipping the next one); otherwise, de-sensitise the 'Next' button, forcing
3747 # them to go back
3748 if ($self->analysisCount) {
3749  
3750 # Allow moving on to the last page
3751 $self->addLabel(
3752 $self->grid,
3753 "If you\'re happy to use the results of previous analyses, click the"
3754 . " <b>\'Next\'</b> button to complete the\nsetup process.",
3755 1, 12, 5, 6);
3756  
3757 # Special rule for the \'next\' button: it returns to page 8
3758 $self->ivAdd('specialNextButtonHash', $self->currentPage, 7);
3759  
3760 } else {
3761  
3762 # Force the user to go back
3763 $self->ivPoke('disableNextButtonFlag', TRUE);
3764 }
3765  
3766 # Add a few empty labels, so that the paragraphs in the window aren't spaced so oddly
3767 for (my $row = 6; $row < 12; $row++) {
3768  
3769 $self->addLabel($self->grid, '',
3770 1, 12, $row, ($row + 1),
3771 );
3772 }
3773  
3774 return 1;
3775  
3776 # Analysis succeeded in verbose/short verbose mode
3777 } elsif ($self->analysisType eq 'verbose' || $self->analysisType eq 'short') {
3778  
3779 $self->ivIncrement('analysisCount');
3780  
3781 if ($self->analysisType eq 'verbose') {
3782 $string = 'Verbose';
3783 } else {
3784 $string = 'Short verbose';
3785 }
3786  
3787 $self->addLabel(
3788 $self->grid,
3789 "$string room statement analysis <u>successful</u>. If the results seems to be in"
3790 . " order, click the <b>\'Next\'</b>\nbutton to see the rest of the analysis.",
3791 1, 12, 1, 2);
3792 $self->addLabel(
3793 $self->grid,
3794 "Otherwise, try analysing a different room statement. Send your character to the"
3795 . " new room, then\nclick the <b>\'Previous\'</b> button to return to the previous"
3796 . " page.",
3797 1, 12, 2, 3);
3798  
3799 # Left column
3800 $self->addLabel($self->grid, '<i>Room title</i>',
3801 1, 6, 3, 4);
3802 my $entry = $self->addEntry($self->grid, undef, undef, TRUE,
3803 1, 6, 4, 5);
3804 $entry->set_editable(FALSE);
3805 if ($self->ivExists('analysisHash', 'verb_title')) {
3806  
3807 $listRef = $self->ivShow('analysisHash', 'verb_title');
3808 # The wizard requires that the 'verb_title' component is only one line
3809 $bufferObj = $self->ivIndex('bufferObjList', $$listRef[0]);
3810 $entry->set_text($bufferObj->modLine);
3811 }
3812 # Add a few empty labels below the entry for padding
3813 for (my $row = 5; $row < 7; $row++) {
3814  
3815 $self->addLabel($self->grid, '',
3816 1, 6, $row, ($row + 1),
3817 );
3818 }
3819  
3820 $self->addLabel($self->grid, '<i>Verbose description</i>',
3821 1, 6, 7, 8);
3822 my $textView = $self->addTextView($self->grid, undef, undef, undef, FALSE,
3823 1, 6, 8, 11);
3824 $self->updateTextView($textView, 'verb_descrip');
3825  
3826 # Right column
3827 $self->addLabel($self->grid, '<i>Exit list</i>',
3828 6, 12, 3, 4);
3829 my $textView2 = $self->addTextView($self->grid, undef, undef, undef, FALSE,
3830 6, 12, 4, 7);
3831 $self->updateTextView($textView2, 'verb_exit');
3832  
3833 $self->addLabel($self->grid, '<i>Individual exits</i>',
3834 6, 12, 7, 8);
3835 my $textView3 = $self->addTextView($self->grid, undef, undef, undef, FALSE,
3836 6, 12, 8, 11);
3837 if ($self->analysisExitList) {
3838  
3839 my $buffer3 = $textView3->get_buffer();
3840 $buffer3->set_text(join("\n", $self->analysisExitList));
3841 }
3842  
3843 return 1;
3844  
3845 # Analysis succeeded in brief mode
3846 } elsif ($self->analysisType eq 'brief') {
3847  
3848 my ($component, $button, $posn, $title);
3849  
3850 $self->ivIncrement('analysisCount');
3851  
3852 $self->addLabel(
3853 $self->grid,
3854 "Brief room statement analysis <u>successful</u>.",
3855 1, 12, 1, 2);
3856  
3857 # For convenience, set which component contains the exit line
3858 if ($self->ivExists('analysisHash', 'brief_title_exit')) {
3859 $component = 'brief_title_exit';
3860 } elsif ($self->ivExists('analysisHash', 'brief_exit_title')) {
3861 $component = 'brief_exit_title';
3862 } else {
3863 $component = 'brief_exit';
3864 }
3865  
3866 # If the 'brief_title_exit' or 'brief_exit_title' components were specified, prompt the
3867 # user to confirm which part of the line contains the room title
3868 if (
3869 (
3870 ! $self->ivExists('profUpdateHash', 'briefExitLeftMarkerList')
3871 && $component eq 'brief_title_exit'
3872 ) || (
3873 ! $self->ivExists('profUpdateHash', 'briefExitRightMarkerList')
3874 && $component eq 'brief_exit_title'
3875 )
3876 ) {
3877 # (The instructions don't need to be repeated, after the user has completed this
3878 # page once before)
3879 $self->addLabel(
3880 $self->grid,
3881 "Please confirm which part of the line containing the room title and exit list"
3882 . " is the room title\nitself, then click the <b>\'Test\'</b> button. For"
3883 . " example, in the line:",
3884 1, 12, 2, 3);
3885 $self->addLabel($self->grid, "<i>Town Centre (n, s, e, w)</i>",
3886 2, 12, 3, 4);
3887 $self->addLabel(
3888 $self->grid,
3889 "...you should copy and paste the <u>Town Centre</u> part (but not the first"
3890 . " bracket) into the box below.",
3891 1, 12, 4, 5);
3892  
3893 # Leave a small gap
3894 $row = 6;
3895  
3896 } else {
3897  
3898 # Leave a small gap
3899 $row = 3;
3900 }
3901  
3902 # (Each of the three components has only line)
3903 $listRef = $self->ivShow('analysisHash', $component);
3904 $bufferObj = $self->ivIndex('bufferObjList', $$listRef[0]);
3905  
3906 if ($component eq 'brief_title_exit') {
3907  
3908 $self->addLabel($self->grid, 'Room title / exit list',
3909 1, 3, $row, ($row + 1));
3910  
3911 } elsif ($component eq 'brief_exit_title') {
3912  
3913 $self->addLabel($self->grid, 'Exit list / room title',
3914 1, 3, $row, ($row + 1));
3915  
3916 } else {
3917  
3918 $self->addLabel($self->grid, 'Exit list',
3919 1, 3, $row, ($row + 1));
3920 }
3921  
3922 my $entry = $self->addEntry($self->grid, undef, $bufferObj->modLine, TRUE,
3923 4, 12, $row, ($row + 1));
3924 $entry->set_editable(FALSE);
3925  
3926 $self->addLabel($self->grid, 'Room title part',
3927 1, 3, ($row + 1), ($row + 2));
3928 my $entry2 = $self->addEntry($self->grid, undef, undef, TRUE,
3929 4, 12, ($row + 1), ($row + 2));
3930  
3931 # If this page has already been completed, we can fill in the room title part
3932 if (
3933 $self->ivExists('profUpdateHash', 'briefExitLeftMarkerList')
3934 && $component eq 'brief_title_exit'
3935 ) {
3936 # The room title is everything to the left of the marker
3937 $listRef = $self->ivShow('profUpdateHash', 'briefExitLeftMarkerList');
3938 OUTER: foreach my $marker (@$listRef) {
3939  
3940 $posn = index($bufferObj->modLine, $marker);
3941 if ($posn > -1) {
3942  
3943 $title = substr($bufferObj->modLine, 0, $posn);
3944 last OUTER;
3945 }
3946 }
3947  
3948 } elsif (
3949 $self->ivExists('profUpdateHash', 'briefExitRightMarkerList')
3950 && $component eq 'brief_exit_title'
3951 ) {
3952 # The room title is everything to the right of the marker
3953 $listRef = $self->ivShow('profUpdateHash', 'briefExitRightMarkerList');
3954 OUTER: foreach my $marker (@$listRef) {
3955  
3956 $posn = index($bufferObj->modLine, $marker);
3957 if ($posn > -1) {
3958  
3959 $title = substr($bufferObj->modLine, ($posn + length($marker)));
3960 last OUTER;
3961 }
3962 }
3963 }
3964  
3965 # Display the room title, if we have it
3966 if ($title) {
3967  
3968 $entry2->set_text($title);
3969 }
3970  
3971 $button = $self->addButton(
3972 $self->grid,
3973 undef,
3974 'Test',
3975 'Test the line containing the list of exits',
3976 1, 12, ($row + 2), ($row + 3));
3977 # ->signal_connect follows...
3978  
3979 # Middle left column
3980 $self->addLabel($self->grid, '<i>Room title</i>',
3981 1, 6, ($row + 3), ($row + 4));
3982 my $entry3 = $self->addEntry($self->grid, undef, undef, TRUE,
3983 1, 6, ($row + 4), ($row + 5));
3984 $entry3->set_editable(FALSE);
3985  
3986 # Middle right column
3987 $self->addLabel($self->grid, '<i>Individual exits</i>',
3988 6, 12, ($row + 3), ($row + 4));
3989 my $entry4 = $self->addEntry($self->grid, undef, undef, TRUE,
3990 6, 12, ($row + 4), ($row + 5));
3991 $entry4->set_editable(FALSE);
3992  
3993 # Bottom portion
3994 $self->addLabel(
3995 $self->grid,
3996 "If the results seem to be in order, click the <b>\'Next\'</b> button. Otherwise,"
3997 . " try analysing a\ndifferent room statement. Send your character to the new room,"
3998 . " then click the <b>\'Previous\'</b> button.",
3999 1, 12, ($row + 5), ($row + 6));
4000  
4001 if ($component eq 'brief_exit') {
4002  
4003 # Add a few empty labels to make the spacing between widgets better
4004 for (my $count = ($row + 5); $count < ($row + 9); $count++) {
4005  
4006 $self->addLabel($self->grid, '',
4007 1, 12, $count, ($count + 1));
4008 }
4009  
4010 } else {
4011  
4012 # Add just a single label to make the spacing between widgets better
4013 $self->addLabel($self->grid, '',
4014 1, 12, ($row + 5), ($row + 6));
4015 }
4016  
4017 # 'Test' button signal_connect
4018 $button->signal_connect('clicked' => sub {
4019  
4020 my (
4021 $lineText, $startText, $stopText, $qmStartText, $qmStopText, $errorMsg,
4022 $newStartText, $newStopText, $foundFlag, $pattern,
4023 @exitList,
4024 );
4025  
4026 $title = $entry2->get_text();
4027 if ($title) {
4028  
4029 # The line stored in $bufferObj->modLine is in the form
4030 # <start_text><exit><delimiter><exit><delimiter><exit><stop_text>
4031 # For the 'brief_title_exit' component, the room title will be somewhere in
4032 # <start_text>; for the 'brief_exit_title' component, the room title will be
4033 # somewhere in <stop_text>.
4034 # The remainding portions of <start_text> and <stop_text> will comprise the
4035 # brief exit markers stored in GA::Profile::World->briefExitLeftMarkerList and
4036 # ->briefExitRightMarkerList
4037 $lineText = $bufferObj->modLine;
4038 $startText = $newStartText = $self->tempStartText;
4039 $stopText = $newStopText = $self->tempStopText;
4040 $qmStartText = quotemeta($startText);
4041 $qmStopText = quotemeta($stopText);
4042  
4043 $errorMsg = 'Test failed (usually because the room title contains a direction,'
4044 . ' e.g. \'The northeast corner of the square\').'
4045 . ' Click the \'Previous\' button and try a room with a'
4046 . ' different title.';
4047  
4048 if ($component eq 'brief_title_exit' && $lineText =~ m/$qmStartText/) {
4049  
4050 # Remove everything up to and including the room title, leaving the rest as
4051 # the left marker
4052 $posn = index($startText, $title);
4053 if ($posn < 0) {
4054  
4055 $self->showMsgDialogue(
4056 'Room title test',
4057 'error',
4058 $errorMsg,
4059 'ok',
4060 );
4061  
4062 } else {
4063  
4064 $newStartText = substr($startText, ($posn + (length $title)));
4065 $foundFlag = TRUE;
4066 }
4067  
4068 } elsif ($component eq 'brief_exit_title' && $lineText =~ m/$qmStopText/) {
4069  
4070 # Remove everything from the room title onwards, leaving the rest as the
4071 # right marker
4072 $posn = index($stopText, $title);
4073 if ($posn < 0) {
4074  
4075 $self->showMsgDialogue(
4076 'Test brief title/exit',
4077 'error',
4078 $errorMsg,
4079 'ok',
4080 );
4081  
4082 } else {
4083  
4084 $newStopText = substr($stopText, 0, $posn);
4085 $foundFlag = TRUE;
4086 }
4087 }
4088  
4089 if ($foundFlag) {
4090  
4091 # Try to extract a list of exits, ready for display. Remove the
4092 # <start_text> and <stop_text> parts from the line...
4093 $lineText =~ s/$qmStartText//;
4094 $lineText =~ s/$qmStopText//;
4095 @exitList = $self->testExtractExits($lineText);
4096  
4097 if (@exitList) {
4098  
4099 # Success! Update $self->profUpdateHash
4100 $self->profileUpdatePush(
4101 'briefExitLeftMarkerList',
4102 quotemeta($newStartText),
4103 );
4104  
4105 $self->profileUpdatePush(
4106 'briefExitRightMarkerList',
4107 quotemeta($newStopText),
4108 );
4109  
4110 $self->profileUpdatePush(
4111 'briefExitDelimiterList',
4112 $self->tempDelimList,
4113 );
4114  
4115 # Update the entry boxes
4116 $entry3->set_text($title);
4117 $entry4->set_text(join(' ', @exitList));
4118  
4119 # As we did for 'brief_exit', compile a regex in the form
4120 # '<start_text>(.*)<stop_text>'
4121 $pattern = quotemeta($newStartText) . '(.*)' . quotemeta($newStopText);
4122 # To cope with a <start_text> part (or even a <stop_text> part) which is
4123 # 'There are four obvious exits:', go through the pattern, removing
4124 # any number words (or numerals!)
4125 $pattern = $self->processPattern($pattern);
4126 # Store the results
4127 $self->profileUpdatePush('briefAnchorPatternList', $pattern);
4128 $self->ivAdd('profUpdateHash', 'briefAnchorOffset', 1);
4129  
4130 # For consistency, also store the analysed exit list
4131 $self->ivPoke('analysisExitList', @exitList);
4132 }
4133 }
4134 }
4135 });
4136  
4137 # For the 'brief_exit' component, there is no room title to display, so desensitise the
4138 # entry boxes and the 'Test' button
4139 if ($component eq 'brief_exit') {
4140  
4141 $entry2->set_sensitive(FALSE);
4142 $entry3->set_sensitive(FALSE);
4143 $button->set_sensitive(FALSE);
4144  
4145 # Also fill $entry4, as if the 'Text' button had already been clicked
4146 $entry4->set_text(join(' ', $self->analysisExitList));
4147 }
4148  
4149 return 1;
4150 }
4151 }
4152  
4153 sub analysis2Page {
4154  
4155 # Analysis2 page - called by $self->setupGrid or ->updateGrid
4156 #
4157 # Expected arguments
4158 # (none besides $self)
4159 #
4160 # Return values
4161 # 'undef' on improper arguments
4162 # 1 otherwise
4163  
4164 my ($self, $check) = @_;
4165  
4166 # Local variables
4167 my ($component, $listRef);
4168  
4169 # Check for improper arguments
4170 if (defined $check) {
4171  
4172 return $axmud::CLIENT->writeImproper($self->_objClass . '->analysis2Page', @_);
4173 }
4174  
4175 # Contents analysis
4176 $self->addLabel($self->grid, '<b>Contents analysis (' . $self->getPageString() . ')</b>',
4177 0, 12, 0, 1);
4178 $self->addLabel(
4179 $self->grid,
4180 $axmud::SCRIPT . " needs some more details so it can analyse lists of objects. For"
4181 . " example, in the line:",
4182 1, 12, 1, 2);
4183 $self->addLabel(
4184 $self->grid,
4185 '<i>Three orcs, two lamps and a giraffe are here.</i>',
4186 2, 12, 2, 3);
4187 $self->addLabel(
4188 $self->grid,
4189 "..." . $axmud::SCRIPT . " needs to know that the pattern <i>\'are here\'</i> means"
4190 . " that there are objects in this room.",
4191 1, 12, 3, 4);
4192 $self->addLabel(
4193 $self->grid,
4194 "Please examine the contents list on the left (it will be empty if you didn\'t allocate"
4195 . " any contents).\nIf the box on the right doesn\'t contain the correct patterns"
4196 . " (regular expressions), you can add them now.",
4197 1, 12, 4, 5);
4198  
4199 if ($self->ivExists('analysisHash', 'verb_content')) {
4200 $component = 'verb_content';
4201 } elsif ($self->ivExists('analysisHash', 'brief_content')) {
4202 $component = 'brief_content';
4203 }
4204  
4205 # Left column
4206 $self->addLabel($self->grid, '<i>Room statement\'s contents list</i>',
4207 1, 6, 5, 6);
4208 my $textView = $self->addTextView($self->grid, undef, undef, undef, FALSE,
4209 1, 6, 6, 7);
4210 my $buffer = $textView->get_buffer();
4211 if ($component && ($component eq 'verb_content' || $component eq 'brief_content')) {
4212  
4213 $self->updateTextView($textView, $component);
4214 }
4215  
4216 # Right column
4217 $self->addLabel($self->grid, '<i>Marker patterns (e.g. \'is here.\')</i>',
4218 6, 12, 5, 6);
4219 my $textView2 = $self->addTextView($self->grid, undef, undef, undef, TRUE,
4220 6, 12, 6, 7);
4221 my $buffer2 = $textView2->get_buffer();
4222 if ($self->markerList) {
4223  
4224 $buffer2->set_text(join("\n", $self->markerList));
4225 }
4226 $self->textViewSignalConnect($buffer2, 'markerList');
4227  
4228 # Bottom area
4229 if ($component) {
4230  
4231 $self->addLabel(
4232 $self->grid,
4233 "If you like, you can test the patterns by clicking the <b>\'Test\'</b> button."
4234 . " When you\'re satisfied,\nclick the <b>\'Next\'</b> button at the bottom of the"
4235 . " window.",
4236 1, 9, 7, 8);
4237 my $button = $self->addButton(
4238 $self->grid,
4239 undef,
4240 'Test',
4241 'Test the contents patterns',
4242 9, 12, 7, 8);
4243 # ->signal_connect appears just below...
4244  
4245 my $textView3 = $self->addTextView($self->grid, undef, undef, undef, FALSE,
4246 1, 12, 8, 9);
4247 my $buffer3 = $textView3->get_buffer();
4248  
4249 $button->signal_connect('clicked' => sub {
4250  
4251 my (@stringList, @modList);
4252  
4253 # Use the standard object parsing code to convert the room's contents list into
4254 # a list of non-model objects
4255 $listRef = $self->ivShow('analysisHash', $component);
4256  
4257 foreach my $line (@$listRef) {
4258  
4259 my $bufferObj = $self->ivIndex('bufferObjList', $line);
4260 push (@stringList, $bufferObj->modLine);
4261 }
4262  
4263 # We can't use GA::Obj::WorldModel->parseObj, because that function uses the
4264 # current world's ->contentPatternList - whereas we want to test the new content
4265 # markers in $textView2
4266 # For each line in turn, perform a substitution - but only once per line
4267 OUTER: foreach my $string (@stringList) {
4268  
4269 INNER: foreach my $regex ($self->markerList) {
4270  
4271 if ($string =~ m/$regex/) {
4272  
4273 $string =~ s/$regex//;
4274 next OUTER;
4275 }
4276 }
4277 }
4278  
4279 $buffer3->set_text(join("\n", @stringList));
4280 });
4281  
4282 } else {
4283  
4284 $self->addLabel(
4285 $self->grid,
4286 "When you\'re ready, click the \'Next\' button at the bottom of the window.",
4287 1, 12, 7, 8);
4288 }
4289  
4290 return 1;
4291 }
4292  
4293 sub lastPage {
4294  
4295 # Last page - called by $self->setupGrid or ->updateGrid
4296 #
4297 # Expected arguments
4298 # (none besides $self)
4299 #
4300 # Return values
4301 # 'undef' on improper arguments
4302 # 1 otherwise
4303  
4304 my ($self, $check) = @_;
4305  
4306 # Local variables
4307 my (@verboseList, @shortList, @briefList);
4308  
4309 # Check for improper arguments
4310 if (defined $check) {
4311  
4312 return $axmud::CLIENT->writeImproper($self->_objClass . '->lastPage', @_);
4313 }
4314  
4315 $self->addLabel($self->grid, '<b>Checklist (' . $self->getPageString() . ')</b>',
4316 0, 12, 0, 1);
4317 $self->addLabel(
4318 $self->grid,
4319 "The world profile will now be updated to use the components displayed below. The"
4320 . " current\ndictionary will also be updated with any modifications you made earlier.",
4321 1, 12, 1, 2);
4322 $self->addLabel(
4323 $self->grid,
4324 "Click <b>\'Finish\'</b> to complete the setup process or click <b>\'Previous\'</b> to"
4325 . " capture another room\nstatement.",
4326 1, 12, 2, 3);
4327  
4328 # Left column
4329 $self->addLabel($self->grid, '<u>Verbose statements</u>',
4330 1, 4, 3, 4);
4331 my $checkButton = $self->addCheckButton(
4332 $self->grid, 'Analysis complete', undef, FALSE, FALSE,
4333 1, 4, 4, 5);
4334 if ($self->verboseComponentObjList) {
4335  
4336 $checkButton->set_active(TRUE);
4337 }
4338  
4339 my $checkButton2 = $self->addCheckButton(
4340 $self->grid, 'Set in profile', undef, FALSE, FALSE,
4341 1, 4, 5, 6);
4342 if ($self->session->currentWorld->verboseComponentList) {
4343  
4344 $checkButton2->set_active(TRUE);
4345 }
4346  
4347 $self->addLabel($self->grid, 'Component list:',
4348 1, 4, 6, 7);
4349 my $textView = $self->addTextView($self->grid, undef, undef, undef, FALSE,
4350 1, 4, 7, 10);
4351 my $buffer = $textView->get_buffer();
4352 foreach my $componentObj ($self->verboseComponentObjList) {
4353  
4354 push (@verboseList, $componentObj->name);
4355 }
4356 $buffer->set_text(join("\n", @verboseList));
4357  
4358 # Middle column
4359 $self->addLabel($self->grid, '<u>Short verbose statements</u>',
4360 5, 8, 3, 4);
4361 my $checkButton3 = $self->addCheckButton(
4362 $self->grid, 'Analysis complete', undef, FALSE, FALSE,
4363 5, 8, 4, 5);
4364 if ($self->shortComponentObjList) {
4365  
4366 $checkButton3->set_active(TRUE);
4367 }
4368  
4369 my $checkButton4 = $self->addCheckButton(
4370 $self->grid, 'Set in profile', undef, FALSE, FALSE,
4371 5, 8, 5, 6);
4372 if ($self->session->currentWorld->shortComponentList) {
4373  
4374 $checkButton4->set_active(TRUE);
4375 }
4376  
4377 $self->addLabel($self->grid, 'Component list:',
4378 5, 8, 6, 7);
4379 my $textView2 = $self->addTextView($self->grid, undef, undef, undef, FALSE,
4380 5, 8, 7, 10);
4381 my $buffer2 = $textView2->get_buffer();
4382 foreach my $componentObj ($self->shortComponentObjList) {
4383  
4384 push (@shortList, $componentObj->name);
4385 }
4386 $buffer2->set_text(join("\n", @shortList));
4387  
4388 # Right column
4389 $self->addLabel($self->grid, '<u>Brief statements</u>',
4390 9, 12, 3, 4);
4391 my $checkButton5 = $self->addCheckButton(
4392 $self->grid, 'Analysis complete', undef, FALSE, FALSE,
4393 9, 12, 4, 5);
4394 if ($self->briefComponentObjList) {
4395  
4396 $checkButton5->set_active(TRUE);
4397 }
4398  
4399 my $checkButton6 = $self->addCheckButton(
4400 $self->grid, 'Set in profile', undef, FALSE, FALSE,
4401 9, 12, 5, 6);
4402 if ($self->session->currentWorld->briefComponentList) {
4403  
4404 $checkButton6->set_active(TRUE);
4405 }
4406  
4407 $self->addLabel($self->grid, 'Component list:',
4408 9, 12, 6, 7);
4409 my $textView3 = $self->addTextView($self->grid, undef, undef, undef, FALSE,
4410 9, 12, 7, 10);
4411 my $buffer3 = $textView3->get_buffer();
4412 foreach my $componentObj ($self->briefComponentObjList) {
4413  
4414 push (@briefList, $componentObj->name);
4415 }
4416 $buffer3->set_text(join("\n", @briefList));
4417  
4418 # Special rule for the \'previous\' button: it returns to page 5
4419 $self->ivAdd('specialPreviousButtonHash', $self->currentPage, 4);
4420  
4421 return 1;
4422 }
4423  
4424 # Support functions
4425  
4426 sub resetDirs {
4427  
4428 # Called by $self->new or ->directionsPage
4429 # Sets (or resets) several direction IVs
4430 #
4431 # Expected arguments
4432 # (none besides $self)
4433 #
4434 # Return values
4435 # 'undef' on improper arguments
4436 # 1 otherwise
4437  
4438 my ($self, $check) = @_;
4439  
4440 # Check for improper arguments
4441 if (defined $check) {
4442  
4443 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetDirs', @_);
4444 }
4445  
4446 $self->ivPoke('customPrimaryDirHash', $self->session->currentDict->primaryDirHash);
4447 $self->ivPoke('customPrimaryAbbrevHash', $self->session->currentDict->primaryAbbrevHash);
4448  
4449 return 1;
4450 }
4451  
4452 sub resetOtherWords {
4453  
4454 # Called by $self->new or ->dictionaryPage
4455 # Sets (or resets) word and phrase IVs
4456 #
4457 # Expected arguments
4458 # (none besides $self)
4459 #
4460 # Return values
4461 # 'undef' on improper arguments
4462 # 1 otherwise
4463  
4464 my ($self, $check) = @_;
4465  
4466 # Local variables
4467 my (
4468 $dictObj,
4469 @numberList,
4470 %numberHash, %newHash,
4471 );
4472  
4473 # Check for improper arguments
4474 if (defined $check) {
4475  
4476 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetOtherWords', @_);
4477 }
4478  
4479 # Import the current dictionary (for convenience)
4480 $dictObj = $self->session->currentDict;
4481  
4482 # Set/reset IVs
4483 $self->ivPoke('definiteList', $dictObj->definiteList);
4484 $self->ivPoke('indefiniteList', $dictObj->indefiniteList);
4485 $self->ivPoke('andList', $dictObj->andList);
4486 $self->ivPoke('orList', $dictObj->orList);
4487  
4488 # $self->numberList is a bit trickier. Import %numberHash, in the form
4489 # $hash{word} = numeral
4490 %numberHash = $dictObj->numberHash;
4491 # Check every key-value pair, looking for the first occurence of each numeral from
4492 # 1 to 10
4493 OUTER: for (my $count = 1; $count <= 10; $count++) {
4494  
4495 INNER: foreach my $key (%numberHash) {
4496  
4497 my $value = $numberHash{$key};
4498  
4499 if (defined $value && $value == $count) {
4500  
4501 if ($newHash{$value}) {
4502  
4503 # We've already added this numeral
4504 next INNER;
4505  
4506 } else {
4507  
4508 # Use this numeral
4509 $newHash{$value} = undef;
4510 push (@numberList, $key);
4511 last INNER;
4512 }
4513 }
4514 }
4515 }
4516  
4517 $self->ivPoke('numberList', @numberList);
4518  
4519 return 1;
4520 }
4521  
4522 sub analyseLines {
4523  
4524 # Called by $self->analysisPage to analyse a room statement gathered in the 'Capture' page
4525 # Analyses the room statement. First performs some checks, and returns an error message if
4526 # any of the checks fail. Otherwise, calls $self->analyseComponent for each component in
4527 # turn
4528 #
4529 # Expected arguments
4530 # (none besides $self)
4531 #
4532 # Return values
4533 # Returns an empty list on improper arguments
4534 # Otherwise, returns a list in the form (1, undef) on success, or (undef, failure_message)
4535 # on failure
4536  
4537 my ($self, $check) = @_;
4538  
4539 # Local variables
4540 my (
4541 $count, $msg, $previous, $anchorLineIndex, $anchorComponent, $flag,
4542 @emptyList, @componentList, @componentObjList,
4543 %analysisHash,
4544 );
4545  
4546 # Check for improper arguments
4547 if (defined $check) {
4548  
4549 $axmud::CLIENT->writeImproper($self->_objClass . '->analyseLines', @_);
4550 return @emptyList;
4551 }
4552  
4553 # The statement's components are spread across up to $self->analysisLength lines
4554 # Divide these lines into groups, one for each component, by compiling a hash in the form
4555 # $hash{component_name} = reference_to_list_of_lines
4556 # Store the hash as $self->analysisHash
4557 $self->collectComponentGroups();
4558  
4559 # For speed, import $self->analysisHash
4560 %analysisHash = $self->analysisHash;
4561  
4562 # Check 1: The wizard uses the first line of the first component containing exits as the
4563 # the anchor line (the user can, of course, designate any part of the room statement as
4564 # the anchor line by using the world profile's 'edit' window)
4565 # There must be exactly one (no more, no less) components containing exits
4566 $count = 0;
4567 foreach my $component (keys %analysisHash) {
4568  
4569 if (
4570 $component eq 'verb_exit' || $component eq 'brief_exit'
4571 || $component eq 'brief_title_exit' || $component eq 'brief_exit_title'
4572 ) {
4573 $count++;
4574 }
4575 }
4576  
4577 if (! $count) {
4578  
4579 $msg = "At least one line must be marked as containing exits (currently, no lines are"
4580 . " marked as\nbelonging to one of the components that contains exits).",
4581  
4582 return (0, $msg);
4583  
4584 } elsif ($count > 1) {
4585  
4586 $msg = "No more than one component containing exits can be specified (you specified "
4587 . $count . " components\nwhich contain exits).";
4588  
4589 return (0, $msg);
4590 }
4591  
4592 # Check 2: There must be either 0 or 1 components containing the room title (specifically,
4593 # the user can't have both 'brief_title' and 'brief_title_exit' / 'brief_exit_title')
4594 $count = 0;
4595 foreach my $component (keys %analysisHash) {
4596  
4597 if (
4598 $component eq 'verb_title' || $component eq 'brief_title'
4599 || $component eq 'brief_title_exit' || $component eq 'brief_exit_title'
4600 ) {
4601 $count++;
4602 }
4603 }
4604  
4605 if ($count > 1) {
4606  
4607 $msg = "No more than one component containing the room title can be specified (you"
4608 . " specified " . $count . "\ncomponents which contain a room title).";
4609  
4610 return (0, $msg);
4611 }
4612  
4613 # Check 3: The wizard requires that some components are a maximum of one line long (the user
4614 # is free, once again, to specify any size in the world profile's 'edit' window)
4615 foreach my $component (keys %analysisHash) {
4616  
4617 my $listRef;
4618  
4619 if (
4620 $component eq 'verb_title' || $component eq 'brief_title'
4621 || $component eq 'brief_exit' || $component eq 'brief_title_exit'
4622 || $component eq 'brief_exit_title'
4623 ) {
4624 $listRef = $analysisHash{$component};
4625  
4626 if (@$listRef > 1) {
4627  
4628 $msg = "Components which contain the room title cannot be longer than 1 line.",
4629  
4630 return (0, $msg);
4631 }
4632 }
4633 }
4634  
4635 # Check 4: The wizard requires that most components are contiguous; i.e. you can't have the
4636 # verbose description on lines 2, 3 and 8 (the user is free, once again, to specify
4637 # non-contiguous components in the world profile's 'edit' window)
4638 # However, the 'outside_statement' and 'ignore_line' don't have to be contiguous
4639 foreach my $component (keys %analysisHash) {
4640  
4641 my ($listRef, $previousLine);
4642  
4643 # Two components are allowed to be split up...
4644 if ($component ne 'outside_statement' && $component ne 'ignore_line') {
4645  
4646 $listRef = $analysisHash{$component};
4647  
4648 foreach my $line (@$listRef) {
4649  
4650 if (defined $previousLine && $line != ($previousLine + 1)) {
4651  
4652 # The component is not contiguous
4653 $msg = "Components can\'t be split up - for example, you can\'t have a"
4654 . " description component on\nlines 2, 3, and 8. (Exception:"
4655 . " \'ignore\' lines can be placed anywhere.)";
4656 return (0, $msg);
4657  
4658 } else {
4659  
4660 $previousLine = $line;
4661 }
4662 }
4663 }
4664 }
4665  
4666 # Check 5: the user may have used 'ignore_line' rather than 'outside_statement' at the
4667 # beginning and end of the list. Convert the former to the latter
4668 $self->convertIgnoreLines();
4669  
4670 # Check 6: there must be no more than 2 'outside_component' groups - one starting at the
4671 # first line, one ending at the last line. ('ignore_line' can be used anywhere, in any
4672 # order)
4673 if (! $self->checkOutsideGroups()) {
4674  
4675 $msg = "You can\'t mark a line in the middle of the room statement as being outside it."
4676 . " Try marking\nthem as lines to ignore, instead.";
4677 return (0, $msg);
4678 }
4679  
4680 # Get a list of components, in the order in which they occur
4681 foreach my $component ($self->bufferTypeList) {
4682  
4683 if (
4684 ! $previous # This is the first component
4685 || $component ne $previous # This is the next component
4686 ) {
4687 push (@componentList, $component);
4688 $previous = $component;
4689 }
4690 }
4691  
4692 # Decide which line is going to be the anchor line (it's the first line of the first
4693 # component containing exits)
4694 OUTER: for (my $line = 0; $line < $self->analysisLength; $line++) {
4695  
4696 my $component;
4697  
4698 if (defined $self->ivIndex('bufferObjList', $line)) {
4699  
4700 $component = $self->ivIndex('bufferTypeList', $line);
4701  
4702 if (
4703 $component eq 'verb_exit' || $component eq 'brief_exit'
4704 || $component eq 'brief_title_exit' || $component eq 'brief_exit_title'
4705 ) {
4706 # This is the anchor line. $anchorLineIndex records its position in
4707 # $self->bufferObjList (not the number of the display buffer line itself)
4708 $anchorLineIndex = $line;
4709 $anchorComponent = $component;
4710 last OUTER;
4711 }
4712 }
4713 }
4714  
4715 # For each component in turn, create a GA::Obj::Component object
4716 foreach my $component (@componentList) {
4717  
4718 my ($componentObj, $listRef);
4719  
4720 # Don't analyse the 'outside_statement' component, obviously
4721 if ($component ne 'outside_statement') {
4722  
4723 $listRef = $analysisHash{$component};
4724  
4725 ($componentObj, $msg) = $self->analyseComponent(
4726 $anchorLineIndex,
4727 $component,
4728 @$listRef,
4729 );
4730  
4731 if (! $componentObj) {
4732  
4733 return (undef, $msg);
4734  
4735 } else {
4736  
4737 push (@componentObjList, $componentObj);
4738 }
4739 }
4740 }
4741  
4742 # Store the list of component objects
4743 if ($self->analysisType eq 'verbose') {
4744 $self->ivPoke('verboseComponentObjList', @componentObjList);
4745 } elsif ($self->analysisType eq 'short') {
4746 $self->ivPoke('shortComponentObjList', @componentObjList);
4747 } elsif ($self->analysisType eq 'brief') {
4748 $self->ivPoke('briefComponentObjList', @componentObjList);
4749 }
4750  
4751 # Analysis successful!
4752 return (1, undef);
4753 }
4754  
4755 sub analyseComponent {
4756  
4757 # Called by $self->analyseLines to analyse one or more lines comprising a single component
4758 # Analyses the lines. If successful, creates a new GA::Obj::Component object for the
4759 # component and sets other IVs ready for them to be copied into the world profile. If not
4760 # successful, returns an error message for ->analysisPage to display
4761 #
4762 # Expected arguments
4763 # $anchorLineIndex - The index of $self->bufferObjList that contains the buffer object
4764 # for the anchor line
4765 # $component - The component's type, e.g. 'verb_title'
4766 # @indexList - A list of of indexes in $self->bufferObjList, each one
4767 # corresponding to a GA::Buffer::Display object. Each index is in
4768 # the range 0 to ($self->analysisLength - 1)
4769 #
4770 # Return values
4771 # Returns an empty list on improper arguments
4772 # Otherwise, returns a list in the form (component_object, undef) on success, or
4773 # (undef, failure_message) on failure
4774  
4775 my ($self, $anchorLineIndex, $component, @indexList) = @_;
4776  
4777 # Local variables
4778 my (
4779 $componentObj, $beforeAnchorFlag, $firstObj, $lastObj, $previousObj, $nextObj,
4780 $componentName, $matchFlag,
4781 @emptyList, @bufferObjList, @originalObjList, @tagList,
4782 );
4783  
4784 # Check for improper arguments
4785 if (! defined $anchorLineIndex || ! defined $component || ! @indexList) {
4786  
4787 $axmud::CLIENT->writeImproper($self->_objClass . '->analyseComponent', @_);
4788 return @emptyList;
4789 }
4790  
4791 # Does this component occur before the anchor line?
4792 if ($indexList[-1] < $anchorLineIndex) {
4793 $beforeAnchorFlag = TRUE;
4794 } else {
4795 $beforeAnchorFlag = FALSE; # Need defined value for a function call
4796 }
4797  
4798 # Get a list of the GA::Buffer::Display objects in this component
4799 foreach my $index (@indexList) {
4800  
4801 push (@bufferObjList, $self->ivIndex('bufferObjList', $index));
4802 }
4803  
4804 # If the component occurs before the anchor line, then we analyse the component's buffer
4805 # objects in reverse order
4806 # (NB In some cases, we need the buffer objects in their original order, so we'll create a
4807 # list for that, too)
4808 @originalObjList = @bufferObjList;
4809 if ($beforeAnchorFlag) {
4810  
4811 @bufferObjList = reverse @bufferObjList;
4812 }
4813  
4814 # For convenience, get the first and last buffer objects (which might be the same). In this
4815 # context, 'first'/'last' mean 'the first/last buffer object to be analysed'
4816 $firstObj = $bufferObjList[0];
4817 $lastObj = $bufferObjList[-1];
4818  
4819 # Get the buffer object which precedes the component ('precedes' means 'the Locator task
4820 # would analyse it before $firstObj'). If there is no such object, $previousObj is 'undef'
4821 if ($beforeAnchorFlag) {
4822 $previousObj = $self->session->ivShow('displayBufferHash', ($firstObj->number + 1));
4823 } else {
4824 $previousObj = $self->session->ivShow('displayBufferHash', ($firstObj->number - 1));
4825 }
4826  
4827 # Get the buffer object which follows the component ('follows' means 'the Locator task
4828 # would analyse it after $lastObj'). If there is no such object, $nextObj is 'undef'
4829 if ($beforeAnchorFlag) {
4830 $nextObj = $self->session->ivShow('displayBufferHash', ($firstObj->number - 1));
4831 } else {
4832 $nextObj = $self->session->ivShow('displayBufferHash', ($firstObj->number + 1));
4833 }
4834  
4835 # A component of the same type could appear in two or all three of the types of room
4836 # statement (verbose, short verbose and brief), and have different characteristics in
4837 # each one. Therefore, give each component a unique name (not already in use by the
4838 # world profile's component hash)
4839 $componentName = $self->setComponentName($component);
4840  
4841 # Create a new component object
4842 $componentObj = Games::Axmud::Obj::Component->new(
4843 $self->session,
4844 $self->session->currentWorld,
4845 $componentName,
4846 $component,
4847 TRUE, # Temporary component (can be made permanent later)
4848 );
4849  
4850 if (! $componentObj) {
4851  
4852 return (undef, "General component error");
4853 }
4854  
4855 # Configure the component, starting with its size. The wizard demands that six components
4856 # have a fixed size; all others have an optional size
4857 if (
4858 $component eq 'verb_title' || $component eq 'brief_title' || $component eq 'brief_exit'
4859 || $component eq 'brief_title_exit' || $component eq 'brief_exit_title'
4860 ) {
4861 # Fixed size - 1 line
4862 $componentObj->ivPoke('size', 1);
4863  
4864 } elsif ($component eq 'verb_exit') {
4865  
4866 # ('verb_exit' components should be treated as single lines, by default)
4867 $componentObj->ivPoke('combineLinesFlag', TRUE);
4868  
4869 # If this component was the last one, or if the size of the component was one line
4870 # (this will be the case nearly every time this wizard is used), assume that the
4871 # component has a fixed size of 1
4872 if ((scalar @indexList) > 1) {
4873  
4874 $matchFlag = $self->checkVerbExitSize($beforeAnchorFlag, @indexList);
4875 }
4876  
4877 if ($matchFlag || (scalar @indexList) == 1) {
4878  
4879 # This component was the last one besides 'outside_statement' components (or the
4880 # first one, if moving backwards)
4881 # Use a fixed size of 1
4882 $componentObj->ivPoke('size', 1);
4883  
4884 } else {
4885  
4886 # Use a minimum size of 1
4887 $componentObj->ivPoke('size', 0);
4888 $componentObj->ivPoke('minSize', 1);
4889 }
4890  
4891 } elsif ($component eq 'ignore_line') {
4892  
4893 # Fixed size - the number of lines specified by the user
4894 $componentObj->ivPoke('size', scalar @indexList);
4895  
4896 } else {
4897  
4898 # Use other IVs to find the size
4899 $componentObj->ivPoke('size', 0);
4900  
4901 # Set the minimum size. For optional components - those that might appear in the room
4902 # statement, or might not, depending on the room - the minimum size is set to 0
4903 if (
4904 $component eq 'verb_content' || $component eq 'verb_special'
4905 || $component eq 'brief_content'
4906 ) {
4907 # Optional component
4908 $componentObj->ivPoke('minSize', 0);
4909 } else {
4910 $componentObj->ivPoke('minSize', 1);
4911 }
4912 }
4913  
4914 if (! $componentObj->size) {
4915  
4916 # The component object specifies several IVs for patterns and Axmud colour/style tags
4917 # which mark the extent of the component. There's no way we can guess which patterns
4918 # might appear in all of the world's room statements, but we can guess which tags are
4919 # being used
4920  
4921 # If there are any colour/style tags used by $firstObj but not used in the preceding
4922 # line, $previousObj...
4923 @tagList = $self->compareTags($firstObj, $previousObj);
4924 if (@tagList) {
4925  
4926 # Store them
4927 $componentObj->ivPoke('startTagList', @tagList);
4928 }
4929  
4930 # If there are any colour/style tags used by $lastObj but not used in the following
4931 # line, $nextObj...
4932 @tagList = $self->compareTags($lastObj, $nextObj);
4933 if (@tagList) {
4934  
4935 # Store them
4936 $componentObj->ivPoke('stopBeforeNoTagList', @tagList);
4937  
4938 } else {
4939  
4940 # Conversely, if there are any colour/style tags used in the following line,
4941 # $nextObj, but not used in $lastObj...
4942 @tagList = $self->compareTags($nextObj, $lastObj);
4943 if (@tagList) {
4944  
4945 # Store them
4946 $componentObj->ivPoke('stopBeforeTagList', @tagList);
4947  
4948 } else {
4949  
4950 # Otherwise, for components before the anchor line, we'll have to assume that
4951 # they stop at the earliest-received line starting with a capital letter
4952 if ($beforeAnchorFlag) {
4953  
4954 $componentObj->ivPoke('upperCount', 1);
4955  
4956 # For components at/after the anchor line, we'll have to assume that they
4957 # stop at the latest-received line containing no alphanumeric characters
4958 } else {
4959  
4960 $componentObj->ivPoke('stopBeforeMode', 'no_letter_num');
4961 }
4962 }
4963 }
4964 }
4965  
4966 # Set the contents of ->profUpdateHash, which in turn is used by $self->saveChanges to
4967 # update the world profile
4968 if ($component eq 'verb_exit') {
4969  
4970 my (
4971 $string, $msg, $exitCount, $subString,
4972 @list, @sortedExitList, @sortedPosnList, @extractedExitList,
4973 %exitPosnHash,
4974 );
4975  
4976 # Empty the temporary list of exits from previous analyses
4977 $self->ivEmpty('analysisExitList');
4978  
4979 # The 'verb_exit' component can consist of more than one line. If it does, usually it's
4980 # because the world has split a long list of exits into two lines; recombine them
4981 # into a single string
4982 $string = '';
4983 foreach my $bufferObj (@originalObjList) {
4984  
4985 if ($string) {
4986 $string .= ' ' . $bufferObj->modLine;
4987 } else {
4988 $string = $bufferObj->modLine;
4989 }
4990 }
4991  
4992 # Get a sorted list of recognised primary directions by length, largest first, and
4993 # eliminate those directions which haven't been set (and are therefore 'undef')
4994 @list = $self->eliminateUndefsFromList(
4995 $self->ivValues('customPrimaryDirHash'),
4996 $self->ivValues('customPrimaryAbbrevHash'),
4997 );
4998  
4999 @sortedExitList = sort {(length $b) <=> (length $a)} (@list);
5000  
5001 # Find the position of each exit in the string. When an exit which matches one of the
5002 # directions in @sortedExitList is found, add it to a hash; in this way, when we find
5003 # the exit 'northeast', we can ignore the exits 'north' and 'east' found at the same
5004 # position
5005 # The hash is in the form
5006 # $exitPosnHash{offset} = exit_name
5007 %exitPosnHash = $self->extractExits($string, @sortedExitList);
5008 if (! %exitPosnHash) {
5009  
5010 $msg = "You marked a line as containing a list of exits, but no exits in recognised"
5011 . " primary directions\nwere found on that line. Either try a different"
5012 . " room, or go back to the first page and modify\nthe list of primary"
5013 . " directions.";
5014 return (0, $msg);
5015 }
5016  
5017 # Otherwise, at least one exit was found. Sort the keys of %exitPosnHash so that we get
5018 # a list of exits found, in the order in which they occured
5019 @sortedPosnList = sort {$a <=> $b} (keys %exitPosnHash);
5020 $exitCount = scalar (@sortedPosnList);
5021  
5022 # Also save the list of exit names (for display on the next page)
5023 foreach my $posn (@sortedPosnList) {
5024  
5025 push (@extractedExitList, $exitPosnHash{$posn});
5026 }
5027  
5028 $self->ivPush('analysisExitList', @extractedExitList);
5029  
5030 # Update $self->profUpdateHash as necessary
5031 if ($exitCount == 1) {
5032  
5033 my ($thisPosn, $thisExit, $pattern);
5034  
5035 # Assume that $string is in the form <start_text><exit><stop_text>
5036 $thisPosn = $sortedPosnList[0];
5037 $thisExit = $exitPosnHash{$thisPosn}; # e.g. 'north'
5038  
5039 # Convert $string into a regex in the form '^<start_text>(.*)<stop_text>'
5040 $pattern = '^' . quotemeta(substr($string, 0, $thisPosn)) . '(.*)'
5041 . quotemeta(substr($string, ($thisPosn + length ($thisExit))));
5042  
5043 # Store the result
5044 if ($self->analysisType eq 'verbose') {
5045  
5046 $self->profileUpdatePush('verboseAnchorPatternList', $pattern);
5047 $self->ivAdd('profUpdateHash', 'verboseAnchorOffset', 1);
5048  
5049 } elsif ($self->analysisType eq 'short') {
5050  
5051 $self->profileUpdatePush('shortAnchorPatternList', $pattern);
5052 $self->ivAdd('profUpdateHash', 'shortAnchorOffset', 1);
5053 }
5054  
5055 # Convert $string into a regex in the form '^<start_text>', and remove any number
5056 # words or numerals (e.g. convert 'There are six exits' to 'There are (.*) exits')
5057 $pattern = '^' . quotemeta(substr($string, 0, $thisPosn));
5058 $pattern = $self->processPattern($pattern);
5059 # Store the result
5060 $self->profileUpdatePush('verboseExitLeftMarkerList', $pattern);
5061  
5062 # Convert $string into a regex in the form '<stop_text>' and remove any number words
5063 # or numerals
5064 $subString = substr($string, ($thisPosn + length ($thisExit)));
5065 $pattern = quotemeta($subString);
5066 $pattern = $self->processPattern($pattern);
5067 # If '<stop_text>' contains only empty space, use an empty string (if the pattern
5068 # contains a space character, and one of the delimiters is also a space
5069 # character, this confuses the Locator task)
5070 if (! ($subString =~ m/\S/)) {
5071  
5072 $pattern = '';
5073 }
5074  
5075 # Store the result
5076 if ($pattern) {
5077  
5078 $self->profileUpdatePush('verboseExitRightMarkerList', $pattern);
5079 }
5080  
5081 } else {
5082  
5083 my (
5084 $startText, $lastPosn, $lastExit, $stopText, $pattern,
5085 @delimList,
5086 );
5087  
5088 # Assume that $string is in the form
5089 # <start_text><exit><delimiter><exit><delimiter><exit><stop_text>
5090 # Get <start_text> and <stop_text>
5091 $startText = substr($string, 0, $sortedPosnList[0]);
5092 $lastPosn = $sortedPosnList[-1];
5093 $lastExit = $exitPosnHash{$lastPosn};
5094 $stopText = substr($string, ($lastPosn + length ($lastExit)));
5095  
5096 # Get a list of <delimiter>s
5097 OUTER: for (my $count = 0; $count < ($exitCount - 1); $count++) {
5098  
5099 my ($thisPosn, $thisExit, $nextPosn, $delim, $flag);
5100  
5101 $thisPosn = $sortedPosnList[$count];
5102 $thisExit = $exitPosnHash{$thisPosn};
5103 $nextPosn = $sortedPosnList[$count + 1];
5104  
5105 $delim = substr(
5106 $string,
5107 ($thisPosn + length($thisExit)),
5108 ($nextPosn - $thisPosn - length($thisExit)),
5109 );
5110  
5111 # Check $delim against the delimiters already in @delimList. If it's not already
5112 # there, add it
5113 INNER: foreach my $otherDelim (@delimList) {
5114  
5115 if ($otherDelim eq $delim) {
5116  
5117 $flag = TRUE;
5118 last INNER;
5119 }
5120 }
5121  
5122 if (! $flag) {
5123  
5124 push (@delimList, $delim);
5125 }
5126 }
5127  
5128 # Compile a regex in the form '^<start_text>(.*)<stop_text>'
5129 $pattern = '^' . quotemeta($startText) . '(.*)' . quotemeta($stopText);
5130 # To cope with a <start_text> part (or even a <stop_text> part) which is 'There are
5131 # four obvious exits:', go through the pattern, removing any number words (or
5132 # numerals!)
5133 $pattern = $self->processPattern($pattern);
5134  
5135 # Store the results
5136 if ($self->analysisType eq 'verbose') {
5137  
5138 $self->profileUpdatePush('verboseAnchorPatternList', $pattern);
5139 $self->ivAdd('profUpdateHash', 'verboseAnchorOffset', 1);
5140  
5141 } elsif ($self->analysisType eq 'short') {
5142  
5143 $self->profileUpdatePush('shortAnchorPatternList', $pattern);
5144 $self->ivAdd('profUpdateHash', 'shortAnchorOffset', 1);
5145 }
5146  
5147 # Compile regexes in the form '^start_text>' and '<stop_text>', and remove any
5148 # number words or numerals (e.g. convert 'There are six exits' to
5149 # 'There are (.*) exits')
5150 # Then store the results
5151 $pattern = '^' . quotemeta($startText);
5152 $pattern = $self->processPattern($pattern);
5153 $self->profileUpdatePush('verboseExitLeftMarkerList', $pattern);
5154  
5155 $pattern = quotemeta($stopText);
5156 $pattern = $self->processPattern($pattern);
5157 # If '<stop_text>' contains only empty space, use an empty string (if the pattern
5158 # contains a space character, and one of the delimiters is also a space
5159 # character, this confuses the Locator task)
5160 if (! ($stopText =~ m/\S/)) {
5161  
5162 $pattern = '';
5163 }
5164  
5165 if ($pattern) {
5166  
5167 $self->profileUpdatePush('verboseExitRightMarkerList', $pattern);
5168 }
5169  
5170 $self->profileUpdatePushSort('verboseExitDelimiterList', @delimList);
5171 }
5172  
5173 } elsif (
5174 $component eq 'brief_exit'
5175 || $component eq 'brief_title_exit'
5176 || $component eq 'brief_exit_title'
5177 ) {
5178 my (
5179 $thisBufferObj, $string, $msg, $exitCount, $startText, $lastPosn, $lastExit,
5180 $stopText, $pattern,
5181 @list, @sortedExitList, @sortedPosnList, @extractedExitList, @delimList,
5182 %exitPosnHash,
5183 );
5184  
5185 # Empty the temporary list of exits from previous analyses
5186 $self->ivEmpty('analysisExitList');
5187  
5188 # The 'verb_exit' component can consist of more than one line, but the wizard requires
5189 # that these three components must be all on line. For compatibility with the code
5190 # above, extract the text of the line into a $string
5191 $thisBufferObj = $bufferObjList[0];
5192 $string = $thisBufferObj->modLine;
5193  
5194 # Get a sorted list of recognised primary directions by length, largest first, and
5195 # eliminate those directions which haven't been set (and are therefore 'undef')
5196 # For the 'verb_exit' component, only non-abbreviated directions are expected; however,
5197 # here we'll assume that both abbreviated and unabbreviated directions are possible
5198 @list = (
5199 $self->eliminateUndefsFromList($self->ivValues('customPrimaryDirHash')),
5200 $self->eliminateUndefsFromList($self->ivValues('customPrimaryAbbrevHash')),
5201 );
5202  
5203 @sortedExitList = sort {(length $b) <=> (length $a)} (@list);
5204  
5205 # Find the position of each exit in the string. When an exit which matches one of the
5206 # directions in @sortedExitList is found, add it to a hash; in this way, when we find
5207 # the exit 'ne', we can ignore the exits 'n' and 'e' found at the same position
5208 # The hash is in the form
5209 # $exitPosnHash{offset} = exit_name
5210 %exitPosnHash = $self->extractExits($string, @sortedExitList);
5211 if (! %exitPosnHash) {
5212  
5213 $msg = "You marked a line as containing a list of exits, but no exits in recognised"
5214 . " primary (abbreviated)\ndirections were found on that line. Either try a"
5215 . " different room, or go back to the first page and\nmodify the list of"
5216 . " primary abbreviated directions.";
5217 return (0, $msg);
5218 }
5219  
5220 # Otherwise, at least one exit was found. Sort the keys of %exitPosnHash so that we get
5221 # a list of exits found, in the order in which they occured
5222 @sortedPosnList = sort {$a <=> $b} (keys %exitPosnHash);
5223 $exitCount = scalar (@sortedPosnList);
5224  
5225 # Also save the list of exit names (for display on the next page)
5226 foreach my $posn (@sortedPosnList) {
5227  
5228 push (@extractedExitList, $exitPosnHash{$posn});
5229 }
5230  
5231 $self->ivPush('analysisExitList', @extractedExitList);
5232  
5233 # Update $self->profUpdateHash as necessary. Assume that $string is in the form
5234 # <start_text><exit><delimiter><exit><delimiter><exit><stop_text>
5235 # ...where <start_text> or <stop_text>, if present, can contain either the room title
5236 # or another <delimiter>
5237  
5238 # Get <start_text> and <stop_text>
5239 $startText = substr($string, 0, $sortedPosnList[0]);
5240 $lastPosn = $sortedPosnList[-1];
5241 $lastExit = $exitPosnHash{$lastPosn};
5242 $stopText = substr($string, ($lastPosn + length ($lastExit)));
5243  
5244 # Get a list of <delimiter>s
5245 OUTER: for (my $count = 0; $count < ($exitCount - 1); $count++) {
5246  
5247 my ($thisPosn, $thisExit, $nextPosn, $delim, $flag);
5248  
5249 $thisPosn = $sortedPosnList[$count];
5250 $thisExit = $exitPosnHash{$thisPosn};
5251 $nextPosn = $sortedPosnList[$count + 1];
5252  
5253 $delim = substr(
5254 $string,
5255 ($thisPosn + length($thisExit)),
5256 ($nextPosn - $thisPosn - length($thisExit)),
5257 );
5258  
5259 # Check $delim against the delimiters already in @delimList. If it's not already
5260 # there, add it
5261 INNER: foreach my $otherDelim (@delimList) {
5262  
5263 if ($otherDelim eq $delim) {
5264  
5265 $flag = TRUE;
5266 last INNER;
5267 }
5268 }
5269  
5270 if (! $flag) {
5271  
5272 push (@delimList, $delim);
5273 }
5274 }
5275  
5276 if ($component eq 'brief_exit') {
5277  
5278 # Compile a regex in the form '^<start_text>(.*)<stop_text>'
5279 $pattern = '^' . quotemeta($startText) . '(.*)' . quotemeta($stopText);
5280 # To cope with a <start_text> part (or even a <stop_text> part) which is 'There are
5281 # four obvious exits:', go through the pattern, removing any number words (or
5282 # numerals!)
5283 $pattern = $self->processPattern($pattern);
5284  
5285 # Store the results
5286 $self->profileUpdatePush('briefAnchorPatternList', $pattern);
5287 $self->ivAdd('profUpdateHash', 'briefAnchorOffset', 1);
5288  
5289 $self->profileUpdatePush('briefExitLeftMarkerList', '^' . quotemeta($startText));
5290  
5291 if ($stopText) {
5292  
5293 $self->profileUpdatePush('briefExitRightMarkerList', quotemeta($stopText));
5294 }
5295  
5296 $self->profileUpdatePushSort('briefExitDelimiterList', @delimList);
5297  
5298 } else {
5299  
5300 # For the 'brief_title_exit' and 'brief_exit_title' components, we need to store
5301 # the substrings and delimiter list temporarily so that $self->analysisPage can
5302 # retrieve them
5303 $self->ivPoke('tempStartText', $startText);
5304 $self->ivPoke('tempStopText', $stopText);
5305 $self->ivPoke('tempDelimList', @delimList);
5306 }
5307 }
5308  
5309 # Analysis complete
5310 return ($componentObj, undef);
5311 }
5312  
5313 sub collectComponentGroups {
5314  
5315 # Called by $self->analyseLines
5316 # Compile the IV ->analysisHash by grouping lines of each component together
5317 #
5318 # Expected arguments
5319 # (none besides $self)
5320 #
5321 # Return values
5322 # 'undef' on improper arguments
5323 # 1 otherwise
5324  
5325 my ($self, $check) = @_;
5326  
5327 # Local variables
5328 my %hash;
5329  
5330 # Check for improper arguments
5331 if (defined $check) {
5332  
5333 return $axmud::CLIENT->writeImproper($self->_objClass . '->collectComponentGroups', @_);
5334 }
5335  
5336 # The statement's components are spread across up to $self->analysisLength lines
5337 # Divide these lines into groups, one for each component, by compiling a hash in the form
5338 # $hash{component_name} = reference_to_list_of_lines
5339 # e.g. $hash{'verb_descrip'} = [3, 4, 5]
5340 for (my $line = 0; $line < $self->analysisLength; $line++) {
5341  
5342 my ($component, $listRef);
5343  
5344 if (defined $self->ivIndex('bufferObjList', $line)) {
5345  
5346 $component = $self->ivIndex('bufferTypeList', $line);
5347  
5348 if (! exists $hash{$component}) {
5349  
5350 $hash{$component} = [$line];
5351  
5352 } else {
5353  
5354 $listRef = $hash{$component};
5355 push (@$listRef, $line);
5356  
5357 $hash{$component} = $listRef;
5358 }
5359 }
5360 }
5361  
5362 # Save the compiled list as an IV
5363 $self->ivPoke('analysisHash', %hash);
5364  
5365 return 1;
5366 }
5367  
5368 sub convertIgnoreLines {
5369  
5370 # Called by $self->analyseLines
5371 # The user may have used 'ignore_line' rather than 'outside_statement' at the beginning
5372 # and end of the list. If so, convert the former to the latter
5373 #
5374 # Expected arguments
5375 # (none besides $self)
5376 #
5377 # Return values
5378 # 'undef' on improper arguments
5379 # 1 otherwise
5380  
5381 my ($self, $check) = @_;
5382  
5383 # Check for improper arguments
5384 if (defined $check) {
5385  
5386 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertIgnoreLines', @_);
5387 }
5388  
5389 # Start from the beginning...
5390 OUTER: for (my $line = 0; $line < $self->analysisLength; $line++) {
5391  
5392 my $type = $self->ivIndex('bufferTypeList', $line);
5393  
5394 if ($type ne 'outside_statement' && $type ne 'ignore_line') {
5395  
5396 last OUTER;
5397  
5398 } elsif ($type eq 'ignore_line') {
5399  
5400 # Convert an 'ignore' to an 'outside'
5401 $self->ivReplace('bufferTypeList', $line, 'outside_statement');
5402 }
5403 }
5404  
5405 # Work back from the end...
5406 OUTER: for (my $line = ($self->analysisLength - 1); $line >= 0; $line--) {
5407  
5408 my $type = $self->ivIndex('bufferTypeList', $line);
5409  
5410 if ($type ne 'outside_statement' && $type ne 'ignore_line') {
5411  
5412 last OUTER;
5413  
5414 } elsif ($type eq 'ignore_line') {
5415  
5416 # Convert an 'ignore' to an 'outside'
5417 $self->ivReplace('bufferTypeList', $line, 'outside_statement');
5418 }
5419 }
5420  
5421 return 1;
5422 }
5423  
5424 sub checkOutsideGroups {
5425  
5426 # Called by $self->analyseLines
5427 # There must be no more than 2 'outside_statement' components - one starting at the first
5428 # line, one ending at the last line ('ignore_line' can be used anywhere, in any order)
5429 # This function checks whether any 'outside_statement' components in the analysed lines
5430 # comply with these rules
5431 #
5432 # Expected arguments
5433 # (none besides $self)
5434 #
5435 # Return values
5436 # 'undef' on improper arguments or if the check fails (the 'outside_component' groups are
5437 # unacceptable)
5438 # 1 if the check succeeds or if there are no 'outside_component' groups in the analysed
5439 # lines
5440  
5441 my ($self, $check) = @_;
5442  
5443 # Local variables
5444 my ($line, $group1Start, $group1Stop, $group2Start, $group2Stop);
5445  
5446 # Check for improper arguments
5447 if (defined $check) {
5448  
5449 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkOutsideGroups', @_);
5450 }
5451  
5452 if ($self->ivExists('analysisHash', 'outside_statement')) {
5453  
5454 $line = -1;
5455  
5456 do {
5457  
5458 $line++;
5459  
5460 if ($self->ivIndex('bufferTypeList', $line) eq 'outside_statement') {
5461  
5462 # First line of group 1
5463 if (! defined $group1Start) {
5464  
5465 $group1Start = $line;
5466  
5467 # First line of group 2
5468 } elsif (defined $group1Stop && ! defined $group2Start) {
5469  
5470 $group2Start = $line;
5471  
5472 # Start of an illegal third group
5473 } elsif (defined $group1Stop && defined $group2Stop) {
5474  
5475 # Check has failed
5476 return undef;
5477 }
5478  
5479 } elsif (defined $group1Start && ! defined $group1Stop) {
5480  
5481 # Last line of group 1
5482 $group1Stop = ($line - 1);
5483  
5484 } elsif (defined $group2Start && ! defined $group2Stop) {
5485  
5486 # Last line of group 2
5487 $group2Stop = ($line - 1);
5488 }
5489  
5490 } until ($line >= ($self->analysisLength - 1));
5491  
5492 # Check for groups that extended all the way to the end
5493 if (defined $group1Start && ! defined $group1Stop) {
5494  
5495 $group1Stop = $self->analysisLength - 1;
5496 }
5497  
5498 if (defined $group2Start && ! defined $group2Stop) {
5499  
5500 $group2Stop = $self->analysisLength - 1;
5501 }
5502  
5503 # Check that 2nd group (if it exists) doesn't stop before the end
5504 if (defined $group2Start && $group2Stop != ($self->analysisLength - 1)) {
5505  
5506 # Check has failed
5507 return undef;
5508 }
5509  
5510 # Check that 1st group (if there are two) doesn't start after the beginning
5511 if (defined $group2Start && $group1Start != 0) {
5512  
5513 # Check has failed
5514 return undef;
5515 }
5516 }
5517  
5518 # Check successful
5519 return 1;
5520 }
5521  
5522 sub checkVerbExitSize {
5523  
5524 # Called by $self->analyseComponent when analysing a 'verb_exit' component
5525 # Checks whether this component is the last one (besides 'outside_statement' components),
5526 # so that we can set the component's size
5527 #
5528 # Expected arguments
5529 # $beforeAnchorFlag
5530 # - Flag set to TRUE if this component occurs before the anchor line, FALSE if it
5531 # occurs after the anchor line
5532 # @indexList
5533 # - A list of of indexes in $self->bufferObjList, each one corresponding to an
5534 # GA::Buffer::Display object
5535 #
5536 # Return values
5537 # 'undef' on improper arguments or if there is another component after the 'verb_exit'
5538 # component
5539 # 1 if the 'verb_exit' component is the last one (besides 'outisde_statement' components)
5540  
5541 my ($self, $beforeAnchorFlag, @indexList) = @_;
5542  
5543 # Local variables
5544 my ($lastIndex, $nextIndex, $step, $exitFlag, $thisIndex);
5545  
5546 # Check for improper arguments
5547 if (! defined $beforeAnchorFlag || ! @indexList) {
5548  
5549 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkVerbExitSize', @_);
5550 }
5551  
5552 # Is this 'verb_exit' component the last one (besides 'outside_statement' components?)
5553 if ($beforeAnchorFlag) {
5554  
5555 $lastIndex = $indexList[0];
5556 $nextIndex = $lastIndex - 1;
5557 $step = -1;
5558  
5559 } else {
5560  
5561 $lastIndex = $indexList[-1];
5562 $nextIndex = $lastIndex + 1;
5563 $step = 1;
5564 }
5565  
5566 $thisIndex = $nextIndex;
5567  
5568 do {
5569  
5570 if ($thisIndex < 0 || $thisIndex >= scalar @indexList) {
5571  
5572 # This 'verb_exit' component is the last one (besides 'outside_statement'
5573 # components)
5574 return 1;
5575  
5576 } elsif ($self->ivIndex('bufferTypeList', $thisIndex) ne 'outside_statement') {
5577  
5578 # This 'verb_exit' component is the not the last one
5579 $exitFlag = TRUE;
5580  
5581 } else {
5582  
5583 # Keep looking
5584 $thisIndex = $thisIndex + $step;
5585 }
5586  
5587 } until ($exitFlag);
5588  
5589 return undef;
5590 }
5591  
5592 sub processPattern {
5593  
5594 # Called by $self->analyseComponent
5595 # The calling function has compiled a pattern to represent the exit list, in the form
5596 # ^<start_text><list_of_exits><stop_text>
5597 # To guard against the possibility that <start_text> might read something like 'There are
5598 # four obvious exits', we need to remove any known number words (and numerals),
5599 # replacing them with '(.*)'
5600 #
5601 # Expected arguments
5602 # $pattern - The pattern to process
5603 #
5604 # Return values
5605 # 'undef' on improper arguments
5606 # Otherwise, returns the processed pattern
5607  
5608 my ($self, $pattern, $check) = @_;
5609  
5610 # Local variables
5611 my (@numberList, @sortedList);
5612  
5613 # Check for improper arguments
5614 if (! defined $pattern || defined $check) {
5615  
5616 return $axmud::CLIENT->writeImproper($self->_objClass . '->processPattern', @_);
5617 }
5618  
5619 # Get a list of words, 'one', 'two', 'three'...
5620 # If the user didn't define any number words in the first page, use the current dictionary
5621 if ($self->numberList) {
5622  
5623 @numberList = $self->numberList;
5624  
5625 } else {
5626  
5627 @numberList = $self->session->currentDict('numberHash');
5628 }
5629  
5630 # Sort the words/phrases in order of size, so that (for example) if $pattern contains the
5631 # word 'nineteen', we don't remove the word 'nine' (leaving 'teen')
5632 @sortedList = sort {length($a) <=> length($b)} (@numberList);
5633  
5634 # Replace number words
5635 foreach my $item (@numberList) {
5636  
5637 $pattern =~ s/$item/(.*)/g;
5638 }
5639  
5640 # Replace numerals
5641 $pattern =~ s/\d+//g;
5642  
5643 return $pattern;
5644 }
5645  
5646 sub extractExits {
5647  
5648 # Called by $self->analyseComponent
5649 # Finds the position of each exit (which matches a recognised custom primary direction) in a
5650 # string which represents one or more buffer lines in a single component
5651 # Adds the exits to a hash, and returns them
5652 #
5653 # Expected arguments
5654 # $string - The line of text to process
5655 #
5656 # Optional arguments
5657 # @exitList - A list of either custom primary directions ('northeast', 'north') or
5658 # custom abbreviated primary directions ('ne', n'), sorted by length,
5659 # largest first. If an empty list, no exits can be extracted (and an
5660 # empty list is returned)
5661 #
5662 # Return values
5663 # An empty list on improper arguments or if $string contains none of the exits in
5664 # @exitList
5665 # Otherwise, returns a hash in the form
5666 # $exitPosnHash{character_number} = direction_name
5667  
5668 my ($self, $string, @exitList) = @_;
5669  
5670 # Local variables
5671 my (
5672 @emptyList,
5673 %exitPosnHash,
5674 );
5675  
5676 # Check for improper arguments
5677 if (! defined $string) {
5678  
5679 $axmud::CLIENT->writeImproper($self->_objClass . '->extractExits', @_);
5680 return @emptyList;
5681 }
5682  
5683 # In some worlds, the list of exits in the room statement is capitalised (e.g.
5684 # 'Exits: North South East'
5685 # Guard against this unfortunate tendency by making sure $string contains no capitals
5686 $string = lc($string);
5687  
5688 # Find the position of each exit in turn
5689 OUTER: foreach my $exit (@exitList) {
5690  
5691 my ($posn, $nextPosn, $exitFlag);
5692  
5693 do {
5694  
5695 my ($previousChar, $nextChar);
5696  
5697 if (defined $nextPosn) {
5698  
5699 # Keep looking after the last position checked
5700 $posn = index($string, $exit, $nextPosn);
5701 $nextPosn = undef;
5702  
5703 } else {
5704  
5705 # Start looking from the beginning of the line
5706 $posn = index($string, $exit);
5707 }
5708  
5709 # Check that the exit is surrounded by non-alphanumeric characters
5710 if ($posn > 0) {
5711  
5712 $previousChar = substr($string, ($posn - 1), 1);
5713 }
5714  
5715 if ($posn < (length ($string) - 1)) {
5716  
5717 $nextChar = substr($string, ($posn + length($exit)), 1);
5718 }
5719  
5720 # If the exit is preceded or followed by an alphanumeric character, then assume
5721 # we've found 'south' in the word 'southeast'
5722 if ($posn > -1) {
5723  
5724 if (
5725 (defined $previousChar && $previousChar =~ m/\w/)
5726 || (defined $nextChar && $nextChar =~ m/\w/)
5727 ) {
5728 $nextPosn = $posn + 1;
5729  
5730 } else {
5731  
5732 # Found an exit. Add it to the hash...
5733 $exitPosnHash{$posn} = $exit;
5734 # ...and move on to the next exit
5735 $exitFlag = TRUE;
5736 }
5737 }
5738  
5739 } until ($posn < 0 || $exitFlag);
5740 }
5741  
5742 return %exitPosnHash; # May be an empty hash
5743 }
5744  
5745 sub testExtractExits {
5746  
5747 # Called by $self->analysisPage, for brief room statements only, after the user clicks the
5748 # 'Test' button
5749 # Extracts a list of exits from a string, from which the room title and/or brief exit
5750 # markers have already been removed
5751 #
5752 # Expected arguments
5753 # $string - The string to process
5754 #
5755 # Return values
5756 # Am empty list on improper arguments
5757 # Otherwise returns the list of exits
5758  
5759 my ($self, $string, $check) = @_;
5760  
5761 # Local variables
5762 my (@emptyList, @delimList, @tempArray, @returnArray);
5763  
5764 # Check for improper arguments
5765 if (! defined $string || defined $check) {
5766  
5767 $axmud::CLIENT->writeImproper($self->_objClass . '->testExtractExits', @_);
5768 return @emptyList;
5769 }
5770  
5771 # In some worlds, the list of exits in the room statement is capitalised (e.g.
5772 # 'Exits: North South East'
5773 # Guard against this unfortunate tendency by making sure $string contains no capitals
5774 $string = lc($string);
5775  
5776 # $self->tempDelimList contains a list of brief exit delimiters stored by the previous page.
5777 # Sort the delimiter list by size, so that a delimiter which is just a comma isn't
5778 # processed before a delimiter which is <, > - which would be ignored, if the comma
5779 # had already been extracted
5780 @delimList = sort {length ($b) <=> length ($a)} ($self->tempDelimList);
5781  
5782 # Initialise @returnArray with the string containing the list of exits to process
5783 push (@returnArray, $string);
5784 foreach my $delim (@delimList) {
5785  
5786 # For each delimiter, move everything already in @returnArray into @tempArray
5787 # For each element now in @tempArray, split it into a list using the delimiter, and push
5788 # it back into @returnArray
5789 # After each iteration, @returnArray will contain the same number of, or more, elements
5790 # than it did before
5791 @tempArray = @returnArray;
5792 @returnArray = ();
5793 foreach my $item (@tempArray) {
5794  
5795 my @list = split ($delim, $item);
5796 push (@returnArray, @list);
5797 }
5798 }
5799  
5800 return @returnArray;
5801 }
5802  
5803 sub textViewSignalConnect {
5804  
5805 # Called by several functions
5806 # Extracts the data from a textview buffer (added with $self->addTextView). Splits it
5807 # into lines of text, removes leading/trailing whitespace, and stores the result in one
5808 # of this object's list IVs
5809 # (Code used is very similar to the ->signal_connect in GA::Generic::EditWin->addTextView)
5810 #
5811 # Expected arguments
5812 # $buffer - The Gtk3::TextView's buffer
5813 # $iv - The list IV in which the lines should be stored
5814 #
5815 # Return values
5816 # 'undef' on improper arguments
5817 # 1 otherwise
5818  
5819 my ($self, $buffer, $iv, $check) = @_;
5820  
5821 # Check for improper arguments
5822 if (defined $check) {
5823  
5824 return $axmud::CLIENT->writeImproper($self->_objClass . '->textViewSignalConnect', @_);
5825 }
5826  
5827 $buffer->signal_connect('changed' => sub {
5828  
5829 my (
5830 $text,
5831 @list, @finalList,
5832 );
5833  
5834 $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
5835  
5836 # Split the contents of the textview into a list of lines, separated by newline
5837 # characters
5838 @list = split("\n", $text);
5839 # Remove any empty lines and leading/trailing whitespace
5840 foreach my $line (@list) {
5841  
5842 if ($line) {
5843  
5844 $line =~ s/^\s*//; # Remove leading whitespace
5845 $line =~ s/\s*$//; # Remove trailing whitepsace
5846  
5847 (push @finalList, $line);
5848 }
5849  
5850 }
5851  
5852 # Set the IV
5853 $self->ivPoke($iv, @finalList);
5854  
5855 # Update the hash of changed IVs
5856 $self->ivAdd('ivChangeHash', $iv, TRUE);
5857 });
5858  
5859 return 1;
5860 }
5861  
5862 sub updateTextView {
5863  
5864 # Called by $self->analysisPage and later pages
5865 # Fills a Gtk3::TextView with the lines in a single component
5866 #
5867 # Expected arguments
5868 # $textView - The Gtk3::TextView to fill up
5869 # $component - The component to use - a key in $self->analysisHash
5870 #
5871 # Return values
5872 # 'undef' on improper arguments
5873 # 1 otherwise
5874  
5875 my ($self, $textView, $component, $check) = @_;
5876  
5877 # Local variables
5878 my (
5879 $textViewBuffer, $listRef,
5880 @bufferObjList, @stringList,
5881 );
5882  
5883 # Check for improper arguments
5884 if (! defined $textView || ! defined $component || defined $check) {
5885  
5886 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateTextView', @_);
5887 }
5888  
5889 $textViewBuffer = $textView->get_buffer();
5890  
5891 # If $component doesn't exist as a key in $self->analysisHash - meaning that the user
5892 # didn't allocate any lines to this component - just make sure the textview is empty
5893 if (! $self->ivExists('analysisHash', $component)) {
5894  
5895 $textViewBuffer->set_text('');
5896  
5897 } else {
5898  
5899 $listRef = $self->ivShow('analysisHash', $component);
5900  
5901 foreach my $line (@$listRef) {
5902  
5903 my $textViewBufferObj = $self->ivIndex('bufferObjList', $line);
5904  
5905 push (@stringList, $textViewBufferObj->modLine);
5906 }
5907  
5908 $textViewBuffer->set_text(join("\n", @stringList));
5909 }
5910  
5911 return 1;
5912 }
5913  
5914 sub eliminateUndefsFromList {
5915  
5916 # Called by several functions which use values from key-value pairs in the hashes
5917 # $self->customPrimaryDirHash and ->customPrimaryAbbrevHash, in which the values might be
5918 # set to 'undef'
5919 # Given a list of elements, eliminates all those which are set to 'undef', and returns
5920 # the modified list
5921 # e.g. in the list ('north', 'south', undef, undef, 'east'), returns
5922 # ('north', 'south', 'east')
5923 #
5924 # Expected arguments
5925 # (none besides $self)
5926 #
5927 # Optional arguments
5928 # @list - A list (usually of custom primary directions)
5929 #
5930 # Return values
5931 # Returns the modified list
5932  
5933 my ($self, @list) = @_;
5934  
5935 # Local variables
5936 my @returnArray;
5937  
5938 # (No improper arguments to check)
5939 foreach my $item (@list) {
5940  
5941 if (defined $item) {
5942  
5943 push (@returnArray, $item);
5944 }
5945 }
5946  
5947 return @returnArray;
5948 }
5949  
5950 sub compareTags {
5951  
5952 # Called by $self->analyseComponent
5953 # Compares two GA::Buffer::Display objects. Returns a list of all the Axmud colour/style
5954 # tags that appear in the first object, but not the second (ignores the dummy tags
5955 # like 'bold', 'reverse_off' and 'attribs_off')
5956 #
5957 # Expected arguments
5958 # $firstObj, $secondObj - The two buffer objects to compare
5959 #
5960 # Return values
5961 # An empty list on improper arguments
5962 # Otherwise, returns a list of all the Axmud colour/style tags that appear in the first
5963 # object, but not the second (ignoring dummy tags); may be an empty list
5964  
5965 my ($self, $firstObj, $secondObj, $check) = @_;
5966  
5967 # Local variables
5968 my (@emptyList, @returnArray);
5969  
5970 # Check for improper arguments
5971 if (! defined $firstObj || ! defined $secondObj || defined $check) {
5972  
5973 $axmud::CLIENT->writeImproper($self->_objClass . '->compareTags', @_);
5974 return @emptyList;
5975 }
5976  
5977 foreach my $tag ($firstObj->ivKeys('tagHash')) {
5978  
5979 if (
5980 ! $secondObj->ivExists('tagHash', $tag)
5981 && ! $axmud::CLIENT->ivExists('constDummyTagHash', $tag)
5982 ) {
5983 push (@returnArray, $tag);
5984 }
5985 }
5986  
5987 # Operation complete
5988 return @returnArray;
5989 }
5990  
5991 sub profileUpdatePush {
5992  
5993 # Called by $self->analysisPage and analyseComponent
5994 #
5995 # The IV $self->profUpdateHash holds any data with which the world profile must be updated,
5996 # when $self->saveChanges is called. The hash is in the form:
5997 # profUpdateHash{$iv} = scalar
5998 # profUpdateHash{$iv} = list_reference
5999 #
6000 # This function adds a new key-value pair for a list IV (but not for a scalar IV).
6001 # If the key already exists, a list of values is added to 'list_reference', however,
6002 # duplicate values are not added
6003 # If the key doesn't yet exist, a new 'list_reference' is created
6004 #
6005 # Expected arguments
6006 # $iv - A list IV (a key in $self->profUpdateHash)
6007 #
6008 # Optional arguments
6009 # @itemList - A list of items to add to the corresponding value in $self->profUpdateHash
6010 # (can be an empty list)
6011 #
6012 # Return values
6013 # 'undef' on improper arguments
6014 # 1 otherwise
6015  
6016 my ($self, $iv, @itemList) = @_;
6017  
6018 # Local variables
6019 my $listRef;
6020  
6021 # Check for improper arguments
6022 if (! defined $iv) {
6023  
6024 return $axmud::CLIENT->writeImproper($self->_objClass . '->profileUpdatePush', @_);
6025 }
6026  
6027 if ($self->ivExists('profUpdateHash', $iv)) {
6028  
6029 $listRef = $self->ivShow('profUpdateHash', $iv);
6030 }
6031  
6032 OUTER: foreach my $newItem (@itemList) {
6033  
6034 INNER: foreach my $oldItem (@$listRef) {
6035  
6036 if ($newItem eq $oldItem) {
6037  
6038 # Don't add the duplicate
6039 next OUTER;
6040 }
6041 }
6042  
6043 # Not a duplicate
6044 push (@$listRef, $newItem);
6045 }
6046  
6047 $self->ivAdd('profUpdateHash', $iv, $listRef);
6048  
6049 return 1;
6050 }
6051  
6052 sub profileUpdatePushSort {
6053  
6054 # Called by $self->analysisPage and analyseComponent
6055 # Companion to $self->profileUpdatePush, called for delimiter lists which need to be
6056 # sorted, longest first
6057 #
6058 # Expected arguments
6059 # $iv - A list IV (a key in $self->profUpdateHash)
6060 #
6061 # Optional arguments
6062 # @itemList - A list of items to add to the corresponding value in $self->profUpdateHash
6063 # (can be an empty list)
6064 #
6065 # Return values
6066 # 'undef' on improper arguments
6067 # 1 otherwise
6068  
6069 my ($self, $iv, @itemList) = @_;
6070  
6071 # Local variables
6072 my $listRef;
6073  
6074 # Check for improper arguments
6075 if (! defined $iv) {
6076  
6077 return $axmud::CLIENT->writeImproper($self->_objClass . '->profileUpdatePush', @_);
6078 }
6079  
6080 if ($self->ivExists('profUpdateHash', $iv)) {
6081  
6082 $listRef = $self->ivShow('profUpdateHash', $iv);
6083 }
6084  
6085 OUTER: foreach my $newItem (@itemList) {
6086  
6087 INNER: foreach my $oldItem (@$listRef) {
6088  
6089 if ($newItem eq $oldItem) {
6090  
6091 # Don't add the duplicate
6092 next OUTER;
6093 }
6094 }
6095  
6096 # Not a duplicate
6097 push (@$listRef, $newItem);
6098 }
6099  
6100 @$listRef = sort {length($b) <=> length($a)} (@$listRef);
6101 $self->ivAdd('profUpdateHash', $iv, $listRef);
6102  
6103 return 1;
6104 }
6105  
6106 sub updateProfileList {
6107  
6108 # Called by $self->saveChanges
6109 #
6110 # Updates a world profile list IV with new values, preserving any existing ones. However,
6111 # duplicate values are not added
6112 #
6113 # Expected arguments
6114 # $profObj - The current world profile
6115 # $iv - An IV in the current world profile
6116 #
6117 # Optional arguments
6118 # @list - A list of values to add to the list IV (if an empty list, no values are
6119 # added)
6120 #
6121 # Return values
6122 # 'undef' on improper arguments or if @list is empty
6123 # 1 otherwise
6124  
6125 my ($self, $profObj, $iv, @list) = @_;
6126  
6127 # Local variables
6128 my @profList;
6129  
6130 # Check for improper arguments
6131 if (! defined $profObj || ! defined $iv) {
6132  
6133 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateProfileList', @_);
6134 }
6135  
6136 # If @list is empty, there's nothing to do
6137 if (! @list) {
6138  
6139 return undef;
6140 }
6141  
6142 # Import the contents of the profile's IV (for convenience)
6143 @profList = $profObj->$iv;
6144  
6145 # Update the list
6146 OUTER: foreach my $item (@list) {
6147  
6148 INNER: foreach my $profItem (@profList) {
6149  
6150 if ($item eq $profItem) {
6151  
6152 # Don't add the duplicate
6153 next OUTER;
6154 }
6155 }
6156  
6157 # Not a duplicate
6158 push (@profList, $item);
6159 }
6160  
6161 # Store the new contents of the IV
6162 $profObj->ivPoke($iv, @profList);
6163  
6164 return 1;
6165 }
6166  
6167 sub insertAnchor {
6168  
6169 # Called by $self->saveChanges
6170 #
6171 # When the world profile's ->verboseComponentList, ->shortComponentList or
6172 # ->briefComponentList is rewritten, we must insert the special 'anchor' component just
6173 # before the component containing exits (which acts as our anchor line)
6174 #
6175 # Expected arguments
6176 # $profObj - The current world profile
6177 # $iv - A list IV in the current world profile (one of the IVs listed above)
6178 # $component - The name of the component about to be inserted into the list IV
6179 #
6180 # Return values
6181 # 'undef' on improper arguments
6182 # 1 otherwise
6183  
6184 my ($self, $profObj, $iv, $component, $check) = @_;
6185  
6186 # Check for improper arguments
6187 if (! defined $profObj || ! defined $iv || ! defined $component || defined $check) {
6188  
6189 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertAnchor', @_);
6190 }
6191  
6192 if (
6193 $component eq 'verb_exit' || $component eq 'brief_exit'
6194 || $component eq 'brief_title_exit' || $component eq 'brief_exit_title'
6195 ) {
6196 $profObj->ivPush($iv, 'anchor');
6197 }
6198  
6199 return 1;
6200 }
6201  
6202 sub checkDelimiters {
6203  
6204 # Called by $self->saveChanges
6205 #
6206 # When the world profile's ->verboseExitDelimiterList IV is updated, we must check that none
6207 # of its values are in ->verboseExitNonDelimiterList and, if so, they must be removed from
6208 # the latter
6209 # We can do the same with ->briefExitDelimiterList and ->briefExitNonDelimiterList
6210 #
6211 # Expected arguments
6212 # $profObj - The current world profile
6213 # $listIV - Set to 'verboseExitDelimiterList' or 'briefExitDelimiterList'
6214 # $nonListIV - Set to 'verboseExitNonDelimiterList' or 'briefExitNonDelimiterList'
6215 #
6216 # Return values
6217 # 'undef' on improper arguments
6218 # 1 otherwise
6219  
6220 my ($self, $profObj, $listIV, $nonListIV, $check) = @_;
6221  
6222 # Local variables
6223 my (@newList);
6224  
6225 # Check for improper arguments
6226 if (! defined $profObj || ! defined $listIV || ! defined $nonListIV || defined $check) {
6227  
6228 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkDelimiters', @_);
6229 }
6230  
6231 OUTER: foreach my $nonDelim ($profObj->$nonListIV) {
6232  
6233 INNER: foreach my $delim ($profObj->$listIV) {
6234  
6235 if ($delim eq $nonDelim) {
6236  
6237 # Remove the non-delimiter by not adding it to @newList
6238 next OUTER;
6239 }
6240 }
6241  
6242 # Preserve the non-delimiter by adding it to @newList
6243 push (@newList, $nonDelim);
6244 }
6245  
6246 # Update the IV
6247 $profObj->ivPoke($nonListIV, @newList);
6248  
6249 return 1;
6250 }
6251  
6252 sub setComponentName {
6253  
6254 # Called by $self->analyseComponent
6255 #
6256 # A component of the same type could appear in two or all three of the types of room
6257 # statement (verbose, short verbose and brief), and have different characteristics in
6258 # each one. Therefore, give each component a unique name (not already in use by the
6259 # world profile's component hash)
6260 #
6261 # Expected arguments
6262 # $type - The component type, e.g. 'verb_descrip'
6263 #
6264 # Return values
6265 # 'undef' on improper arguments
6266 # Otherwise returns the unique component name
6267  
6268 my ($self, $type, $check) = @_;
6269  
6270 # Local variables
6271 my ($count, $name);
6272  
6273 # Check for improper arguments
6274 if (! defined $type || defined $check) {
6275  
6276 return $axmud::CLIENT->writeImproper($self->_objClass . '->setComponentName', @_);
6277 }
6278  
6279 # Try the name 'type_1', then 'type_2', 'type_3', etc
6280 # To prevent any (extremely unlikely) infinite loops, give up at 9999
6281 $count = 0;
6282 # Most pre-configured worlds use components whose names are the same as their type; if
6283 # that's the case, the first new component is 'type_2' rather than 'type_1'
6284 if ($self->session->currentWorld->ivExists('componentHash', $type)) {
6285  
6286 $count = 1;
6287 }
6288  
6289 do {
6290  
6291 my $flag;
6292  
6293 $count++;
6294 $name = $type . '_' . $count;
6295  
6296 # Check that the world profile doesn't have an existing component with this name
6297 if ($self->session->currentWorld->ivExists('componentHash', $name)) {
6298  
6299 $flag = TRUE;
6300 }
6301  
6302 # Check that the wizard hasn't already created any components with this name for a
6303 # different type of room description
6304 if (! $flag && $self->analysisType ne 'verbose') {
6305  
6306 OUTER: foreach my $componentObj ($self->verboseComponentObjList) {
6307  
6308 if ($componentObj->name eq $name) {
6309  
6310 $flag = TRUE;
6311 last OUTER;
6312 }
6313 }
6314 }
6315  
6316 if (! $flag && $self->analysisType ne 'short') {
6317  
6318 OUTER: foreach my $componentObj ($self->shortComponentObjList) {
6319  
6320 if ($componentObj->name eq $name) {
6321  
6322 $flag = TRUE;
6323 last OUTER;
6324 }
6325 }
6326 }
6327  
6328 if (! $flag && $self->analysisType ne 'brief') {
6329  
6330 OUTER: foreach my $componentObj ($self->briefComponentObjList) {
6331  
6332 if ($componentObj->name eq $name) {
6333  
6334 $flag = TRUE;
6335 last OUTER;
6336 }
6337 }
6338 }
6339  
6340 if (! $flag) {
6341  
6342 # The component $name is available
6343 return $name;
6344 }
6345  
6346 } until ($count >= 9999);
6347  
6348 # Escape an (extremely unlikely) infinite loop by just using the name $type
6349 return $type;
6350 }
6351  
6352 sub updateContentComponent {
6353  
6354 # Called by $self->saveChanges
6355 #
6356 # $self->markerList contains the content marker patterns, e.g. 'is here' and 'are here'. The
6357 # markers should also be added to components of the 'verb_content' and 'brief_content', by
6358 # default (would be confusing for the user, if they had to do it themselves using the
6359 # 'edit' window)
6360 #
6361 # Expected arguments
6362 # $componentObj - The GA::Obj::Component to process (can be of any type, but only the
6363 # types 'verb_content' and 'brief_content' are modified)
6364 #
6365 # Return values
6366 # 'undef' on improper arguments or if no modifications are needed
6367 # 1 otherwise
6368  
6369 my ($self, $componentObj, $check) = @_;
6370  
6371 # Check for improper arguments
6372 if (! defined $componentObj || defined $check) {
6373  
6374 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateContentComponent', @_);
6375 }
6376  
6377 # Do nothing if $componentObj is of the wrong type, or if the list of content marker
6378 # patterns in $self->markerList has been emptied
6379 if (
6380 ! $self->markerList
6381 || ($componentObj->type ne 'verb_content' && $componentObj->type ne 'brief_content')
6382 ) {
6383 return undef;
6384 }
6385  
6386 # Use the marker patterns as patterns which mark the start of the component
6387 $componentObj->ivPush('startPatternList', $self->markerList);
6388 # Any line which doesn't contain one of these patterns marks the end of the component
6389 $componentObj->ivPush('stopBeforeNoPatternList', $self->markerList);
6390  
6391 return 1;
6392 }
6393  
6394 ##################
6395 # Accessors - set
6396  
6397 ##################
6398 # Accessors - get
6399  
6400 sub customPrimaryDirHash
6401 { my $self = shift; return %{$self->{customPrimaryDirHash}}; }
6402 sub customPrimaryAbbrevHash
6403 { my $self = shift; return %{$self->{customPrimaryAbbrevHash}}; }
6404  
6405 sub definiteList
6406 { my $self = shift; return @{$self->{definiteList}}; }
6407 sub indefiniteList
6408 { my $self = shift; return @{$self->{indefiniteList}}; }
6409 sub andList
6410 { my $self = shift; return @{$self->{andList}}; }
6411 sub orList
6412 { my $self = shift; return @{$self->{orList}}; }
6413 sub numberList
6414 { my $self = shift; return @{$self->{numberList}}; }
6415 sub markerList
6416 { my $self = shift; return @{$self->{markerList}}; }
6417  
6418 sub ivChangeHash
6419 { my $self = shift; return %{$self->{ivChangeHash}}; }
6420  
6421 sub componentTypeHash
6422 { my $self = shift; return %{$self->{componentTypeHash}}; }
6423 sub verboseComponentList
6424 { my $self = shift; return @{$self->{verboseComponentList}}; }
6425 sub shortComponentList
6426 { my $self = shift; return @{$self->{shortComponentList}}; }
6427 sub briefComponentList
6428 { my $self = shift; return @{$self->{briefComponentList}}; }
6429  
6430 sub bufferObjList
6431 { my $self = shift; return @{$self->{bufferObjList}}; }
6432 sub bufferTypeList
6433 { my $self = shift; return @{$self->{bufferTypeList}}; }
6434  
6435 sub analysisCount
6436 { $_[0]->{analysisCount} }
6437 sub analysisType
6438 { $_[0]->{analysisType} }
6439 sub analysisLength
6440 { $_[0]->{analysisLength} }
6441 sub analysisMinLength
6442 { $_[0]->{analysisMinLength} }
6443 sub analysisMaxLength
6444 { $_[0]->{analysisMaxLength} }
6445 sub analysisInc
6446 { $_[0]->{analysisInc} }
6447 sub analysisHash
6448 { my $self = shift; return %{$self->{analysisHash}}; }
6449  
6450 sub verboseComponentObjList
6451 { my $self = shift; return @{$self->{verboseComponentObjList}}; }
6452 sub shortComponentObjList
6453 { my $self = shift; return @{$self->{shortComponentObjList}}; }
6454 sub briefComponentObjList
6455 { my $self = shift; return @{$self->{briefComponentObjList}}; }
6456  
6457 sub profUpdateHash
6458 { my $self = shift; return %{$self->{profUpdateHash}}; }
6459  
6460 sub analysisExitList
6461 { my $self = shift; return @{$self->{analysisExitList}}; }
6462 sub tempStartText
6463 { $_[0]->{tempStartText} }
6464 sub tempStopText
6465 { $_[0]->{tempStopText} }
6466 sub tempDelimList
6467 { my $self = shift; return @{$self->{tempDelimList}}; }
6468  
6469 sub dirPageLang
6470 { $_[0]->{dirPageLang} }
6471 sub dictPageLang
6472 { $_[0]->{dictPageLang} }
6473 sub indexConvertHash
6474 { my $self = shift; return %{$self->{indexConvertHash}}; }
6475 }
6476  
6477 # Package must return a true value
6478 1