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

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 135 CC 9 SCAR 25.0
CC
9
Cov
0%
set_vars
42.0
new
6.0
clone
6.0
CRAP 12.2
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::Winzone
16 # A winzone object marks out an area on the Gtk3::Grid used by an 'internal' window as being in use
17 # by a single widget, and stores the widget type used
18  
19 { package Games::Axmud::Obj::Winzone;
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::Winmap->setupStandardWinmap and GA::Cmd::AddWinzone->do
35 # Create a new instance of the winzone object, each of which marks out an area of the
36 # Gtk3::Grid used by an 'internal' window as being in use by a table object (inheriting
37 # from GA::Generic::Table), and specifies the type of table object used
38 #
39 # Expected arguments
40 # $winmapObj - The parent GA::Obj::Winmap object
41 #
42 # Return values
43 # 'undef' on improper arguments
44 # Blessed reference to the newly-created object on success
45  
46 my ($class, $winmapObj, $check) = @_;
47  
48 # Check for improper arguments
49 if (! defined $class || ! defined $winmapObj || defined $check) {
50  
51 return $axmud::CLIENT->writeImproper($class . '->new', @_);
52 }
53  
54 # Setup
55 my $self = {
56 _objName => $winmapObj->name . '_winzone',
57 _objClass => $class,
58 _parentFile => 'winmaps',
59 _parentWorld => undef,
60 _privFlag => TRUE, # All IVs are private
61  
62 # Perl object components
63 # ----------------------
64  
65 # The parent GA::Obj::Winmap object
66 winmapObj => $winmapObj,
67  
68 # Other IVs
69 # ---------
70  
71 # The winzone's number within the parent winmap (matches
72 # GA::Obj::Winmap->zoneCount) - set by GA::Obj::Winmap->addWinzone when the winzone is
73 # added to the winmap
74 number => undef,
75 # The package name for the table object handling the Gtk3::Widget in this winzone
76 # (inherits from GA::Generic::Table)
77 packageName => undef,
78 # An optional name to give to the table object, when it is created. If not specified,
79 # the table object's own ->name is the same as its ->number. However, the code that
80 # calls GA::Strip::Table->addTableObj can specify a name and, if so, that name is used
81 # If specified, ->objName can be any string (avoid using short strings or numbers. No
82 # part of the code checks that table object names are unique; if two or more table
83 # objects share the same name, usually the one with the lowest ->number 'wins')
84 # Max 16 characters
85 objName => undef,
86 # Hash of initialisation settings for the table object. The table object should use
87 # default initialisation settings unless it can succesfully interpret one or more of
88 # the key-value pairs in the hash, if there are any
89 initHash => {},
90  
91 # The coordinates of the winzone within the winmap's Gtk3::Grid
92 # Coordinates of the top-left corner (e.g. 0,0)
93 left => undef,
94 top => undef,
95 # Coordinates of the bottom-right corner (e.g. 59, 59)
96 right => undef,
97 bottom => undef,
98 # The size of the winzone (e.g. 60, 60)
99 width => undef,
100 height => undef,
101 };
102  
103 # Bless the object into existence
104 bless $self, $class;
105 return $self;
106 }
107  
108 sub clone {
109  
110 # Create a clone of an existing winzone
111 #
112 # Expected arguments
113 # $winmapObj - The new winzone's parent GA::Obj::Winmap object
114 # $number - The number of the new winzone in the parent winmap
115 #
116 # Return values
117 # 'undef' on improper arguments
118 # Blessed reference to the newly-created object on success
119  
120 my ($self, $winmapObj, $number, $check) = @_;
121  
122 # Check for improper arguments
123 if (! defined $winmapObj || ! defined $number || defined $check) {
124  
125 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
126 }
127  
128 # Setup
129 my $clone = {
130 _objName => $winmapObj->name . '_winzone',
131 _objClass => $self->_objClass,
132 _parentFile => 'winmaps',
133 _parentWorld => undef,
134 _privFlag => TRUE, # All IVs are private
135  
136 winmapObj => $winmapObj,
137  
138 number => $number,
139 packageName => $self->packageName,
140 objName => $self->objName,
141 initHash => {$self->initHash},
142  
143 left => $self->left,
144 top => $self->top,
145 right => $self->right,
146 bottom => $self->bottom,
147 width => $self->width,
148 height => $self->height,
149 };
150  
151 # Bless the new winzone into existence
152 bless $clone, $self->_objClass;
153  
154 return $clone;
155 }
156  
157 ##################
158 # Methods
159  
160 ##################
161 # Accessors - set
162  
163 sub set_number {
164  
165 # Called by GA::Obj::Winmap->addWinzone once this winzone has been added to a winmap
166  
167 my ($self, $number, $check) = @_;
168  
169 # Check for improper arguments
170 if (! defined $number || defined $check) {
171  
172 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_);
173 }
174  
175 $self->ivPoke('number', $number);
176  
177 return 1;
178 }
179  
180 sub set_vars {
181  
182 # Called by GA::Cmd::AddWinzone->do and ModifyWinzone->do
183 # Sets multiple instance variables for this winzone object
184 #
185 # Expected arguments
186 # $standardCmd - The client command that called this function: 'addwinzone' or
187 # 'modifywinzone'
188 #
189 # Optional arguments
190 # A list in the form: (
191 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
192 # $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
193 # $initHashRef, $removeHashRef,
194 # )
195 #
196 # Return values
197 # 'undef' on improper arguments
198 # 1 otherwise
199  
200 my (
201 $self, $standardCmd,
202 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
203 $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
204 $initHashRef, $removeHashRef,
205 ) = @_;
206  
207 # Check for improper arguments
208 if (! defined $standardCmd) {
209  
210 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_);
211 }
212  
213 # Set IVs
214 if ($packageNameFlag) {
215  
216 $self->ivPoke('packageName', $packageName); # Never 'undef'
217 $self->ivEmpty('initHash');
218 }
219  
220 if ($sizeFlag) {
221  
222 $self->ivPoke('width', $widthBlocks);
223 $self->ivPoke('height', $heightBlocks);
224 }
225  
226 if ($positionFlag) {
227  
228 $self->ivPoke('left', $xPosBlocks);
229 $self->ivPoke('top', $yPosBlocks);
230 $self->ivPoke('right', $xPosBlocks + $self->width - 1);
231 $self->ivPoke('bottom', $yPosBlocks + $self->height - 1);
232 }
233  
234 if ($objNameFlag) {
235  
236 $self->ivPoke('objName', $objName); # May be 'undef'
237 }
238  
239 foreach my $key (keys %$initHashRef) {
240  
241 $self->ivAdd('initHash', $key, $$initHashRef{$key});
242 }
243  
244 foreach my $key (keys %$removeHashRef) {
245  
246 $self->ivDelete('initHash', $key);
247 }
248  
249 return 1;
250 }
251  
252 ##################
253 # Accessors - get
254  
255 sub winmapObj
256 { $_[0]->{winmapObj} }
257  
258 sub number
259 { $_[0]->{number} }
260 sub packageName
261 { $_[0]->{packageName} }
262 sub objName
263 { $_[0]->{objName} }
264 sub initHash
265 { my $self = shift; return %{$self->{initHash}}; }
266  
267 sub left
268 { $_[0]->{left} }
269 sub top
270 { $_[0]->{top} }
271 sub right
272 { $_[0]->{right} }
273 sub bottom
274 { $_[0]->{bottom} }
275 sub width
276 { $_[0]->{width} }
277 sub height
278 { $_[0]->{height} }
279 }
280  
281 # Package must return a true value
282 1