From 86db3af89661ee123bdc79082d5138a865cdbe81 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 14 May 2020 20:38:08 +0100 Subject: [PATCH] remove utils\Color, use new pocketmine/color class we're so close to separating protocol from core !!! --- composer.json | 1 + composer.lock | 36 ++++- src/block/utils/DyeColor.php | 2 +- src/command/defaults/ParticleCommand.php | 2 +- src/entity/effect/Effect.php | 2 +- src/entity/effect/EffectInstance.php | 2 +- src/entity/effect/EffectManager.php | 2 +- src/entity/effect/PoisonEffect.php | 2 +- src/entity/effect/VanillaEffects.php | 2 +- src/entity/projectile/SplashPotion.php | 2 +- src/item/Armor.php | 2 +- .../protocol/ClientboundMapItemDataPacket.php | 2 +- .../mcpe/protocol/types/MapDecoration.php | 2 +- src/utils/Color.php | 130 ------------------ src/world/particle/DustParticle.php | 2 +- src/world/particle/InstantEnchantParticle.php | 2 +- src/world/particle/PotionSplashParticle.php | 2 +- 17 files changed, 50 insertions(+), 145 deletions(-) delete mode 100644 src/utils/Color.php diff --git a/composer.json b/composer.json index 7bc7933ca6..06b474b941 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "pocketmine/callback-validator": "^1.0.1", "pocketmine/errorhandler": "^0.1.0", "pocketmine/uuid": "^0.1.0", + "pocketmine/color": "^0.1.0", "adhocore/json-comment": "^0.1.0", "particle/validator": "^2.3", "netresearch/jsonmapper": "^2.0", diff --git a/composer.lock b/composer.lock index e8d057667a..4009aa716c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "475fdc2cb5250b9813bc55fb87f7733c", + "content-hash": "4bd35ad045d13f81b88bef943137c79f", "packages": [ { "name": "adhocore/json-comment", @@ -465,6 +465,40 @@ "description": "Ad-hoc autoloading components used by PocketMine-MP", "time": "2020-01-31T14:26:22+00:00" }, + { + "name": "pocketmine/color", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/pmmp/Color.git", + "reference": "10f3453d0eb3eccbccad5cf58a00e42cdaef1772" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pmmp/Color/zipball/10f3453d0eb3eccbccad5cf58a00e42cdaef1772", + "reference": "10f3453d0eb3eccbccad5cf58a00e42cdaef1772", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.25", + "phpstan/phpstan-strict-rules": "^0.12.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "pocketmine\\color\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "description": "Color handling library used by PocketMine-MP and related projects", + "time": "2020-05-14T19:15:33+00:00" + }, { "name": "pocketmine/errorhandler", "version": "0.1.0", diff --git a/src/block/utils/DyeColor.php b/src/block/utils/DyeColor.php index d6f98b974c..855f8659cd 100644 --- a/src/block/utils/DyeColor.php +++ b/src/block/utils/DyeColor.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\Color; +use pocketmine\color\Color; use pocketmine\utils\EnumTrait; /** diff --git a/src/command/defaults/ParticleCommand.php b/src/command/defaults/ParticleCommand.php index 37ba888f17..ef0df87df7 100644 --- a/src/command/defaults/ParticleCommand.php +++ b/src/command/defaults/ParticleCommand.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\command\defaults; use pocketmine\block\BlockFactory; +use pocketmine\color\Color; use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\item\ItemFactory; @@ -31,7 +32,6 @@ use pocketmine\item\VanillaItems; use pocketmine\lang\TranslationContainer; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\utils\Color; use pocketmine\utils\Random; use pocketmine\utils\TextFormat; use pocketmine\world\particle\AngryVillagerParticle; diff --git a/src/entity/effect/Effect.php b/src/entity/effect/Effect.php index 8b6e757e16..a6b85ea062 100644 --- a/src/entity/effect/Effect.php +++ b/src/entity/effect/Effect.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\entity\effect; +use pocketmine\color\Color; use pocketmine\entity\Entity; use pocketmine\entity\Living; -use pocketmine\utils\Color; class Effect{ diff --git a/src/entity/effect/EffectInstance.php b/src/entity/effect/EffectInstance.php index 65f4c8ebb7..c006275e78 100644 --- a/src/entity/effect/EffectInstance.php +++ b/src/entity/effect/EffectInstance.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\entity\effect; -use pocketmine\utils\Color; +use pocketmine\color\Color; use pocketmine\utils\Limits; use function max; diff --git a/src/entity/effect/EffectManager.php b/src/entity/effect/EffectManager.php index 683c713bb6..842447ae3c 100644 --- a/src/entity/effect/EffectManager.php +++ b/src/entity/effect/EffectManager.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\entity\effect; use Ds\Set; +use pocketmine\color\Color; use pocketmine\entity\Living; use pocketmine\event\entity\EntityEffectAddEvent; use pocketmine\event\entity\EntityEffectRemoveEvent; -use pocketmine\utils\Color; use function abs; use function count; diff --git a/src/entity/effect/PoisonEffect.php b/src/entity/effect/PoisonEffect.php index 2c351981a2..5c977be27b 100644 --- a/src/entity/effect/PoisonEffect.php +++ b/src/entity/effect/PoisonEffect.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\entity\effect; +use pocketmine\color\Color; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\utils\Color; class PoisonEffect extends Effect{ diff --git a/src/entity/effect/VanillaEffects.php b/src/entity/effect/VanillaEffects.php index c714c18429..9efc7add99 100644 --- a/src/entity/effect/VanillaEffects.php +++ b/src/entity/effect/VanillaEffects.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\entity\effect; -use pocketmine\utils\Color; +use pocketmine\color\Color; use pocketmine\utils\RegistryTrait; use function assert; diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index 4c2336524d..20a087dee9 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -25,6 +25,7 @@ namespace pocketmine\entity\projectile; use pocketmine\block\BlockLegacyIds; use pocketmine\block\VanillaBlocks; +use pocketmine\color\Color; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\InstantEffect; use pocketmine\entity\Living; @@ -36,7 +37,6 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; -use pocketmine\utils\Color; use pocketmine\world\particle\PotionSplashParticle; use pocketmine\world\sound\PotionSplashSound; use function count; diff --git a/src/item/Armor.php b/src/item/Armor.php index a9b469965a..b10ae3ab93 100644 --- a/src/item/Armor.php +++ b/src/item/Armor.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\block\Block; +use pocketmine\color\Color; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\inventory\ArmorInventory; use pocketmine\item\enchantment\Enchantment; @@ -33,7 +34,6 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\player\Player; use pocketmine\utils\Binary; -use pocketmine\utils\Color; use function lcg_value; use function mt_rand; diff --git a/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php index 3b1cec6ab7..dfaa37f33f 100644 --- a/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -25,11 +25,11 @@ namespace pocketmine\network\mcpe\protocol; #include +use pocketmine\color\Color; use pocketmine\network\mcpe\protocol\serializer\NetworkBinaryStream; use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\MapDecoration; use pocketmine\network\mcpe\protocol\types\MapTrackedObject; -use pocketmine\utils\Color; use function count; #ifndef COMPILE use pocketmine\utils\Binary; diff --git a/src/network/mcpe/protocol/types/MapDecoration.php b/src/network/mcpe/protocol/types/MapDecoration.php index 564cdf4bf6..7cf2dbde25 100644 --- a/src/network/mcpe/protocol/types/MapDecoration.php +++ b/src/network/mcpe/protocol/types/MapDecoration.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types; -use pocketmine\utils\Color; +use pocketmine\color\Color; class MapDecoration{ /** @var int */ diff --git a/src/utils/Color.php b/src/utils/Color.php deleted file mode 100644 index 047b709e6d..0000000000 --- a/src/utils/Color.php +++ /dev/null @@ -1,130 +0,0 @@ -r = $r & 0xff; - $this->g = $g & 0xff; - $this->b = $b & 0xff; - $this->a = $a & 0xff; - } - - /** - * Returns the alpha (opacity) value of this colour. - */ - public function getA() : int{ - return $this->a; - } - - /** - * Retuns the red value of this colour. - */ - public function getR() : int{ - return $this->r; - } - - /** - * Returns the green value of this colour. - */ - public function getG() : int{ - return $this->g; - } - - /** - * Returns the blue value of this colour. - */ - public function getB() : int{ - return $this->b; - } - - /** - * Mixes the supplied list of colours together to produce a result colour. - * - * @param Color ...$colors - */ - public static function mix(Color $color1, Color ...$colors) : Color{ - $colors[] = $color1; - $count = count($colors); - - $a = $r = $g = $b = 0; - - foreach($colors as $color){ - $a += $color->a; - $r += $color->r; - $g += $color->g; - $b += $color->b; - } - - return new Color(intdiv($r, $count), intdiv($g, $count), intdiv($b, $count), intdiv($a, $count)); - } - - /** - * Returns a Color from the supplied RGB colour code (24-bit) - */ - public static function fromRGB(int $code) : Color{ - return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff); - } - - /** - * Returns a Color from the supplied ARGB colour code (32-bit) - */ - public static function fromARGB(int $code) : Color{ - return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff, ($code >> 24) & 0xff); - } - - /** - * Returns an ARGB 32-bit colour value. - */ - public function toARGB() : int{ - return ($this->a << 24) | ($this->r << 16) | ($this->g << 8) | $this->b; - } - - /** - * Returns a Color from the supplied RGBA colour code (32-bit) - */ - public static function fromRGBA(int $c) : Color{ - return new Color(($c >> 24) & 0xff, ($c >> 16) & 0xff, ($c >> 8) & 0xff, $c & 0xff); - } - - /** - * Returns an RGBA 32-bit colour value. - */ - public function toRGBA() : int{ - return ($this->r << 24) | ($this->g << 16) | ($this->b << 8) | $this->a; - } -} diff --git a/src/world/particle/DustParticle.php b/src/world/particle/DustParticle.php index de9aa13359..27a7d742fd 100644 --- a/src/world/particle/DustParticle.php +++ b/src/world/particle/DustParticle.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\world\particle; +use pocketmine\color\Color; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; -use pocketmine\utils\Color; class DustParticle implements Particle{ /** @var Color */ diff --git a/src/world/particle/InstantEnchantParticle.php b/src/world/particle/InstantEnchantParticle.php index 1f48004e6d..17156d1ef9 100644 --- a/src/world/particle/InstantEnchantParticle.php +++ b/src/world/particle/InstantEnchantParticle.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\world\particle; +use pocketmine\color\Color; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; -use pocketmine\utils\Color; class InstantEnchantParticle implements Particle{ /** @var Color */ diff --git a/src/world/particle/PotionSplashParticle.php b/src/world/particle/PotionSplashParticle.php index 89f9cf047e..6c7fc67c33 100644 --- a/src/world/particle/PotionSplashParticle.php +++ b/src/world/particle/PotionSplashParticle.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\world\particle; +use pocketmine\color\Color; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; -use pocketmine\utils\Color; class PotionSplashParticle implements Particle{