| 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::Blinker | ||
| 16 | # Blinker objects handle a blinker (a little blob of colour which is lit up, briefly, when data is | ||
| 17 | # sent to and forth from the world) | ||
| 18 | |||
| 19 | { package Games::Axmud::Obj::Blinker; | ||
| 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::Strip::ConnectInfo->createStandardBlinkers | ||
| 35 | # Creates a new blinker object handling a blinker (a little blob of colour which is lit up, | ||
| 36 | # briefly, when data is sent to and forth from the world) | ||
| 37 | # | ||
| 38 | # Expected arguments | ||
| 39 | # $number - A unique number for the blinker within the parent strip object | ||
| 40 | # (GA::Strip::ConnectInfo) | ||
| 41 | # | ||
| 42 | # Return values | ||
| 43 | # 'undef' on improper arguments | ||
| 44 | # Blessed reference to the newly-created object on success | ||
| 45 | |||
| 46 | my ($class, $number, $check) = @_; | ||
| 47 | |||
| 48 | # Local variables | ||
| 49 | my ($onColour, $offColour); | ||
| 50 | |||
| 51 | # Check for improper arguments | ||
| 52 | if (! defined $class || ! defined $number || defined $check) { | ||
| 53 | |||
| 54 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 55 | } | ||
| 56 | |||
| 57 | # Set standard blinker colours | ||
| 58 | if ($number == 0) { | ||
| 59 | $onColour = '#B966D7', # Custom purple | ||
| 60 | } elsif ($number == 1) { | ||
| 61 | $onColour = '#FFFFFF', # HTML white | ||
| 62 | } elsif ($number == 2) { | ||
| 63 | $onColour = '#EB3D3B', # Custom red | ||
| 64 | } else { | ||
| 65 | $onColour = '#FFFF00', # Fallback: HTML yellow | ||
| 66 | } | ||
| 67 | |||
| 68 | $offColour = '#A9A9A9', # HTML darkgray | ||
| 69 | |||
| 70 | # Setup | ||
| 71 | my $self = { | ||
| 72 | _objName => 'blinker_' . $number, | ||
| 73 | _objClass => $class, | ||
| 74 | _parentFile => undef, | ||
| 75 | _parentWorld => undef, | ||
| 76 | _privFlag => FALSE, # All IVs are public | ||
| 77 | |||
| 78 | # IVs | ||
| 79 | # --- | ||
| 80 | |||
| 81 | # A unique number for the blinker within the parent strip object | ||
| 82 | # (GA::Strip::ConnectInfo) | ||
| 83 | number => $number, | ||
| 84 | |||
| 85 | # The GooCanvas2 object (GooCanvas2::CanvasRect) that actually draws the blinker | ||
| 86 | canvasObj => undef, | ||
| 87 | |||
| 88 | # Flag set to TRUE if the blinker is currently ON, FALSE if it is currently OFF | ||
| 89 | onFlag => FALSE, | ||
| 90 | # The blinker's colours when 'off' and 'on' | ||
| 91 | onColour => $onColour, | ||
| 92 | offColour => $offColour, | ||
| 93 | }; | ||
| 94 | |||
| 95 | # Bless the object into existence | ||
| 96 | bless $self, $class; | ||
| 97 | |||
| 98 | return $self; | ||
| 99 | } | ||
| 100 | |||
| 101 | ################## | ||
| 102 | # Methods | ||
| 103 | |||
| 104 | ################## | ||
| 105 | # Accessors - set | ||
| 106 | |||
| 107 | ################## | ||
| 108 | # Accessors - get | ||
| 109 | |||
| 110 | sub number | ||
| 111 | { $_[0]->{number} } | ||
| 112 | |||
| 113 | sub canvasObj | ||
| 114 | { $_[0]->{canvasObj} } | ||
| 115 | |||
| 116 | sub onFlag | ||
| 117 | { $_[0]->{onFlag} } | ||
| 118 | sub onColour | ||
| 119 | { $_[0]->{onColour} } | ||
| 120 | sub offColour | ||
| 121 | { $_[0]->{offColour} } | ||
| 122 | } | ||
| 123 | |||
| 124 | # Package must return a true value | ||
| 125 | 1 |