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.6.0 #491

Merged
merged 3 commits into from
Feb 20, 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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.6.0
- Adds param `hudComponents` in `BonfireWidget`;
- Adds `queryHud` method in `BonfireGameInterface`;
- Adds `addHud` method in `BonfireGameInterface`;
- Update Flame to `1.16.0`.

# 3.5.0
- Adds Parallax support
- Background improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BarrelShowKeyboardInput extends GameDecoration
}

@override
bool onKeyboard(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) {
bool onKeyboard(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) {
input += event.character ?? '';
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:bonfire/bonfire.dart';

class BonfireParallaxBackground extends GameBackground {
@override
void onGameMounted() {
void onMount() {
_addParallax();
super.onGameMounted();
super.onMount();
}

void _addParallax() async {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/parallax/flame/parallax_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:bonfire/bonfire.dart';

class ParallaxBackground extends GameBackground {
@override
void onGameMounted() {
void onMount() {
_addParallax();
super.onGameMounted();
super.onMount();
}

void _addParallax() async {
Expand Down
24 changes: 8 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.4.0"
version: "3.5.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -124,10 +124,10 @@ packages:
dependency: transitive
description:
name: flame
sha256: "2a2352741500ce47823dcf212f06b23e9bdb622454eab90244ee6da58e23b488"
sha256: bb42a35fa5dabdea535daebe5b020e21a2fce8192b67b7e55cd30fed86d29f69
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.16.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -238,18 +238,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -535,14 +535,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -569,4 +561,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.13.0"
flutter: ">=3.19.0"
2 changes: 1 addition & 1 deletion lib/base/base_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ abstract class BaseGame extends FlameGame

@override
KeyEventResult onKeyEvent(
RawKeyEvent event,
KeyEvent event,
Set<LogicalKeyboardKey> keysPressed,
) {
if (!enabledKeyboard) {
Expand Down
14 changes: 13 additions & 1 deletion lib/base/bonfire_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
this.player,
this.interface,
List<GameComponent>? components,
List<GameComponent>? hudComponents,
this.background,
bool debugMode = false,
this.showCollisionArea = false,
Expand Down Expand Up @@ -138,6 +139,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
keyboardConfig: keyboardConfig,
),
if (interface != null) interface,
...hudComponents ?? []
],
),
world: World(
Expand Down Expand Up @@ -312,7 +314,6 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
@override
void onDetach() {
_notifyGameDetach();
FollowerWidget.removeAll();
super.onDetach();
}

Expand Down Expand Up @@ -473,6 +474,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {
}

void _notifyGameDetach() {
FollowerWidget.removeAll();
void gameDetachComp(GameComponent c) => c.onGameDetach();
query<GameComponent>().forEach(gameDetachComp);
for (var child in camera.children) {
Expand All @@ -485,4 +487,14 @@ class BonfireGame extends BaseGame implements BonfireGameInterface {

@override
Vector2 get worldsize => map.size;

@override
Iterable<T> queryHud<T extends Component>() {
return camera.viewport.children.query<T>();
}

@override
FutureOr<void> addHud(Component component) {
return camera.viewport.add(component);
}
}
10 changes: 8 additions & 2 deletions lib/base/bonfire_game_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ abstract class BonfireGameInterface {
Iterable<T> query<T extends Component>({bool onlyVisible = false});

/// This method convert word position to screen position
Vector2 worldToScreen(Vector2 position);
Vector2 worldToScreen(Vector2 worldPosition);

/// This method convert screen position to word position
Vector2 screenToWorld(Vector2 position);
Vector2 screenToWorld(Vector2 screenPosition);

/// Used to check if a component is visible in the camera.
bool isVisibleInCamera(GameComponent c);
Expand All @@ -112,6 +112,12 @@ abstract class BonfireGameInterface {
bool moveCameraToTarget = false,
});

/// Used to get hud components.
Iterable<T> queryHud<T extends Component>();

/// Used to add hud component in the game.
FutureOr<void> addHud(Component component);

RaycastResult<ShapeHitbox>? raycast(
Ray2 ray, {
double? maxDistance,
Expand Down
9 changes: 6 additions & 3 deletions lib/base/listener_game_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,18 @@ class ListenerGameWidgetState<T extends Game>
}
}

KeyEventResult _handleKeyEvent(FocusNode focusNode, RawKeyEvent event) {
KeyEventResult _handleKeyEvent(FocusNode focusNode, KeyEvent event) {
final game = currentGame;

if (!_focusNode.hasPrimaryFocus) {
return KeyEventResult.ignored;
}

if (game is KeyboardEvents) {
return game.onKeyEvent(event, RawKeyboard.instance.keysPressed);
return game.onKeyEvent(
event,
HardwareKeyboard.instance.logicalKeysPressed,
);
}
return KeyEventResult.handled;
}
Expand Down Expand Up @@ -364,7 +367,7 @@ class ListenerGameWidgetState<T extends Game>
focusNode: _focusNode,
autofocus: widget.autofocus,
descendantsAreFocusable: true,
onKey: _handleKeyEvent,
onKeyEvent: _handleKeyEvent,
child: MouseRegion(
cursor: currentGame.mouseCursor,
child: Directionality(
Expand Down
5 changes: 1 addition & 4 deletions lib/color_filter/color_filter_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class ColorFilterComponent extends GameComponent

@override
int get priority {
if (hasGameRef) {
return LayerPriority.getColorFilterPriority(gameRef.highestPriority);
}
return super.priority;
return LayerPriority.getHudColorFilterPriority();
}

@override
Expand Down
5 changes: 1 addition & 4 deletions lib/game_interface/game_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import 'package:bonfire/bonfire.dart';
class GameInterface extends GameComponent {
@override
int get priority {
if (hasGameRef) {
return LayerPriority.getInterfacePriority(gameRef.highestPriority);
}
return super.priority;
return LayerPriority.getHudInterfacePriority();
}

/// Used to add components in your interface like a Button.
Expand Down
8 changes: 4 additions & 4 deletions lib/input/keyboard/control_by_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener {
}

@override
bool onKeyboard(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) {
bool onKeyboard(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) {
/// If the keyboard is disabled, we do not process the event
if (!keyboardConfig.enable) return false;

Expand All @@ -28,7 +28,7 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener {

/// No keyboard events, keep idle
if (!_containDirectionalPressed(keysPressed) &&
!event.repeat &&
!event.synthesized &&
!_directionalIsIdle) {
_directionalIsIdle = true;
joystickChangeDirectional(
Expand Down Expand Up @@ -57,14 +57,14 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener {
}
} else {
/// Process action events
if (event is RawKeyDownEvent) {
if (event is KeyDownEvent) {
joystickAction(
JoystickActionEvent(
id: event.logicalKey,
event: ActionEvent.DOWN,
),
);
} else if (event is RawKeyUpEvent) {
} else if (event is KeyUpEvent) {
joystickAction(
JoystickActionEvent(
id: event.logicalKey,
Expand Down
2 changes: 1 addition & 1 deletion lib/input/keyboard/keyboard_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/services.dart';
mixin KeyboardEventListener on GameComponent {
// If return 'true' this event is not relay to others components.
bool onKeyboard(
RawKeyEvent event,
KeyEvent event,
Set<LogicalKeyboardKey> keysPressed,
) {
return false;
Expand Down
12 changes: 8 additions & 4 deletions lib/input/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ mixin PlayerControllerListener {
}

abstract class PlayerController extends GameComponent {
final dynamic id;
final List<PlayerControllerListener> _observers = [];

PlayerController({this.id, PlayerControllerListener? observer}) {
if (observer != null) {
_observers.add(observer);
}
}

void joystickChangeDirectional(JoystickDirectionalEvent event) {
for (var o in _observers) {
o.onJoystickChangeDirectional(event);
Expand Down Expand Up @@ -83,10 +90,7 @@ abstract class PlayerController extends GameComponent {

@override
int get priority {
if (hasGameRef) {
return LayerPriority.getJoystickPriority(gameRef.highestPriority);
}
return super.priority;
return LayerPriority.getHudJoystickPriority();
}

@override
Expand Down
5 changes: 1 addition & 4 deletions lib/lighting/lighting_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class LightingComponent extends GameComponent implements LightingInterface {

@override
int get priority {
if (hasGameRef) {
return LayerPriority.getLightingPriority(gameRef.highestPriority);
}
return super.priority;
return LayerPriority.getHudLightingPriority();
}

Path getWheelPath(double wheelSize, double fromRadius, double toRadius) {
Expand Down
18 changes: 9 additions & 9 deletions lib/util/priority_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ class LayerPriority {
}

static int getAbovePriority(int highestPriority) {
return highestPriority + 5;
return highestPriority + 10;
}

static int getLightingPriority(int highestPriority) {
return highestPriority + 10;
static int getHudLightingPriority() {
return 10;
}

static int getColorFilterPriority(int highestPriority) {
return highestPriority + 20;
static int getHudColorFilterPriority() {
return 20;
}

static int getInterfacePriority(int highestPriority) {
return highestPriority + 30;
static int getHudInterfacePriority() {
return 30;
}

static int getJoystickPriority(int highestPriority) {
return highestPriority + 40;
static int getHudJoystickPriority() {
return 40;
}
}
8 changes: 4 additions & 4 deletions lib/util/talk/talk_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class TalkDialogState extends State<TalkDialog> {
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: RawKeyboardListener(
child: KeyboardListener(
focusNode: _focusNode,
onKey: (raw) {
if (widget.keyboardKeysToNext.isEmpty && raw is RawKeyDownEvent) {
onKeyEvent: (raw) {
if (widget.keyboardKeysToNext.isEmpty && raw is KeyDownEvent) {
// Prevent volume buttons from triggering the next dialog
if (raw.logicalKey != LogicalKeyboardKey.audioVolumeUp &&
raw.logicalKey != LogicalKeyboardKey.audioVolumeDown) {
_nextOrFinish();
}
} else if (widget.keyboardKeysToNext.contains(raw.logicalKey) &&
raw is RawKeyDownEvent) {
raw is KeyDownEvent) {
_nextOrFinish();
}
},
Expand Down
Loading
Loading