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

Version 3.12.5 #572

Merged
merged 20 commits into from
Jan 2, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: init update
RafaelBarbosatec committed Dec 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8306415b0de8e58a4409d51d436141c2d85cdc6c
32 changes: 4 additions & 28 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
include: package:flame_lint/analysis_options.yaml

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
exclude:
- 'example/**'
44 changes: 24 additions & 20 deletions lib/base/bonfire_game.dart
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import 'package:bonfire/joystick/joystick_map_explorer.dart';
import 'package:bonfire/lighting/lighting_component.dart';
import 'package:flame/camera.dart';
// ignore: implementation_imports
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' hide Viewport;

/// Is a customGame where all magic of the Bonfire happen.
class BonfireGame extends BaseGame implements BonfireGameInterface {
@@ -21,11 +21,13 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
@override
final BuildContext context;

/// Represents the character controlled by the user in the game. Instances of this class has actions and movements ready to be used and configured.
/// Represents the character controlled by the user in the game. Instances of
/// this class has actions and movements ready to be used and configured.
@override
final Player? player;

/// The way you can draw things like life bars, stamina and settings. In another words, anything that you may add to the interface to the game.
/// The way you can draw things like life bars, stamina and settings.
/// In another words, anything that you may add to the interface to the game.
@override
final GameInterface? interface;

@@ -87,7 +89,9 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
throw Exception('Is forbiden updade camera');
}

/// variable that keeps the highest rendering priority per frame. This is used to determine the order in which to render the `interface`, `lighting` and `joystick`
/// variable that keeps the highest rendering priority per frame.
/// This is used to determine the order in which to render the `interface`,
/// `lighting` and `joystick`
int _highestPriority = 1000000;

