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

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 68 CC 4 SCAR 19.7
CC
4
Cov
0%
new
20.0
name
2.0
shortName
2.0
CRAP 7.1
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::RoomFlag
16 # An object storing settings for a single room flag used by the world model
17  
18 { package Games::Axmud::Obj::RoomFlag;
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 # Prepare a new instance of the room flag object (which stores settings for a single room
34 # flag used by the world model)
35 #
36 # Expected arguments
37 # $session - The parent GA::Session (not stored as an IV)
38 # $name - The room flag name, e.g. 'blocked_room' (max 16 characters)
39 # $customFlag - TRUE if a custom flag created by the user; FALSE for a built-in room flag
40 #
41 # Return values
42 # 'undef' on improper arguments or if $name is too long
43 # Blessed reference to the newly-created object on success
44  
45 my ($class, $session, $name, $customFlag, $check) = @_;
46  
47 # Check for improper arguments
48 if (! defined $session || ! defined $class || ! defined $name || defined $check) {
49  
50 return $axmud::CLIENT->writeImproper($class . '->new', @_);
51 }
52  
53 # Check maximum name length
54 if ((length $name) > 16) {
55  
56 return undef;
57 }
58  
59 # $customFlag should be TRUE or FALSE
60 if (! $customFlag) {
61 $customFlag = FALSE;
62 } else {
63 $customFlag = TRUE;
64 }
65  
66 # Setup
67 my $self = {
68 _objName => $name,
69 _objClass => $class,
70 _parentFile => 'worldmodel',
71 _parentWorld => $session->currentWorld->name,
72 _privFlag => FALSE, # All IVs are public
73  
74 # IVs
75 # ---
76  
77 # The room flag name, e.g. 'blocked_room' (max 16 characters)
78 name => $name,
79 # Short version of the name, usually two character (e.g. 'Bl'). Cannot be modified by
80 # the user
81 shortName => undef,
82 # A description for the room flag, e.g. 'Room is blocked'. Cannot be modified by the
83 # user
84 descrip => undef,
85  
86 # This room flag's position in the room flag priority list, with the highest-priority
87 # room flag being 1, and the lowest being a value in the 100s. Can be modified by the
88 # user (indirectly, as the ->priority in all room flag objects must be set at the
89 # same time)
90 priority => undef,
91 # The room filter to which this room flag belongs (one of the values in
92 # GA::Client->constRoomFilterList). Cannot be modified by the user
93 filter => undef,
94 # The colour with which the automapper windows draws a room with this room flag (an
95 # RGB colour tag, e.g. '#ABCDEF'; case-insensitive). Can be modified by the user
96 colour => undef,
97  
98 # Flag set to TRUE for a custom room flag, added by the user (and which can be deleted
99 # by the user); FALSE for a built-in room flag which can't be deleted
100 customFlag => $customFlag,
101 };
102  
103 # Bless the object into existence
104 bless $self, $class;
105 return $self;
106 }
107  
108 ##################
109 # Methods
110  
111 ##################
112 # Accessors - set
113  
114 ##################
115 # Accessors - get
116  
117 sub name
118 { $_[0]->{name} }
119 sub shortName
120 { $_[0]->{shortName} }
121 sub descrip
122 { $_[0]->{descrip} }
123  
124 sub priority
125 { $_[0]->{priority} }
126 sub filter
127 { $_[0]->{filter} }
128 sub colour
129 { $_[0]->{colour} }
130  
131 sub customFlag
132 { $_[0]->{customFlag} }
133 }
134  
135 # Package must return a true value
136 1