Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding extensions methods for direction enums #75

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/leap/lib/src/entities/status.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions packages/leap/lib/src/utils/direction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Loading