/// Get of the _highestPriority
@@ -127,7 +131,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
),
...playerControllers ?? [],
if (interface != null) interface,
...hudComponents ?? []
...hudComponents ?? [],
],
),
world: World(
@@ -188,6 +192,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
super.update(dt);
_intervalUpdateOder.update(dt);
_intervalOprimizeTree.update(dt);
// ignore: use_if_null_to_convert_nulls_to_bools
if (!_gameMounted && camera.world?.children.isNotEmpty == true) {
_gameMounted = true;
Future.delayed(Duration.zero, _notifyGameMounted);
@@ -223,7 +228,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
@override
Iterable<ShapeHitbox> collisions({bool onlyVisible = false}) {
if (onlyVisible) {
List<ShapeHitbox> tilesCollision = [];
final tilesCollision = <ShapeHitbox>[];
map
.getRenderedTiles()
.where((element) => element.containsShapeHitbox)
@@ -274,8 +279,12 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {

@override
bool isVisibleInCamera(GameComponent c) {
if (!hasLayout) return false;
if (c.isRemoving) return false;
if (!hasLayout) {
return false;
}
if (c.isRemoving) {
return false;
}
return camera.canSee(c);
}

@@ -308,13 +317,10 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {

@override
void stopScene() {
try {
world.children
.firstWhere((value) => value is SceneBuilderComponent)
.removeFromParent();
} catch (e) {
/// Not found SceneBuilderComponent
}
world.children
.whereType<SceneBuilderComponent>()
.firstOrNull
?.removeFromParent();
}

@override
@@ -333,9 +339,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
void removeVisible(GameComponent obj) {
_visibleComponents.remove(obj);
if (obj.containsShapeHitbox) {
obj.children.query<ShapeHitbox>().forEach((element) {
_visibleCollisions.remove(element);
});
obj.children.query<ShapeHitbox>().forEach(_visibleCollisions.remove);
}
}

@@ -477,7 +481,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
FollowerWidget.removeAll();
void gameDetachComp(GameComponent c) => c.onGameDetach();
query<GameComponent>().forEach(gameDetachComp);
for (var child in camera.children) {
for (final child in camera.children) {
if (child is GameComponent) {
child.onGameDetach();
}
@@ -498,7 +502,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
return camera.viewport.add(component);
}

static _getViewPort(CameraConfig? cameraConfig) {
static Viewport? _getViewPort(CameraConfig? cameraConfig) {
if (cameraConfig?.resolution != null) {
return FixedResolutionViewport(
resolution: cameraConfig!.resolution!,
6 changes: 4 additions & 2 deletions lib/decoration/decoration.dart
Original file line number Diff line number Diff line change
@@ -33,7 +33,9 @@ class GameDecoration extends AnimatedGameObject {
super.lightingConfig,
super.renderAboveComponents,
}) {
loader?.add(AssetToLoad(sprite, (value) => this.sprite = value));
loader?.add(
AssetToLoad<Sprite>(sprite, (value) => this.sprite = value),
);
applyBleedingPixel(position: position, size: size);
}

@@ -46,7 +48,7 @@ class GameDecoration extends AnimatedGameObject {
super.lightingConfig,
super.renderAboveComponents,
}) {
loader?.add(AssetToLoad(animation, (value) => setAnimation(value)));
loader?.add(AssetToLoad<SpriteAnimation>(animation, setAnimation));
applyBleedingPixel(position: position, size: size);
}

23 changes: 15 additions & 8 deletions lib/game_interface/interface_component.dart
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@ class InterfaceComponent extends GameComponent
/// sprite that will be render when pressed
Sprite? spriteSelected;

/// Callback used to receive onTab gesture in your component. this return if is selected
/// Callback used to receive onTab gesture in your component.
/// this return if is selected
final ValueChanged<bool>? onTapComponent;
final bool selectable;
bool _lastSelected = false;
@@ -28,12 +29,16 @@ class InterfaceComponent extends GameComponent
this.selectable = false,
this.onTapComponent,
}) {
loader?.add(AssetToLoad(spriteUnselected, (value) {
this.spriteUnselected = value;
}));
loader?.add(AssetToLoad(spriteSelected, (value) {
this.spriteSelected = value;
}));
loader?.add(
AssetToLoad<Sprite>(spriteUnselected, (value) {
this.spriteUnselected = value;
}),
);
loader?.add(
AssetToLoad<Sprite>(spriteSelected, (value) {
this.spriteSelected = value;
}),
);
this.position = position;
this.size = size;
}
@@ -46,7 +51,9 @@ class InterfaceComponent extends GameComponent

@override
void onTapCancel() {
if (selectable) return;
if (selectable) {
return;
}
selected = !selected;
}

60 changes: 33 additions & 27 deletions lib/joystick/joystick_action.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:bonfire/bonfire.dart';
import 'package:bonfire/util/extensions/color_extensions.dart';
import 'package:flame/camera.dart' as camera;
import 'package:flutter/material.dart';

@@ -51,15 +52,18 @@ class JoystickAction {
this.opacityBackground = 0.5,
this.opacityKnob = 0.8,
}) {
_loader?.add(AssetToLoad(sprite, (value) {
this.sprite = value;
}));
_loader?.add(AssetToLoad(spritePressed, (value) {
this.spritePressed = value;
}));
_loader?.add(AssetToLoad(spriteBackgroundDirection, (value) {
this.spriteBackgroundDirection = value;
}));
_loader?.add(
AssetToLoad<Sprite>(sprite, (value) => this.sprite = value),
);
_loader?.add(
AssetToLoad<Sprite>(spritePressed, (value) => this.spritePressed = value),
);
_loader?.add(
AssetToLoad<Sprite>(
spriteBackgroundDirection,
(value) => this.spriteBackgroundDirection = value,
),
);
_sizeBackgroundDirection = sizeFactorBackgroundDirection * size;
_tileSize = _sizeBackgroundDirection / 2;
}
@@ -76,15 +80,15 @@ class JoystickAction {
_viewport = viewport;
_screenSize = viewport.virtualSize.clone();
_controller = controller;
double radius = size / 2;
final radius = size / 2;
final screenRect = Rect.fromLTRB(
margin.left + radius,
margin.top + radius,
_screenSize.x - margin.right - radius,
_screenSize.y - margin.bottom - radius,
);

Offset osBackground = alignment.withinRect(screenRect);
final osBackground = alignment.withinRect(screenRect);
_rect = Rect.fromCircle(
center: osBackground,
radius: radius,
@@ -102,7 +106,7 @@ class JoystickAction {
if (_rectBackgroundDirection != null && _dragging && enableDirection) {
if (spriteBackgroundDirection == null) {
_paintBackground?.let((paintBackground) {
double radiusBackground = _rectBackgroundDirection!.width / 2;
final radiusBackground = _rectBackgroundDirection!.width / 2;
c.drawCircle(
Offset(
_rectBackgroundDirection!.left + radiusBackground,
@@ -127,7 +131,7 @@ class JoystickAction {
rect,
);
} else {
double radiusAction = rect.width / 2;
final radiusAction = rect.width / 2;
c.drawCircle(
Offset(
rect.left + radiusAction,
@@ -143,36 +147,38 @@ class JoystickAction {
void update(double dt) {
if (_dragPosition == null ||
_rectBackgroundDirection == null ||
_rect == null) return;
_rect == null) {
return;
}
if (_dragging) {
double radAngle = atan2(
final radAngle = atan2(
_dragPosition!.dy - _rectBackgroundDirection!.center.dy,
_dragPosition!.dx - _rectBackgroundDirection!.center.dx,
);

// Distance between the center of joystick background & drag position
Vector2 centerPosition = _rectBackgroundDirection!.center.toVector2();
Vector2 dragPosition = _dragPosition!.toVector2();
double dist = centerPosition.distanceTo(dragPosition);
final centerPosition = _rectBackgroundDirection!.center.toVector2();
final dragPosition = _dragPosition!.toVector2();
var dist = centerPosition.distanceTo(dragPosition);

// The maximum distance for the knob position the edge of
// the background + half of its own size. The knob can wander in the
// background image, but not outside.
dist = min(dist, _tileSize);

// Calculation the knob position
double nextX = dist * cos(radAngle);
double nextY = dist * sin(radAngle);
Offset nextPoint = Offset(nextX, nextY);
final nextX = dist * cos(radAngle);
final nextY = dist * sin(radAngle);
final nextPoint = Offset(nextX, nextY);

Offset diff = Offset(
final diff = Offset(
_rectBackgroundDirection!.center.dx + nextPoint.dx,
_rectBackgroundDirection!.center.dy + nextPoint.dy,
) -
_rect!.center;
_rect = _rect!.shift(diff);

double intensity = dist / _tileSize;
final intensity = dist / _tileSize;

_controller.onJoystickAction(
JoystickActionEvent(
@@ -183,7 +189,7 @@ class JoystickAction {
),
);
} else {
Offset diff = _dragPosition! - _rect!.center;
final diff = _dragPosition! - _rect!.center;
_rect = _rect!.shift(diff);
}
}
@@ -251,19 +257,19 @@ class JoystickAction {

if (spriteBackgroundDirection == null) {
_paintBackground = Paint()
..color = color.withOpacity(opacityBackground)
..color = color.setOpacity(opacityBackground)
..style = PaintingStyle.fill;
}

if (sprite == null) {
_paintAction = Paint()
..color = color.withOpacity(opacityKnob)
..color = color.setOpacity(opacityKnob)
..style = PaintingStyle.fill;
}

if (spritePressed == null) {
_paintActionPressed = Paint()
..color = color.withOpacity(opacityBackground)
..color = color.setOpacity(opacityBackground)
..style = PaintingStyle.fill;
}

Loading