blib/lib/Games/Axmud/Obj/ZoneModel.pm untested

filter: Statementstmt 0.0% 0 / 110 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 29 Podpod 0.0% 0 / 26 totaltotal 0.0% 0 / 249 CC 29 SCAR 55.4
CC
29
Cov
0%
set_vars
600.0
set_multipleLayerFlag
12.0
new
6.0
CRAP 254.7
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::Obj::ZoneModel
16 # A zone model is a template for real zone objects (GA::Obj::Zone) which are stored in a zonemap
17 # (GA::Obj::Zonemap)
18  
19 { package Games::Axmud::Obj::ZoneModel;
20  
21 use strict;
22 use warnings;
23 # use diagnostics;
24  
25 use Glib qw(TRUE FALSE);
26  
27 our @ISA = qw(Games::Axmud);
28  
29 ##################
30 # Constructors
31  
32 sub new {
33  
34 # Called by GA::Obj::Zonemap->setupStandardZonemap and GA::Cmd::AddZoneModel->do
35 # Create a new instance of the zone model object, a blueprint for real zone objects
36 # (GA::Obj::Zone) which are stored in a workspace grid object (GA::Obj::WorkspaceGrid)
37 #
38 # Expected arguments
39 # $zonemapObj - The parent GA::Obj::Zonemap object
40 #
41 # Return values
42 # 'undef' on improper arguments
43 # Blessed reference to the newly-created object on success
44  
45 my ($class, $zonemapObj, $check) = @_;
46  
47 # Check for improper arguments
48 if (! defined $class || ! defined $zonemapObj || defined $check) {
49  
50 return $axmud::CLIENT->writeImproper($class . '->new', @_);
51 }
52  
53 # Setup
54 my $self = {
55 _objName => $zonemapObj->name . '_model',
56 _objClass => $class,
57 _parentFile => 'zonemaps',
58 _parentWorld => undef,
59 _privFlag => TRUE, # All IVs are private
60  
61 # Perl object components
62 # ----------------------
63  
64 # The parent GA::Obj::Zonemap object
65 zonemapObj => $zonemapObj,
66  
67 # Other IVs
68 # ---------
69  
70 # The zone model's number within the parent zonemap (matches
71 # GA::Obj::Zonemap->modelCount) - set by GA::Obj::Zonemap->addZoneModel when the zone
72 # model is added to the zonemap
73 number => undef,
74  
75 # The coordinates of the zone model within the zonemap's 60x60 grid
76 # Coordinates of the top-left corner (e.g. 0,0)
77 left => undef,
78 top => undef,
79 # Coordinates of the bottom-right corner (e.g. 59, 59)
80 right => undef,
81 bottom => undef,
82 # The size of the zone (e.g. 60, 60)
83 width => undef,
84 height => undef,
85  
86 # If this flag is set, the zone model is reserved for certain window types
87 reservedFlag => FALSE,
88 # For reserved zone models, a hash of window types allowed to use it. Hash in the form
89 # $reservedHash{window_name} = window_type
90 # ...where 'window_type' is one of the window types specified by
91 # GA::Client->constGridWinTypeHash, and 'window_name' is either the same as the window
92 # type, or something different that further limits the type of window allowed to use
93 # it:
94 # window_type window_name
95 # ----------- -----------
96 # main main
97 # map map
98 # protocol Any string chosen by the protocol code, (default value is
99 # 'protocol')
100 # fixed Any string chosen by the controlling code (default value is
101 # 'fixed')
102 # custom Any string chosen by the controlling code. For task windows,
103 # the name of the task (e.g. 'status_task', for other windows,
104 # default value is 'custom'
105 # external The external window's name (e.g. 'Notepad')
106 reservedHash => {},
107 # For reserved zones, it's often preferable to use only a single layer. When this flag
108 # is set to TRUE, only a single layer is used by the zone (the default one specified
109 # by GA::Obj::WorkspaceGrid->defaultLayer)
110 multipleLayerFlag => TRUE,
111  
112 # When GA::Client->shareMainWinFlag = FALSE, meaning every session has its own 'main'
113 # window, we probably want to prevent multiple sessions from sharing the same zone
114 # If this IV is defined, this zone model is reserved for a single session. The IV's
115 # value can be any non-empty string. All zone models with the same ->ownerString are
116 # reserved for a particular session.
117 # The first session to place one of its windows into any 'owned' zone claims all of
118 # those zones for itself. If this IV is 'undef', the corresponding zone is available
119 # for any session to use (subject to the restrictions above)
120 # NB Even if ->ownerString is set, it is ignored when GA::Client->shareMainWinFlag
121 # = TRUE (meaning all sessions share a single 'main' window). This default behaviour
122 # guards against the user selecting a zonemap such as 'horizontal', which is designed
123 # for GA::Client->shareMainWinFlag = FALSE
124 ownerString => undef,
125  
126 # In which corner the zone should start placing windows ('top_left', 'top_right',
127 # 'bottom_left', 'bottom_right');
128 startCorner => 'top_left',
129 # In which direction the zone should place windows first ('horizontal' move horizontally
130 # after the first window, if possible, 'vertical' move vertically after the first
131 # window, if possible)
132 orientation => 'vertical',
133 # The default winmap names to use in this zone with 'main' windows and other 'internal'
134 # windows. If not specified, the corresponding GA::Client IVs are used as default
135 # winmaps
136 defaultEnabledWinmap => undef,
137 defaultDisabledWinmap => undef,
138 defaultInternalWinmap => undef,
139  
140 # Sometimes it's useful to set the maximum number of areas (each containing a single
141 # window) allowed in the zone, especially for zones reserved for certain types of
142 # windows. If set to 0, there is no maximum
143 areaMax => 0,
144 # It's very often useful to set the maximum number of areas allowed in one layer of
145 # the zone, because this helps to fill a zone with windows easily. Unlike ->areaMax
146 # which is an absolute maximum, if any layer is full then new windows are just moved
147 # to another layer
148 visibleAreaMax => 0,
149 # The sizes of areas within a zone normally depend on $self->visibleAreaMax; i.e. if
150 # ->visibleAreaMax is set to 2, each area takes up half the zone
151 # If ->visibleAreaMax is set to 0 (meaning unlimited areas), the default area size
152 # is set by the following two variables. They show the default size of an area in
153 # terms of the zonemap's 60x60 grid
154 # If ->visibleAreaMax is set to 0 and either or both of these variables are set to 0,
155 # then either or both of the default area sizes is used when areas are created
156 defaultAreaWidth => 0,
157 defaultAreaHeight => 0,
158 };
159  
160 # Bless the object into existence
161 bless $self, $class;
162 return $self;
163 }
164  
165 sub clone {
166  
167 # Create a clone of an existing zone model
168 #
169 # Expected arguments
170 # $zonemapObj - The new zone model's parent GA::Obj::Zonemap object
171 # $number - The number of the new zone model in the parent zonemap
172 #
173 # Return values
174 # 'undef' on improper arguments
175 # Blessed reference to the newly-created object on success
176  
177 my ($self, $zonemapObj, $number, $check) = @_;
178  
179 # Check for improper arguments
180 if (! defined $zonemapObj || ! defined $number || defined $check) {
181  
182 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
183 }
184  
185 # Setup
186 my $clone = {
187 _objName => $zonemapObj->name . '_model',
188 _objClass => $self->_objClass,
189 _parentFile => 'zonemaps',
190 _parentWorld => undef,
191 _privFlag => TRUE, # All IVs are private
192  
193 zonemapObj => $zonemapObj,
194  
195 number => $number,
196  
197 left => $self->left,
198 top => $self->top,
199 right => $self->right,
200 bottom => $self->bottom,
201 width => $self->width,
202 height => $self->height,
203  
204 reservedFlag => $self->reservedFlag,
205 reservedHash => {$self->reservedHash},
206 multipleLayerFlag => $self->multipleLayerFlag,
207  
208 ownerString => $self->ownerString,
209  
210 startCorner => $self->startCorner,
211 orientation => $self->orientation,
212 defaultEnabledWinmap => $self->defaultEnabledWinmap,
213 defaultDisabledWinmap => $self->defaultDisabledWinmap,
214 defaultInternalWinmap => $self->defaultInternalWinmap,
215  
216 areaMax => $self->areaMax,
217 visibleAreaMax => $self->visibleAreaMax,
218 defaultAreaWidth => $self->defaultAreaWidth,
219 defaultAreaHeight => $self->defaultAreaHeight,
220 };
221  
222 # Bless the new zone model into existence
223 bless $clone, $self->_objClass;
224  
225 return $clone;
226 }
227  
228 ##################
229 # Methods
230  
231 ##################
232 # Accessors - set
233  
234 sub set_multipleLayerFlag {
235  
236 # Called by $self->modifyStandardZonemap
237  
238 my ($self, $flag, $check) = @_;
239  
240 # Check for improper arguments
241 if (! defined $flag || defined $check) {
242  
243 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_multipleLayerFlag', @_);
244 }
245  
246 if ($flag) {
247 $self->ivPoke('multipleLayerFlag', TRUE);
248 } else {
249 $self->ivPoke('multipleLayerFlag', FALSE);
250 }
251  
252 return 1;
253 }
254  
255 sub set_number {
256  
257 # Called by GA::Obj::Zonemap->addZoneModel once this zone model has been added to a zonemap
258  
259 my ($self, $number, $check) = @_;
260  
261 # Check for improper arguments
262 if (! defined $number || defined $check) {
263  
264 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_);
265 }
266  
267 $self->ivPoke('number', $number);
268  
269 return 1;
270 }
271  
272 sub set_vars {
273  
274 # Called by GA::Cmd::AddZoneModel->do and ModifyZoneModel->do
275 # Sets multiple instance variables for this zone model object
276 #
277 # Expected arguments
278 # $standardCmd - The client command that called this function: 'addzonemodel' or
279 # 'modifyzonemodel'
280 #
281 # Optional arguments
282 # A list in the form: (
283 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner, $orientation,
284 # $maxWindows, $maxVisibleWindows, $defaultWidthBlocks, $defaultHeightBlocks,
285 # $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
286 # $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
287 # $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
288 # $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
289 # $reservedFlag,
290 # %reservedWinHash
291 # )
292 #
293 # Notes
294 # Many elements in the argument list correspond to one of this object's IVs. Any scalar
295 # element which is set to 'undef' causes the corresponding IV to be set to its default
296 # value. If %reservedWinHash is empty, the corresponding IV is emptied.
297 #
298 # Return values
299 # 'undef' on improper arguments
300 # 1 otherwise
301  
302 my (
303 $self, $standardCmd,
304 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner, $orientation,
305 $maxWindows, $maxVisibleWindows, $defaultWidthBlocks, $defaultHeightBlocks, $ownerID,
306 $enabledWinmap, $disabledWinmap, $gridWinmap,
307 $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
308 $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
309 $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
310 $reservedFlag,
311 %reservedWinHash,
312 ) = @_;
313  
314 # Check for improper arguments
315 if (! defined $standardCmd) {
316  
317 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_);
318 }
319  
320 # Set IVs
321 if ($sizeFlag) {
322  
323 $self->ivPoke('width', $widthBlocks);
324 $self->ivPoke('height', $heightBlocks);
325 }
326  
327 if ($positionFlag) {
328  
329 $self->ivPoke('left', $xPosBlocks);
330 $self->ivPoke('top', $yPosBlocks);
331 $self->ivPoke('right', $xPosBlocks + $self->width - 1);
332 $self->ivPoke('bottom', $yPosBlocks + $self->height - 1);
333 }
334  
335 if ($reservedFlag) {
336  
337 $self->ivPoke('reservedFlag', TRUE);
338 foreach my $winName (keys %reservedWinHash) {
339  
340 $self->ivAdd('reservedHash', $winName, $reservedWinHash{$winName});
341 }
342  
343 } elsif ($standardCmd eq 'addzonemodel') {
344  
345 $self->ivPoke('reservedFlag', FALSE);
346 $self->ivEmpty('reservedHash');
347 }
348  
349 if ($singleLayerFlag) {
350 $self->ivPoke('multipleLayerFlag', TRUE);
351 } elsif ($standardCmd eq 'addzonemodel') {
352 $self->ivPoke('multipleLayerFlag', FALSE); # Default
353 }
354  
355 if ($startCornerFlag) {
356 $self->ivPoke('startCorner', $startCorner);
357 } elsif ($standardCmd eq 'addzonemodel') {
358 $self->ivPoke('startCorner', 'top_left'); # Default
359 }
360  
361 if ($orientationFlag) {
362 $self->ivPoke('orientation', $orientation);
363 } elsif ($standardCmd eq 'addzonemodel') {
364 $self->ivPoke('orientation', 'vertical'); # Default
365 }
366  
367 if ($maxWindowFlag) {
368 $self->ivPoke('areaMax', $maxWindows);
369 } elsif ($standardCmd eq 'addzonemodel') {
370 $self->ivPoke('areaMax', 0); # Default
371 }
372  
373 if ($maxVisibleWindowFlag) {
374 $self->ivPoke('visibleAreaMax', $maxVisibleWindows);
375 } elsif ($standardCmd eq 'addzonemodel') {
376 $self->ivPoke('visibleAreaMax', 0); # Default
377 }
378  
379 if ($defaultWidthFlag) {
380 $self->ivPoke('defaultAreaWidth', $defaultWidthBlocks);
381 } elsif ($standardCmd eq 'addzonemodel') {
382 $self->ivPoke('defaultAreaWidth', 0); # Default
383 }
384  
385 if ($defaultHeightFlag) {
386 $self->ivPoke('defaultAreaHeight', $defaultHeightBlocks);
387 } elsif ($standardCmd eq 'addzonemodel') {
388 $self->ivPoke('defaultAreaHeight', 0); # Default
389 }
390  
391 if ($ownerIDFlag) {
392 $self->ivPoke('ownerString', $ownerID); # May be 'undef'
393 } else {
394 $self->ivUndef('ownerString'); # Default
395 }
396  
397 if ($enabledWinmapFlag) {
398 $self->ivPoke('defaultEnabledWinmap', $enabledWinmap); # May be 'undef'
399 } else {
400 $self->ivUndef('defaultEnabledWinmap'); # Default
401 }
402  
403 if ($disabledWinmapFlag) {
404 $self->ivPoke('defaultDisabledWinmap', $disabledWinmap); # May be 'undef'
405 } else {
406 $self->ivUndef('defaultDisabledWinmap'); # Default
407 }
408  
409 if ($gridWinmapFlag) {
410 $self->ivPoke('defaultInternalWinmap', $gridWinmap); # May be 'undef'
411 } else {
412 $self->ivUndef('defaultInternalWinmap'); # Default
413 }
414  
415 return 1;
416 }
417  
418 ##################
419 # Accessors - get
420  
421 sub zonemapObj
422 { $_[0]->{zonemapObj} }
423  
424 sub number
425 { $_[0]->{number} }
426  
427 sub left
428 { $_[0]->{left} }
429 sub top
430 { $_[0]->{top} }
431 sub right
432 { $_[0]->{right} }
433 sub bottom
434 { $_[0]->{bottom} }
435 sub width
436 { $_[0]->{width} }
437 sub height
438 { $_[0]->{height} }
439  
440 sub reservedFlag
441 { $_[0]->{reservedFlag} }
442 sub reservedHash
443 { my $self = shift; return %{$self->{reservedHash}}; }
444 sub multipleLayerFlag
445 { $_[0]->{multipleLayerFlag} }
446  
447 sub ownerString
448 { $_[0]->{ownerString} }
449  
450 sub startCorner
451 { $_[0]->{startCorner} }
452 sub orientation
453 { $_[0]->{orientation} }
454 sub defaultEnabledWinmap
455 { $_[0]->{defaultEnabledWinmap} }
456 sub defaultDisabledWinmap
457 { $_[0]->{defaultDisabledWinmap} }
458 sub defaultInternalWinmap
459 { $_[0]->{defaultInternalWinmap} }
460  
461 sub areaMax
462 { $_[0]->{areaMax} }
463 sub visibleAreaMax
464 { $_[0]->{visibleAreaMax} }
465 sub defaultAreaWidth
466 { $_[0]->{defaultAreaWidth} }
467 sub defaultAreaHeight
468 { $_[0]->{defaultAreaHeight} }
469 }
470  
471 # Package must return a true value
472 1