From 7b66f7dd29dbe7250cc9f915319a26e20d5cef35 Mon Sep 17 00:00:00 2001 From: Kurtis Melby Date: Tue, 15 Oct 2024 23:20:18 -0400 Subject: [PATCH] feat: adding extensions methods for direction enums --- packages/leap/lib/src/entities/status.dart | 6 +++--- packages/leap/lib/src/utils/direction.dart | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/leap/lib/src/entities/status.dart b/packages/leap/lib/src/entities/status.dart index e83782f..d0c0f1e 100644 --- a/packages/leap/lib/src/entities/status.dart +++ b/packages/leap/lib/src/entities/status.dart @@ -1,7 +1,6 @@ import 'package:flame/components.dart'; import 'package:flutter/foundation.dart'; import 'package:leap/leap.dart'; -import 'package:leap/src/entities/physical_entity.dart'; /// A base for building status effects pertaining to [PhysicalEntity]. Effects /// could be implemented as mixins (see [IgnoresGravity]), whereas fully custom @@ -38,11 +37,12 @@ class EntityStatus extends Component { mixin IgnoredByWorld on EntityStatus {} /// A status mixin which indicates the parent entity should not -/// be affected by gravity while the status is present. +/// be affected by gravity while the status is present +/// (via [GravityAccelerationBehavior]). mixin IgnoresGravity on EntityStatus {} /// A status mixin which indicates the parent entity should not -/// be automatically moved by its velocity. +/// be automatically moved by its velocity (via [ApplyVelocityBehavior]) mixin IgnoresVelocity on EntityStatus {} /// A status mixin which indicates the parent entity should not diff --git a/packages/leap/lib/src/utils/direction.dart b/packages/leap/lib/src/utils/direction.dart index c7883ab..cc016de 100644 --- a/packages/leap/lib/src/utils/direction.dart +++ b/packages/leap/lib/src/utils/direction.dart @@ -3,7 +3,27 @@ enum HorizontalDirection { right, } +extension HorizontalDirectionExtension on HorizontalDirection { + HorizontalDirection flip() { + if (this == HorizontalDirection.left) { + return HorizontalDirection.right; + } else { + return HorizontalDirection.left; + } + } +} + enum VerticalDirection { up, down, } + +extension VerticalDirectionExtension on VerticalDirection { + VerticalDirection flip() { + if (this == VerticalDirection.up) { + return VerticalDirection.down; + } else { + return VerticalDirection.up; + } + } +}