| 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::Mxp::xxx | ||
| 16 | # Objects for use during MXP-enabled sessions | ||
| 17 | |||
| 18 | { package Games::Axmud::Mxp::Dest; | ||
| 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::Session->processMxpDestElement | ||
| 34 | # Creates a new instance of the MXP destination object (which temporarily stores text tokens | ||
| 35 | # inside a <DEST>...</DEST> construction, which are sent to the specified frame when the | ||
| 36 | # construction is terminated | ||
| 37 | # | ||
| 38 | # Expected arguments | ||
| 39 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 40 | # $name - The name of the frame to which text tokens inside the <DEST>...</DEST> | ||
| 41 | # construction will be sent | ||
| 42 | # | ||
| 43 | # Return values | ||
| 44 | # 'undef' on improper arguments | ||
| 45 | # Blessed reference to the newly-created object on success | ||
| 46 | |||
| 47 | my ($class, $session, $name, $check) = @_; | ||
| 48 | |||
| 49 | # Check for improper arguments | ||
| 50 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 51 | |||
| 52 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 53 | } | ||
| 54 | |||
| 55 | # Setup | ||
| 56 | my $self = { | ||
| 57 | _objName => $name, | ||
| 58 | _objClass => $class, | ||
| 59 | _parentFile => $session->currentWorld->name, | ||
| 60 | _parentWorld => undef, | ||
| 61 | _privFlag => FALSE, # All IVs are public | ||
| 62 | |||
| 63 | # IVs | ||
| 64 | # --- | ||
| 65 | |||
| 66 | # The name of the frame to which text tokens inside the <DEST>...</DEST> construction | ||
| 67 | # will be sent | ||
| 68 | name => $name, | ||
| 69 | |||
| 70 | # The position in the frame at which the text will be inserted. 'undef' if not | ||
| 71 | # specified by the world | ||
| 72 | xPos => undef, | ||
| 73 | yPos => undef, | ||
| 74 | # Flag set to TRUE if the EOF keyword was specified (after displaying the text, erase | ||
| 75 | # the rest of the text) | ||
| 76 | eofFlag => FALSE, | ||
| 77 | # Flag set to TRUE if the EOL keyword was specified (erase the current or specified | ||
| 78 | # line) | ||
| 79 | eolFlag => FALSE, | ||
| 80 | |||
| 81 | # When the <DEST> tag is processed, the name of the frame that was being used to display | ||
| 82 | # text received from the world (set to the contents of the GA::Session IVs at that | ||
| 83 | # moment) | ||
| 84 | mxpCurrentFrame => undef, | ||
| 85 | mxpPrevFrame => undef, | ||
| 86 | }; | ||
| 87 | |||
| 88 | # Bless the object into existence | ||
| 89 | bless $self, $class; | ||
| 90 | return $self; | ||
| 91 | } | ||
| 92 | |||
| 93 | ################## | ||
| 94 | # Methods | ||
| 95 | |||
| 96 | ################## | ||
| 97 | # Accessors - set | ||
| 98 | |||
| 99 | ################## | ||
| 100 | # Accessors - get | ||
| 101 | |||
| 102 | sub name | ||
| 103 | { $_[0]->{name} } | ||
| 104 | |||
| 105 | sub xPos | ||
| 106 | { $_[0]->{xPos} } | ||
| 107 | sub yPos | ||
| 108 | { $_[0]->{yPos} } | ||
| 109 | sub eofFlag | ||
| 110 | { $_[0]->{eofFlag} } | ||
| 111 | sub eolFlag | ||
| 112 | { $_[0]->{eolFlag} } | ||
| 113 | |||
| 114 | sub mxpCurrentFrame | ||
| 115 | { $_[0]->{mxpCurrentFrame} } | ||
| 116 | sub mxpPrevFrame | ||
| 117 | { $_[0]->{mxpPrevFrame} } | ||
| 118 | } | ||
| 119 | |||
| 120 | { package Games::Axmud::Mxp::Element; | ||
| 121 | |||
| 122 | use strict; | ||
| 123 | use warnings; | ||
| 124 | # use diagnostics; | ||
| 125 | |||
| 126 | use Glib qw(TRUE FALSE); | ||
| 127 | |||
| 128 | our @ISA = qw(Games::Axmud); | ||
| 129 | |||
| 130 | ################## | ||
| 131 | # Constructors | ||
| 132 | |||
| 133 | sub new { | ||
| 134 | |||
| 135 | # Called by GA::Session->processMxpElement | ||
| 136 | # Creates a new instance of the MXP element object | ||
| 137 | # | ||
| 138 | # Expected arguments | ||
| 139 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 140 | # $name - A unique string name for this MXP element (we'll assume that it has | ||
| 141 | # already been checked for validity; should be lower case) | ||
| 142 | # | ||
| 143 | # Return values | ||
| 144 | # 'undef' on improper arguments | ||
| 145 | # Blessed reference to the newly-created object on success | ||
| 146 | |||
| 147 | my ($class, $session, $name, $check) = @_; | ||
| 148 | |||
| 149 | # Check for improper arguments | ||
| 150 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 151 | |||
| 152 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 153 | } | ||
| 154 | |||
| 155 | # Setup | ||
| 156 | my $self = { | ||
| 157 | _objName => $name, | ||
| 158 | _objClass => $class, | ||
| 159 | _parentFile => $session->currentWorld->name, | ||
| 160 | _parentWorld => undef, | ||
| 161 | _privFlag => FALSE, # All IVs are public | ||
| 162 | |||
| 163 | # IVs | ||
| 164 | # --- | ||
| 165 | |||
| 166 | # The (unique) element name | ||
| 167 | name => $name, | ||
| 168 | # The element definition (A string comprising certain MXP tags, possibly separated by | ||
| 169 | # whitespace; 'undef' if not set) | ||
| 170 | defnArg => undef, | ||
| 171 | # A list of tags in ->defnArg (if set), in the order they were first specified; e.g. | ||
| 172 | # if ->defnArg is '<COLOR red><B>', then the list is ('<COLOUR red>', '<B>') | ||
| 173 | defnList => [], | ||
| 174 | |||
| 175 | # The attribute list (a string), ATT=... ('undef' if not set) | ||
| 176 | # NB If attributes are modified with an <!ATTLIST> tag, this IV is not updated | ||
| 177 | attArg => undef, | ||
| 178 | # An ordered list of attribute names, in the order in which they were declared | ||
| 179 | attList => [], | ||
| 180 | # A hash of attributes and their values, in the form | ||
| 181 | # $attHash{attribute_name} = default_value | ||
| 182 | # ...where 'default_value' is an empty string if the attribute has no default value | ||
| 183 | attHash => {}, | ||
| 184 | |||
| 185 | # The user-defined line tag, TAG=... ('undef' if not set) | ||
| 186 | tagArg => undef, | ||
| 187 | # The flag argument, FLAG=... ('undef' if not set) | ||
| 188 | flagArg => undef, | ||
| 189 | # The open argument, OPEN (set to FALSE for 'secure' tags, TRUE for 'open' tags; | ||
| 190 | # elements are secure by default) | ||
| 191 | openFlag => FALSE, | ||
| 192 | # The empty argument, EMPTY (set to FALSE or TRUE) | ||
| 193 | emptyFlag => FALSE, | ||
| 194 | }; | ||
| 195 | |||
| 196 | # Bless the object into existence | ||
| 197 | bless $self, $class; | ||
| 198 | return $self; | ||
| 199 | } | ||
| 200 | |||
| 201 | ################## | ||
| 202 | # Methods | ||
| 203 | |||
| 204 | sub setDefn { | ||
| 205 | |||
| 206 | # Called by GA::Session->processMxpElement, when processing an element in the form | ||
| 207 | # <!ELEMENT element_name [definition] ... > | ||
| 208 | # If [definition] is specified, it is stored in this object in 2 IVs. This function handles | ||
| 209 | # the setting of those IVs | ||
| 210 | # | ||
| 211 | # Expected arguments | ||
| 212 | # $session - The calling function's GA::Session | ||
| 213 | # $defnArg - The definition argument, e.g. '<COLOR RED><B>' | ||
| 214 | # | ||
| 215 | # Return values | ||
| 216 | # 'undef' on improper arguments or if $defnArg contains characters outside <...> tags | ||
| 217 | # 1 otherwise | ||
| 218 | |||
| 219 | my ($self, $session, $defnArg, $check) = @_; | ||
| 220 | |||
| 221 | # Local variables | ||
| 222 | my ( | ||
| 223 | $origDefnArg, | ||
| 224 | @defnList, | ||
| 225 | ); | ||
| 226 | |||
| 227 | # Check for improper arguments | ||
| 228 | if (! defined $session || ! defined $defnArg || defined $check) { | ||
| 229 | |||
| 230 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setDefn', @_); | ||
| 231 | } | ||
| 232 | |||
| 233 | # $defnArg should consist of one or more <...> tags, possibly separated by whitespace | ||
| 234 | # Extract each tag in turn | ||
| 235 | $origDefnArg = $defnArg; | ||
| 236 | do { | ||
| 237 | |||
| 238 | my ($posn, $token, $element); | ||
| 239 | |||
| 240 | $posn = index($defnArg, '<'); | ||
| 241 | if ($posn == -1) { | ||
| 242 | |||
| 243 | # Unexpected text in the macro expansion (i.e. not inside <...>) | ||
| 244 | return undef; | ||
| 245 | |||
| 246 | } else { | ||
| 247 | |||
| 248 | $token = $session->extractMxpPuebloElement(substr($defnArg, $posn)); | ||
| 249 | if (! defined $token || $token eq '') { | ||
| 250 | |||
| 251 | # Invalid element | ||
| 252 | return undef; | ||
| 253 | |||
| 254 | } else { | ||
| 255 | |||
| 256 | # Remove the <...> tag from $defnArg | ||
| 257 | $element = substr($defnArg, $posn, length($token)); | ||
| 258 | push (@defnList, $element); | ||
| 259 | |||
| 260 | substr($defnArg, $posn, length($token), ''); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | # Trim leading and trailing whitespace, allowing $defnArg to be an empty string if we've | ||
| 265 | # removed all elements | ||
| 266 | $defnArg = $axmud::CLIENT->trimWhitespace($defnArg); | ||
| 267 | |||
| 268 | } until (! $defnArg); | ||
| 269 | |||
| 270 | # Update IVs | ||
| 271 | $self->ivPoke('defnArg', $origDefnArg); | ||
| 272 | $self->ivPoke('defnList', @defnList); | ||
| 273 | |||
| 274 | return 1; | ||
| 275 | } | ||
| 276 | |||
| 277 | sub setAttList { | ||
| 278 | |||
| 279 | # Called by GA::Session->processMxpElement, when processing an element in the form | ||
| 280 | # <!ELEMENT element_name [ATT=attribute_list] ... > | ||
| 281 | # | ||
| 282 | # If [ATT=attribute_list] is specified, it is stored in this object in 2 IVs. This function | ||
| 283 | # handles the setting of those IVs | ||
| 284 | # | ||
| 285 | # Expected arguments | ||
| 286 | # $session - The calling function's GA::Session | ||
| 287 | # $attListArg - The attribute list (a string), e.g. 'col=red', | ||
| 288 | # 'color=red background=white flags' | ||
| 289 | # | ||
| 290 | # Return values | ||
| 291 | # 'undef' on improper arguments or if the attribute list is invalid (i.e. malformed) | ||
| 292 | # 1 otherwise | ||
| 293 | |||
| 294 | my ($self, $session, $attListArg, $check) = @_; | ||
| 295 | |||
| 296 | # Local variables | ||
| 297 | my ( | ||
| 298 | $string, | ||
| 299 | @newList, | ||
| 300 | %newHash, | ||
| 301 | ); | ||
| 302 | |||
| 303 | # Check for improper arguments | ||
| 304 | if (! defined $session || ! defined $attListArg || defined $check) { | ||
| 305 | |||
| 306 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setAttList', @_); | ||
| 307 | } | ||
| 308 | |||
| 309 | # Items can be in the form 'name=value', where 'value' is the attribute's default value, or | ||
| 310 | # in the form 'name', for attributes with no default value | ||
| 311 | # Each argument can be single-quote or double-quoted; if not, the attribute value can be | ||
| 312 | # single quoted or double quoted (following the usual MXP rules) | ||
| 313 | $string = $attListArg; | ||
| 314 | do { | ||
| 315 | |||
| 316 | my ($attName, $attValue); | ||
| 317 | |||
| 318 | ($string, $attName, $attValue) = $session->extractMxpArgument($string); | ||
| 319 | if (! defined $string) { | ||
| 320 | |||
| 321 | # Invalid argument | ||
| 322 | return undef; | ||
| 323 | |||
| 324 | } else { | ||
| 325 | |||
| 326 | # If the argument is not in the form 'argument_name=argument_value', then the | ||
| 327 | # attribute's default value is an empty string | ||
| 328 | if (! defined $attValue) { | ||
| 329 | |||
| 330 | $attValue = ''; | ||
| 331 | } | ||
| 332 | |||
| 333 | push (@newList, $attName); | ||
| 334 | $newHash{$attName} = $attValue; | ||
| 335 | |||
| 336 | # There must be whitepsace between this argument, and the next one (if any) | ||
| 337 | if ($string && $string =~ m/^\S/) { | ||
| 338 | |||
| 339 | return undef; | ||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | } until (! $string); | ||
| 344 | |||
| 345 | # Attributes extracted; update IVs | ||
| 346 | $self->ivPoke('attArg', $attListArg); | ||
| 347 | $self->ivPoke('attList', @newList); | ||
| 348 | $self->ivPoke('attHash', %newHash); | ||
| 349 | |||
| 350 | return 1; | ||
| 351 | } | ||
| 352 | |||
| 353 | ################## | ||
| 354 | # Accessors - set | ||
| 355 | |||
| 356 | ################## | ||
| 357 | # Accessors - get | ||
| 358 | |||
| 359 | sub name | ||
| 360 | { $_[0]->{name} } | ||
| 361 | sub defnArg | ||
| 362 | { $_[0]->{defnArg} } | ||
| 363 | sub defnList | ||
| 364 | { my $self = shift; return @{$self->{defnList}}; } | ||
| 365 | |||
| 366 | sub attArg | ||
| 367 | { $_[0]->{attArg} } | ||
| 368 | sub attList | ||
| 369 | { my $self = shift; return @{$self->{attList}}; } | ||
| 370 | sub attHash | ||
| 371 | { my $self = shift; return %{$self->{attHash}}; } | ||
| 372 | |||
| 373 | sub tagArg | ||
| 374 | { $_[0]->{tagArg} } | ||
| 375 | sub flagArg | ||
| 376 | { $_[0]->{flagArg} } | ||
| 377 | sub openFlag | ||
| 378 | { $_[0]->{openFlag} } | ||
| 379 | sub emptyFlag | ||
| 380 | { $_[0]->{emptyFlag} } | ||
| 381 | } | ||
| 382 | |||
| 383 | { package Games::Axmud::Mxp::Entity; | ||
| 384 | |||
| 385 | use strict; | ||
| 386 | use warnings; | ||
| 387 | # use diagnostics; | ||
| 388 | |||
| 389 | use Glib qw(TRUE FALSE); | ||
| 390 | |||
| 391 | our @ISA = qw(Games::Axmud); | ||
| 392 | |||
| 393 | ################## | ||
| 394 | # Constructors | ||
| 395 | |||
| 396 | sub new { | ||
| 397 | |||
| 398 | # Called by GA::Session->processMxpElement | ||
| 399 | # Creates a new instance of the MXP entity object | ||
| 400 | # | ||
| 401 | # Expected arguments | ||
| 402 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 403 | # $name - A unique string name for this MXP entity (unlike element names, entity | ||
| 404 | # names are case-sensitive) | ||
| 405 | # | ||
| 406 | # Return values | ||
| 407 | # 'undef' on improper arguments | ||
| 408 | # Blessed reference to the newly-created object on success | ||
| 409 | |||
| 410 | my ($class, $session, $name, $check) = @_; | ||
| 411 | |||
| 412 | # Check for improper arguments | ||
| 413 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 414 | |||
| 415 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 416 | } | ||
| 417 | |||
| 418 | # Setup | ||
| 419 | my $self = { | ||
| 420 | _objName => $name, | ||
| 421 | _objClass => $class, | ||
| 422 | _parentFile => $session->currentWorld->name, | ||
| 423 | _parentWorld => undef, | ||
| 424 | _privFlag => FALSE, # All IVs are public | ||
| 425 | |||
| 426 | # IVs | ||
| 427 | # --- | ||
| 428 | |||
| 429 | # The (unique) entity name | ||
| 430 | name => $name, | ||
| 431 | # The entity's value (a string, set to 'undef' until the <!ELEMENT> tag has been | ||
| 432 | # processed) | ||
| 433 | value => undef, | ||
| 434 | |||
| 435 | # The description string, DESC=... ('undef' if not set) | ||
| 436 | descArg => undef, | ||
| 437 | # The private argument, PRIVATE (set to FALSE or TRUE) | ||
| 438 | privateFlag => FALSE, | ||
| 439 | # The publish argument, PUBLISH (set to FALSE or TRUE) | ||
| 440 | publishFlag => FALSE, | ||
| 441 | }; | ||
| 442 | |||
| 443 | # Bless the object into existence | ||
| 444 | bless $self, $class; | ||
| 445 | return $self; | ||
| 446 | } | ||
| 447 | |||
| 448 | ################## | ||
| 449 | # Methods | ||
| 450 | |||
| 451 | ################## | ||
| 452 | # Accessors - set | ||
| 453 | |||
| 454 | ################## | ||
| 455 | # Accessors - get | ||
| 456 | |||
| 457 | sub name | ||
| 458 | { $_[0]->{name} } | ||
| 459 | sub value | ||
| 460 | { $_[0]->{value} } | ||
| 461 | |||
| 462 | sub descArg | ||
| 463 | { $_[0]->{descArg} } | ||
| 464 | sub privateFlag | ||
| 465 | { $_[0]->{privateFlag} } | ||
| 466 | sub publishFlag | ||
| 467 | { $_[0]->{publishFlag} } | ||
| 468 | } | ||
| 469 | |||
| 470 | { package Games::Axmud::Mxp::Filter; | ||
| 471 | |||
| 472 | use strict; | ||
| 473 | use warnings; | ||
| 474 | # use diagnostics; | ||
| 475 | |||
| 476 | use Glib qw(TRUE FALSE); | ||
| 477 | |||
| 478 | our @ISA = qw(Games::Axmud); | ||
| 479 | |||
| 480 | ################## | ||
| 481 | # Constructors | ||
| 482 | |||
| 483 | sub new { | ||
| 484 | |||
| 485 | # Called by GA::Session->processMxpFilterElement | ||
| 486 | # Creates a new instance of the MXP file filter object | ||
| 487 | # | ||
| 488 | # Expected arguments | ||
| 489 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 490 | # $src - The source file extension, e.g. 'gff' | ||
| 491 | # $dest - The destination file extension, after the image/sound file is converted | ||
| 492 | # to a file type that Axmud supports, e.g. 'gif' | ||
| 493 | # $name - The name of the plugin which contains the conversion code | ||
| 494 | # $proc - An optional numerical parameter used to support multiple conversions, as | ||
| 495 | # needed (see the MXP spec). Default value is 0 | ||
| 496 | # | ||
| 497 | # Return values | ||
| 498 | # 'undef' on improper arguments | ||
| 499 | # Blessed reference to the newly-created object on success | ||
| 500 | |||
| 501 | my ($class, $session, $src, $dest, $name, $proc, $check) = @_; | ||
| 502 | |||
| 503 | # Check for improper arguments | ||
| 504 | if ( | ||
| 505 | ! defined $class || ! defined $session || ! defined $src || ! defined $dest | ||
| 506 | || ! defined $name || ! defined $proc || defined $check | ||
| 507 | ) { | ||
| 508 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 509 | } | ||
| 510 | |||
| 511 | # Setup | ||
| 512 | my $self = { | ||
| 513 | _objName => $name, | ||
| 514 | _objClass => $class, | ||
| 515 | _parentFile => $session->currentWorld->name, | ||
| 516 | _parentWorld => undef, | ||
| 517 | _privFlag => FALSE, # All IVs are public | ||
| 518 | |||
| 519 | # IVs | ||
| 520 | # --- | ||
| 521 | |||
| 522 | # The source file extension, e.g. 'gff' | ||
| 523 | src => $src, | ||
| 524 | # The destination file extension, after the image/sound file is converted to a file type | ||
| 525 | # that Axmud supports, e.g. 'gif' | ||
| 526 | dest => $dest, | ||
| 527 | # The name of the plugin which contains the conversion code | ||
| 528 | name => $name, | ||
| 529 | # An optional numerical parameter used to support multiple conversions, as needed (see | ||
| 530 | # the MXP spec). Default value is 0 | ||
| 531 | proc => $proc, | ||
| 532 | }; | ||
| 533 | |||
| 534 | # Bless the object into existence | ||
| 535 | bless $self, $class; | ||
| 536 | return $self; | ||
| 537 | } | ||
| 538 | |||
| 539 | ################## | ||
| 540 | # Methods | ||
| 541 | |||
| 542 | ################## | ||
| 543 | # Accessors - set | ||
| 544 | |||
| 545 | ################## | ||
| 546 | # Accessors - get | ||
| 547 | |||
| 548 | sub src | ||
| 549 | { $_[0]->{src} } | ||
| 550 | sub dest | ||
| 551 | { $_[0]->{dest} } | ||
| 552 | sub name | ||
| 553 | { $_[0]->{name} } | ||
| 554 | sub proc | ||
| 555 | { $_[0]->{proc} } | ||
| 556 | } | ||
| 557 | |||
| 558 | { package Games::Axmud::Mxp::Frame; | ||
| 559 | |||
| 560 | use strict; | ||
| 561 | use warnings; | ||
| 562 | # use diagnostics; | ||
| 563 | |||
| 564 | use Glib qw(TRUE FALSE); | ||
| 565 | |||
| 566 | our @ISA = qw(Games::Axmud); | ||
| 567 | |||
| 568 | ################## | ||
| 569 | # Constructors | ||
| 570 | |||
| 571 | sub new { | ||
| 572 | |||
| 573 | # Called by GA::Session->processMxpFrameElement | ||
| 574 | # Creates a new instance of the MXP frame object | ||
| 575 | # | ||
| 576 | # Expected arguments | ||
| 577 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 578 | # $name - A unique string name for this MXP frame (the MXP spec doesn't say if it's | ||
| 579 | # case-sensitive or not, so Axmud will treat them as case-senstitive) | ||
| 580 | # | ||
| 581 | # Return values | ||
| 582 | # 'undef' on improper arguments | ||
| 583 | # Blessed reference to the newly-created object on success | ||
| 584 | |||
| 585 | my ($class, $session, $name, $check) = @_; | ||
| 586 | |||
| 587 | # Check for improper arguments | ||
| 588 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 589 | |||
| 590 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 591 | } | ||
| 592 | |||
| 593 | # Setup | ||
| 594 | my $self = { | ||
| 595 | _objName => $name, | ||
| 596 | _objClass => $class, | ||
| 597 | _parentFile => $session->currentWorld->name, | ||
| 598 | _parentWorld => undef, | ||
| 599 | _privFlag => FALSE, # All IVs are public | ||
| 600 | |||
| 601 | # IVs | ||
| 602 | # --- | ||
| 603 | |||
| 604 | # The (unique) frame name (the MXP spec doesn't say if it's case-sensitive or not, so | ||
| 605 | # Axmud will treat them as case-sensitive) | ||
| 606 | name => $name, | ||
| 607 | # The frame title. If set to 'undef' (default), $self->name is used as the frame title | ||
| 608 | title => undef, | ||
| 609 | |||
| 610 | # MXP frames are implemented as pane objects (either inside the session's 'main' window, | ||
| 611 | # or inside a Frame task window) | ||
| 612 | # The pane object for this frame | ||
| 613 | paneObj => undef, | ||
| 614 | # In case the pane has multiple tabs (unlikely, but possible), the tab used by this | ||
| 615 | # frame (a tab object, GA::Obj::Tab) | ||
| 616 | tabObj => undef, | ||
| 617 | # The textview object for this tab | ||
| 618 | textViewObj => undef, | ||
| 619 | |||
| 620 | # Flag set to TRUE if the frame is internal to the current MUD window (for Axmud, always | ||
| 621 | # the 'main' window); set to FALSE if a floating frame must be created (using the | ||
| 622 | # Frame task) | ||
| 623 | internalFlag => FALSE, | ||
| 624 | # If ->internalFlag is TRUE, the alignment of the frame in the 'main' window - should be | ||
| 625 | # 'left', 'right', 'bottom' or 'top' (default) | ||
| 626 | align => 'top', | ||
| 627 | |||
| 628 | # If ->internalFlag is FALSE, the Frame task object whose task window is used for this | ||
| 629 | # frame ('undef' if ->internalFlag is TRUE) | ||
| 630 | taskObj => undef, | ||
| 631 | # If ->internalFlag is FALSE, the position of the Frame task window (ignored if | ||
| 632 | # ->internalFlag is TRUE) | ||
| 633 | # The coordinate of the left side of the frame - a percentage (ends in %), a number of | ||
| 634 | # character widths (ends in c) or a number of pixels. If a negative number is used, | ||
| 635 | # the value is relative to the right side of the screen, rather than the left. The | ||
| 636 | # character spacing uses the width of the character X. | ||
| 637 | left => 0, | ||
| 638 | # The coordinate of the top of the frame. Same syntax as for ->left. If a negative | ||
| 639 | # number is used, the value is relative to the bottom of the screen, rather than the | ||
| 640 | # right. The character spacing uses the height of the character X. | ||
| 641 | top => 0, | ||
| 642 | # The width of the frame. Same syntax as for ->left. A percentage refers to the | ||
| 643 | # percentage of the screen width. The MXP spec doesn't give a default value, so we'll | ||
| 644 | # use our own. | ||
| 645 | width => '50%', | ||
| 646 | # The height of the frame. Same syntax as for ->top. A percentage refers to the | ||
| 647 | # percentage of the screen height. | ||
| 648 | height => '50%', | ||
| 649 | |||
| 650 | # Flag set to TRUE if the frame is allowed to scroll; set to FALSE (default) if the | ||
| 651 | # frame isn't allowed to scroll | ||
| 652 | scrollingFlag => FALSE, | ||
| 653 | # Flag set to TRUE if the frame is forced to 'stay on top' of the 'main' window. Ignored | ||
| 654 | # if ->internalFlag is TRUE | ||
| 655 | floatingFlag => FALSE, | ||
| 656 | }; | ||
| 657 | |||
| 658 | # Bless the object into existence | ||
| 659 | bless $self, $class; | ||
| 660 | return $self; | ||
| 661 | } | ||
| 662 | |||
| 663 | ################## | ||
| 664 | # Methods | ||
| 665 | |||
| 666 | ################## | ||
| 667 | # Accessors - set | ||
| 668 | |||
| 669 | ################## | ||
| 670 | # Accessors - get | ||
| 671 | |||
| 672 | sub name | ||
| 673 | { $_[0]->{name} } | ||
| 674 | sub title | ||
| 675 | { $_[0]->{title} } | ||
| 676 | |||
| 677 | sub paneObj | ||
| 678 | { $_[0]->{paneObj} } | ||
| 679 | sub tabObj | ||
| 680 | { $_[0]->{tabObj} } | ||
| 681 | sub textViewObj | ||
| 682 | { $_[0]->{textViewObj} } | ||
| 683 | |||
| 684 | sub internalFlag | ||
| 685 | { $_[0]->{internalFlag} } | ||
| 686 | sub align | ||
| 687 | { $_[0]->{align} } | ||
| 688 | |||
| 689 | sub taskObj | ||
| 690 | { $_[0]->{taskObj} } | ||
| 691 | sub left | ||
| 692 | { $_[0]->{left} } | ||
| 693 | sub top | ||
| 694 | { $_[0]->{top} } | ||
| 695 | sub width | ||
| 696 | { $_[0]->{width} } | ||
| 697 | sub height | ||
| 698 | { $_[0]->{height} } | ||
| 699 | |||
| 700 | sub scrollingFlag | ||
| 701 | { $_[0]->{scrollingFlag} } | ||
| 702 | sub floatingFlag | ||
| 703 | { $_[0]->{floatingFlag} } | ||
| 704 | } | ||
| 705 | |||
| 706 | { package Games::Axmud::Mxp::StackObj; | ||
| 707 | |||
| 708 | use strict; | ||
| 709 | use warnings; | ||
| 710 | # use diagnostics; | ||
| 711 | |||
| 712 | use Glib qw(TRUE FALSE); | ||
| 713 | |||
| 714 | our @ISA = qw(Games::Axmud); | ||
| 715 | |||
| 716 | ################## | ||
| 717 | # Constructors | ||
| 718 | |||
| 719 | sub new { | ||
| 720 | |||
| 721 | # Called by GA::Obj::TextView->createMxpStackObj | ||
| 722 | # Creates a new instance of the MXP stack object, which stores the current state of the | ||
| 723 | # textview object's ->mxpModalStackHash, just before it is updated | ||
| 724 | # Storing old copies of the hash allowing text attributes (colours, fonts etc) to be nested | ||
| 725 | # | ||
| 726 | # Expected arguments | ||
| 727 | # $session - The calling GA::Session (not stored as an IV) | ||
| 728 | # $keyword - The keyword of the corresponding MXP tag, e.g. 'B', 'FONT', etc | ||
| 729 | # | ||
| 730 | # Optional arguments | ||
| 731 | # %stackHash - A copy of the calling textview object's ->->mxpModalStackHash (may be an | ||
| 732 | # empty hash) | ||
| 733 | # | ||
| 734 | # Return values | ||
| 735 | # 'undef' on improper arguments | ||
| 736 | # Blessed reference to the newly-created object on success | ||
| 737 | |||
| 738 | my ($class, $session, $keyword, %stackHash) = @_; | ||
| 739 | |||
| 740 | # Check for improper arguments | ||
| 741 | if (! defined $class || ! defined $session || ! defined $keyword) { | ||
| 742 | |||
| 743 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 744 | } | ||
| 745 | |||
| 746 | # Setup | ||
| 747 | my $self = { | ||
| 748 | _objName => $keyword, | ||
| 749 | _objClass => $class, | ||
| 750 | _parentFile => $session->currentWorld->name, | ||
| 751 | _parentWorld => undef, | ||
| 752 | _privFlag => FALSE, # All IVs are public | ||
| 753 | |||
| 754 | # IVs | ||
| 755 | # --- | ||
| 756 | |||
| 757 | # The keyword of the corresponding MXP tag, e.g. 'B', 'FONT', etc | ||
| 758 | keyword => $keyword, | ||
| 759 | # A copy of GA::Obj::TextViewObj->mxpModalStackHash, at the time the MXP tag was | ||
| 760 | # encountered | ||
| 761 | stackHash => {%stackHash}, | ||
| 762 | }; | ||
| 763 | |||
| 764 | # Bless the object into existence | ||
| 765 | bless $self, $class; | ||
| 766 | |||
| 767 | return $self; | ||
| 768 | } | ||
| 769 | |||
| 770 | ################## | ||
| 771 | # Methods | ||
| 772 | |||
| 773 | ################## | ||
| 774 | # Accessors - set | ||
| 775 | |||
| 776 | ################## | ||
| 777 | # Accessors - get | ||
| 778 | |||
| 779 | sub keyword | ||
| 780 | { $_[0]->{keyword} } | ||
| 781 | sub stackHash | ||
| 782 | { my $self = shift; return %{$self->{stackHash}}; } | ||
| 783 | } | ||
| 784 | |||
| 785 | { package Games::Axmud::Mxp::Var; | ||
| 786 | |||
| 787 | use strict; | ||
| 788 | use warnings; | ||
| 789 | # use diagnostics; | ||
| 790 | |||
| 791 | use Glib qw(TRUE FALSE); | ||
| 792 | |||
| 793 | our @ISA = qw(Games::Axmud); | ||
| 794 | |||
| 795 | ################## | ||
| 796 | # Constructors | ||
| 797 | |||
| 798 | sub new { | ||
| 799 | |||
| 800 | # Called by GA::Session->processMxpElement | ||
| 801 | # Creates a new instance of the MXP variable object (which temporarily stores arguments | ||
| 802 | # in a <V>...</V> construction, until the code is ready to modify the GA::Mxp::Entity | ||
| 803 | # object, at which time this object's IVs are copied to the entity object) | ||
| 804 | # | ||
| 805 | # Expected arguments | ||
| 806 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 807 | # $name - The name of the entity object which this <V>...</V> construction will | ||
| 808 | # modify | ||
| 809 | # | ||
| 810 | # Return values | ||
| 811 | # 'undef' on improper arguments | ||
| 812 | # Blessed reference to the newly-created object on success | ||
| 813 | |||
| 814 | my ($class, $session, $name, $check) = @_; | ||
| 815 | |||
| 816 | # Check for improper arguments | ||
| 817 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 818 | |||
| 819 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 820 | } | ||
| 821 | |||
| 822 | # Setup | ||
| 823 | my $self = { | ||
| 824 | _objName => $name, | ||
| 825 | _objClass => $class, | ||
| 826 | _parentFile => $session->currentWorld->name, | ||
| 827 | _parentWorld => undef, | ||
| 828 | _privFlag => FALSE, # All IVs are public | ||
| 829 | |||
| 830 | # IVs | ||
| 831 | # --- | ||
| 832 | |||
| 833 | # The name of the corresponding GA::Mxp::Entity object | ||
| 834 | name => $name, | ||
| 835 | # Accumulated text tokens between matching <V>...</V> tags | ||
| 836 | value => '', | ||
| 837 | |||
| 838 | # Optional arguments from the <V...> tag | ||
| 839 | # The description string, DESC=... ('undef' if not set) | ||
| 840 | descArg => undef, | ||
| 841 | # The private argument, PRIVATE (set to FALSE or TRUE) | ||
| 842 | privateFlag => FALSE, | ||
| 843 | # The publish argument, PUBLISH (set to FALSE or TRUE) | ||
| 844 | publishFlag => FALSE, | ||
| 845 | # The delete argument, DELETE (set to FALSE or TRUE) | ||
| 846 | deleteFlag => FALSE, | ||
| 847 | # The add argument, ADD (set to FALSE or TRUE) | ||
| 848 | addFlag => FALSE, | ||
| 849 | # The remove argument, REMOVE (set to FALSE or TRUE) | ||
| 850 | removeFlag => FALSE, | ||
| 851 | }; | ||
| 852 | |||
| 853 | # Bless the object into existence | ||
| 854 | bless $self, $class; | ||
| 855 | return $self; | ||
| 856 | } | ||
| 857 | |||
| 858 | ################## | ||
| 859 | # Methods | ||
| 860 | |||
| 861 | ################## | ||
| 862 | # Accessors - set | ||
| 863 | |||
| 864 | ################## | ||
| 865 | # Accessors - get | ||
| 866 | |||
| 867 | sub name | ||
| 868 | { $_[0]->{name} } | ||
| 869 | sub value | ||
| 870 | { $_[0]->{value} } | ||
| 871 | |||
| 872 | sub descArg | ||
| 873 | { $_[0]->{descArg} } | ||
| 874 | sub privateFlag | ||
| 875 | { $_[0]->{privateFlag} } | ||
| 876 | sub publishFlag | ||
| 877 | { $_[0]->{publishFlag} } | ||
| 878 | sub deleteFlag | ||
| 879 | { $_[0]->{deleteFlag} } | ||
| 880 | sub addFlag | ||
| 881 | { $_[0]->{addFlag} } | ||
| 882 | sub removeFlag | ||
| 883 | { $_[0]->{removeFlag} } | ||
| 884 | } | ||
| 885 | |||
| 886 | # Package must return a true value | ||
| 887 | 1 |