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.2 #497

Merged
merged 4 commits into from
Mar 23, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.6.2
- standardizes 'onLoad' method.
- adds 'size' in 'EmptyWorldMap'.
- adds mixin 'FlipRender'.

# 3.6.1
- Adds `moveAlongThePath` method in `PathFinding` mixin.
- Bugfix in `Vision` mixin.
Expand Down
5 changes: 2 additions & 3 deletions lib/background/background_image_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class BackgroundImageGame extends GameBackground with UseSprite {
}

@override
Future<void>? onLoad() async {
Future<void> onLoad() async {
await super.onLoad();
camera = gameRef.camera;
sprite = await MapAssetsManager.getFutureSprite(imagePath);
_parallaxOffset = Vector2(offset.x * factor, offset.y * factor);
Expand All @@ -64,8 +65,6 @@ class BackgroundImageGame extends GameBackground with UseSprite {
sprite!.image.width * factor,
sprite!.image.height * factor,
);

return super.onLoad();
}

@override
Expand Down
3 changes: 3 additions & 0 deletions lib/base/game_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ abstract class GameComponent extends PositionComponent
super.onMount();
}

@override
Future<void> onLoad() async => super.onLoad();

void onGameDetach() {}
void onGameMounted() {}
}
1 change: 1 addition & 0 deletions lib/bonfire.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export 'package:bonfire/mixins/use_barlife.dart';
export 'package:bonfire/mixins/use_sprite.dart';
export 'package:bonfire/mixins/use_sprite_animation.dart';
export 'package:bonfire/mixins/vision.dart';
export 'package:bonfire/mixins/flip_render.dart';
export 'package:bonfire/npc/ally/ally.dart';
export 'package:bonfire/npc/enemy/enemy.dart';
export 'package:bonfire/npc/npc.dart';
Expand Down
8 changes: 5 additions & 3 deletions lib/map/empty_map.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:bonfire/map/world_map.dart';
import 'package:bonfire/bonfire.dart';

class EmptyWorldMap extends WorldMap {
EmptyWorldMap({double tileSizeToUpdate = 0})
: super([], tileSizeToUpdate: tileSizeToUpdate);
EmptyWorldMap({double tileSizeToUpdate = 0, Vector2? size})
: super([
if (size != null) TileModel(x: size.x, y: size.y, width: 1, height: 1)
], tileSizeToUpdate: tileSizeToUpdate);
}
8 changes: 4 additions & 4 deletions lib/map/world_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class WorldMap extends GameMap {

tree.QuadTree<TileModel>? quadTree;

factory WorldMap.empty() {
return EmptyWorldMap();
factory WorldMap.empty({Vector2? size}) {
return EmptyWorldMap(size: size);
}

WorldMap(
Expand Down Expand Up @@ -163,9 +163,9 @@ class WorldMap extends GameMap {
}

@override
Future<void>? onLoad() async {
_calculatePositionAndSize();
Future<void> onLoad() async {
await super.onLoad();
_calculatePositionAndSize();
await Future.forEach<TileModel>(tiles, _loadTile);
_createQuadTree(gameRef.size);
_searchTilesToRender();
Expand Down
30 changes: 30 additions & 0 deletions lib/mixins/flip_render.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:bonfire/bonfire.dart';

mixin FlipRender on GameComponent {
bool flipRenderVertically = false;
bool flipRenderHorizonally = false;

@override
void render(Canvas canvas) {
if (_needFlip) {
_doFlip(canvas);
}
super.render(canvas);
if (_needFlip) {
canvas.restore();
}
}

bool get _needFlip => flipRenderVertically || flipRenderHorizonally;

void _doFlip(Canvas canvas) {
Vector2 center = (size / 2);
canvas.save();
canvas.translate(center.x, center.y);
canvas.scale(
flipRenderHorizonally ? -1 : 1,
flipRenderVertically ? -1 : 1,
);
canvas.translate(-center.x, -center.y);
}
}
2 changes: 1 addition & 1 deletion lib/tiled/map_world_by_tiled.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WorldMapByTiled extends WorldMap {
}

@override
Future<void>? onLoad() async {
Future<void> onLoad() async {
final map = await _builder.build();
tiles = map.map.tiles;
gameRef.addAll(map.components ?? []);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bonfire
description: (RPG maker) Create RPG-style or similar games more simply with Flame.
version: 3.6.1
version: 3.6.2
homepage: https://bonfire-engine.github.io
repository: https://github.com/RafaelBarbosatec/bonfire
issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues
Expand Down
Loading