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

filter: Statementstmt 0.0% 0 / 92 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 39 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 202 CC 5 SCAR 13.5
CC
5
Cov
0%
new
20.0
reset
6.0
name
2.0
CRAP 3.9
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::RegionScheme
16 # Region scheme object, used to set the colours used by the automapper window
17  
18 { package Games::Axmud::Obj::RegionScheme;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Called by GA::Obj::WorldModel->new and ->addRegionScheme
34 # Creates the GA::Obj::RegionScheme, used to set the colours used by the automapper window
35 #
36 # Expected arguments
37 # $session - The parent GA::Session (not stored as an IV)
38 # $wmObj - The parent GA::Obj::WorldModel (not stored as an IV)
39 # $name - Unique name for this region scheme (max 16 chars)
40 #
41 # Return values
42 # 'undef' on improper arguments or if $name is invalid
43 # Blessed reference to the newly-created object on success
44  
45 my ($class, $session, $wmObj, $name, $check) = @_;
46  
47 # Check for improper arguments
48 if (
49 ! defined $class || ! defined $session || ! defined $wmObj || ! defined $name
50 || defined $check
51 ) {
52 return $axmud::CLIENT->writeImproper($class . '->new', @_);
53 }
54  
55 # Check that $name is valid and not already in use by another region scheme
56 if ($name ne 'default' && ! $axmud::CLIENT->nameCheck($name, 16)) {
57  
58 return $axmud::CLIENT->writeError(
59 'Registry naming error: invalid name \'' . $name . '\'',
60 $class . '->new',
61 );
62  
63 } elsif ($wmObj->ivExists('regionSchemeHash', $name)) {
64  
65 return $axmud::CLIENT->writeError(
66 'Registry naming error: region scheme \'' . $name . '\' already exists',
67 $class . '->new',
68 );
69 }
70  
71 # Setup
72 my $self = {
73 _objName => 'region_scheme_' . $name,
74 _objClass => $class,
75 _parentFile => 'worldmodel',
76 _parentWorld => $session->currentWorld->name,
77 _privFlag => FALSE, # All IVs are public
78  
79 # IVs
80 # ---
81  
82 # Unique name for this regon scheme (max 16 chars)
83 name => $name,
84  
85 # Colours for the region scheme, corresponding to IVs for default colours in the
86 # parent GA::Obj::WorldModel object
87 backgroundColour => undef, # Set below
88 # (There is no ->noBackgroundColour IV; always use
89 # GA::Obj::WorldModel->defaultNoBackgroundColour)
90 roomColour => undef,
91 roomTextColour => undef,
92 selectBoxColour => undef,
93 borderColour => undef,
94 currentBorderColour => undef,
95 currentFollowBorderColour => undef,
96 currentWaitBorderColour => undef,
97 currentSelectBorderColour => undef,
98 lostBorderColour => undef,
99 lostSelectBorderColour => undef,
100 ghostBorderColour => undef,
101 ghostSelectBorderColour => undef,
102 selectBorderColour => undef,
103 roomAboveColour => undef,
104 roomBelowColour => undef,
105 roomTagColour => undef,
106 selectRoomTagColour => undef,
107 roomGuildColour => undef,
108 selectRoomGuildColour => undef,
109 exitColour => undef,
110 selectExitColour => undef,
111 selectExitTwinColour => undef,
112 selectExitShadowColour => undef,
113 randomExitColour => undef,
114 impassableExitColour => undef,
115 mysteryExitColour => undef,
116 checkedDirColour => undef,
117 dragExitColour => undef,
118 exitTagColour => undef,
119 selectExitTagColour => undef,
120 mapLabelColour => undef,
121 selectMapLabelColour => undef,
122 };
123  
124 # Bless the object into existence
125 bless $self, $class;
126  
127 # Give the colours their initial values
128 $self->reset($wmObj);
129  
130 return $self;
131 }
132  
133 ##################
134 # Methods
135  
136 sub reset {
137  
138 # Called by $self->new, or by any other code
139 # Resets colours for this region scheme to match the default colours of the parent
140 # GA::Obj::WorldModel object
141 #
142 # Expected arguments
143 # $wmObj - The parent GA::Obj::WorldModel
144 #
145 # Return values
146 # 'undef' on improper arguments
147 # 1 otherwise
148  
149 my ($self, $wmObj, $check) = @_;
150  
151 # Check for improper arguments
152 if (! defined $wmObj || defined $check) {
153  
154 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset', @_);
155 }
156  
157 $self->ivPoke('backgroundColour', $wmObj->defaultBackgroundColour);
158 $self->ivPoke('roomColour', $wmObj->defaultRoomColour);
159 $self->ivPoke('roomTextColour', $wmObj->defaultRoomTextColour);
160 $self->ivPoke('selectBoxColour', $wmObj->defaultSelectBoxColour);
161 $self->ivPoke('borderColour', $wmObj->defaultBorderColour);
162 $self->ivPoke('currentBorderColour', $wmObj->defaultCurrentBorderColour);
163 $self->ivPoke('currentFollowBorderColour', $wmObj->defaultCurrentFollowBorderColour);
164 $self->ivPoke('currentWaitBorderColour', $wmObj->defaultCurrentWaitBorderColour);
165 $self->ivPoke('currentSelectBorderColour', $wmObj->defaultCurrentSelectBorderColour);
166 $self->ivPoke('lostBorderColour', $wmObj->defaultLostBorderColour);
167 $self->ivPoke('lostSelectBorderColour', $wmObj->defaultLostSelectBorderColour);
168 $self->ivPoke('ghostBorderColour', $wmObj->defaultGhostBorderColour);
169 $self->ivPoke('ghostSelectBorderColour', $wmObj->defaultGhostSelectBorderColour);
170 $self->ivPoke('selectBorderColour', $wmObj->defaultSelectBorderColour);
171 $self->ivPoke('roomAboveColour', $wmObj->defaultRoomAboveColour);
172 $self->ivPoke('roomBelowColour', $wmObj->defaultRoomBelowColour);
173 $self->ivPoke('roomTagColour', $wmObj->defaultRoomTagColour);
174 $self->ivPoke('selectRoomTagColour', $wmObj->defaultSelectRoomTagColour);
175 $self->ivPoke('roomGuildColour', $wmObj->defaultRoomGuildColour);
176 $self->ivPoke('selectRoomGuildColour', $wmObj->defaultSelectRoomGuildColour);
177 $self->ivPoke('exitColour', $wmObj->defaultExitColour);
178 $self->ivPoke('selectExitColour', $wmObj->defaultSelectExitColour);
179 $self->ivPoke('selectExitTwinColour', $wmObj->defaultSelectExitTwinColour);
180 $self->ivPoke('selectExitShadowColour', $wmObj->defaultSelectExitShadowColour);
181 $self->ivPoke('randomExitColour', $wmObj->defaultRandomExitColour);
182 $self->ivPoke('impassableExitColour', $wmObj->defaultImpassableExitColour);
183 $self->ivPoke('mysteryExitColour', $wmObj->defaultMysteryExitColour);
184 $self->ivPoke('checkedDirColour', $wmObj->defaultCheckedDirColour);
185 $self->ivPoke('dragExitColour', $wmObj->defaultDragExitColour);
186 $self->ivPoke('exitTagColour', $wmObj->defaultExitTagColour);
187 $self->ivPoke('selectExitTagColour', $wmObj->defaultSelectExitTagColour);
188 $self->ivPoke('mapLabelColour', $wmObj->defaultMapLabelColour);
189 $self->ivPoke('selectMapLabelColour', $wmObj->defaultSelectMapLabelColour);
190  
191 return 1;
192 }
193  
194 ##################
195 # Accessors - set
196  
197 ##################
198 # Accessors - get
199  
200 sub name
201 { $_[0]->{name} }
202  
203 sub backgroundColour
204 { $_[0]->{backgroundColour} }
205 sub roomColour
206 { $_[0]->{roomColour} }
207 sub roomTextColour
208 { $_[0]->{roomTextColour} }
209 sub selectBoxColour
210 { $_[0]->{selectBoxColour} }
211 sub borderColour
212 { $_[0]->{borderColour} }
213 sub currentBorderColour
214 { $_[0]->{currentBorderColour} }
215 sub currentFollowBorderColour
216 { $_[0]->{currentFollowBorderColour} }
217 sub currentWaitBorderColour
218 { $_[0]->{currentWaitBorderColour} }
219 sub currentSelectBorderColour
220 { $_[0]->{currentSelectBorderColour} }
221 sub lostBorderColour
222 { $_[0]->{lostBorderColour} }
223 sub lostSelectBorderColour
224 { $_[0]->{lostSelectBorderColour} }
225 sub ghostBorderColour
226 { $_[0]->{ghostBorderColour} }
227 sub ghostSelectBorderColour
228 { $_[0]->{ghostSelectBorderColour} }
229 sub selectBorderColour
230 { $_[0]->{selectBorderColour} }
231 sub roomAboveColour
232 { $_[0]->{roomAboveColour} }
233 sub roomBelowColour
234 { $_[0]->{roomBelowColour} }
235 sub roomTagColour
236 { $_[0]->{roomTagColour} }
237 sub selectRoomTagColour
238 { $_[0]->{selectRoomTagColour} }
239 sub roomGuildColour
240 { $_[0]->{roomGuildColour} }
241 sub selectRoomGuildColour
242 { $_[0]->{selectRoomGuildColour} }
243 sub exitColour
244 { $_[0]->{exitColour} }
245 sub selectExitColour
246 { $_[0]->{selectExitColour} }
247 sub selectExitTwinColour
248 { $_[0]->{selectExitTwinColour} }
249 sub selectExitShadowColour
250 { $_[0]->{selectExitShadowColour} }
251 sub randomExitColour
252 { $_[0]->{randomExitColour} }
253 sub impassableExitColour
254 { $_[0]->{impassableExitColour} }
255 sub mysteryExitColour
256 { $_[0]->{mysteryExitColour} }
257 sub checkedDirColour
258 { $_[0]->{checkedDirColour} }
259 sub dragExitColour
260 { $_[0]->{dragExitColour} }
261 sub exitTagColour
262 { $_[0]->{exitTagColour} }
263 sub selectExitTagColour
264 { $_[0]->{selectExitTagColour} }
265 sub mapLabelColour
266 { $_[0]->{mapLabelColour} }
267 sub selectMapLabelColour
268 { $_[0]->{selectMapLabelColour} }
269 }
270  
271 # Package must return a true value
272 1