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

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 158 CC 5 SCAR 11.9
CC
5
Cov
0%
new
6.0
set_posn
6.0
set_win
6.0
CRAP 3.3
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::Area
16 # Handles an area, comprising the space used by a single window, within a zone object's internal
17 # grid
18  
19 { package Games::Axmud::Obj::Area;
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::Zone->addArea
35 # Create a new instance of the area object, which stores details about an area of a zone
36 # object's (GA::Obj::Zone) internal grid. The area comprises the space used by a single
37 # window
38 #
39 # Expected arguments
40 # $number - The area's unique number within the zone
41 # $zoneObj - The GA::Obj::Zone to which this area belongs
42 #
43 # Return values
44 # 'undef' on improper arguments
45 # Blessed reference to the newly-created object on success
46  
47 my ($class, $number, $zoneObj, $check) = @_;
48  
49 # Check for improper arguments
50 if (! defined $class || ! defined $number || ! defined $zoneObj || defined $check) {
51  
52 return $axmud::CLIENT->writeImproper($class . '->new', @_);
53 }
54  
55 # Setup
56 my $self = {
57 _objName => 'area',
58 _objClass => $class,
59 _parentFile => undef, # No parent file object
60 _parentWorld => undef, # No parent file object
61 _privFlag => TRUE, # All IVs are private
62  
63 # IVs
64 # ---
65  
66 # The area's number on the zone object's internal grid (matches a key in
67 # GA::Obj::Zone->areaHash) - set later on
68 number => $number,
69 # The GA::Obj::Zone to which this area belongs
70 zoneObj => $zoneObj,
71  
72 # The coordinates of the area within the zone's internal grid, in gridblocks
73 layer => undef,
74 # (Coordinates of the top-left corner)
75 leftBlocks => undef,
76 topBlocks => undef,
77 # (Coordinates of the bottom-right corner)
78 rightBlocks => undef,
79 bottomBlocks => undef,
80 # (The size of the area)
81 widthBlocks => undef,
82 heightBlocks => undef,
83  
84 # The window object (something inheriting from GA::Generic::Win) that fills this area of
85 # the zone object's internal grid
86 winObj => undef,
87 # The current size and position of the window on the workspace (in pixels)
88 xPosPixels => undef,
89 yPosPixels => undef,
90 widthPixels => undef,
91 heightPixels => undef,
92 };
93  
94 # Bless the zone layout into existence
95 bless $self, $class;
96  
97 return $self;
98 }
99  
100 ##################
101 # Methods
102  
103 ##################
104 # Accessors - set
105  
106 sub set_posn {
107  
108 my ($self, $xPosPixels, $yPosPixels, $widthPixels, $heightPixels, $check) = @_;
109  
110 # Check for improper arguments
111 if (
112 ! defined $xPosPixels || ! defined $yPosPixels || ! defined $widthPixels
113 || ! defined $heightPixels || defined $check
114 ) {
115 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_zone', @_);
116 }
117  
118 $self->ivPoke('xPosPixels', $xPosPixels);
119 $self->ivPoke('yPosPixels', $yPosPixels);
120 $self->ivPoke('widthPixels', $widthPixels);
121 $self->ivPoke('heightPixels', $heightPixels);
122  
123 return 1;
124 }
125  
126 sub set_win {
127  
128 my ($self, $winObj, $check) = @_;
129  
130 # Check for improper arguments
131 if (! defined $winObj || defined $check) {
132  
133 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_win', @_);
134 }
135  
136 $self->ivPoke('winObj', $winObj);
137  
138 return 1;
139 }
140  
141 sub set_zone {
142  
143 my ($self, $layer, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $check) = @_;
144  
145 # Check for improper arguments
146 if (
147 ! defined $layer || ! defined $xPosBlocks || ! defined $yPosBlocks
148 || ! defined $widthBlocks || ! defined $heightBlocks || defined $check
149 ) {
150 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_zone', @_);
151 }
152  
153 $self->ivPoke('layer', $layer);
154  
155 $self->ivPoke('leftBlocks', $xPosBlocks);
156 $self->ivPoke('topBlocks', $yPosBlocks);
157 $self->ivPoke('rightBlocks', $xPosBlocks + $widthBlocks - 1);
158 $self->ivPoke('bottomBlocks', $yPosBlocks + $heightBlocks - 1);
159 $self->ivPoke('widthBlocks', $widthBlocks);
160 $self->ivPoke('heightBlocks', $heightBlocks);
161  
162 return 1;
163 }
164  
165 ##################
166 # Accessors - get
167  
168 sub number
169 { $_[0]->{number} }
170 sub zoneObj
171 { $_[0]->{zoneObj} }
172  
173 sub layer
174 { $_[0]->{layer} }
175 sub leftBlocks
176 { $_[0]->{leftBlocks} }
177 sub topBlocks
178 { $_[0]->{topBlocks} }
179 sub rightBlocks
180 { $_[0]->{rightBlocks} }
181 sub bottomBlocks
182 { $_[0]->{bottomBlocks} }
183 sub widthBlocks
184 { $_[0]->{widthBlocks} }
185 sub heightBlocks
186 { $_[0]->{heightBlocks} }
187  
188 sub winObj
189 { $_[0]->{winObj} }
190 sub xPosPixels
191 { $_[0]->{xPosPixels} }
192 sub yPosPixels
193 { $_[0]->{yPosPixels} }
194 sub widthPixels
195 { $_[0]->{widthPixels} }
196 sub heightPixels
197 { $_[0]->{heightPixels} }
198 }
199  
200 # Package must return a true value
201 1