-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customizable background, add send event
- Loading branch information
1 parent
2eff3c5
commit 779dd8f
Showing
26 changed files
with
733 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
import 'dart:async'; | ||
import 'dart:ui'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flame_bloc/flame_bloc.dart'; | ||
import 'package:quokka/bloc/board.dart'; | ||
import 'package:quokka/bloc/board_state.dart'; | ||
import 'package:quokka/board/game.dart'; | ||
|
||
class GameBoardBackground extends SpriteComponent | ||
with HasGameReference<BoardGame> { | ||
with | ||
HasGameReference<BoardGame>, | ||
FlameBlocListenable<BoardBloc, BoardState> { | ||
GameBoardBackground({super.size}) | ||
: super(paint: Paint()..isAntiAlias = false); | ||
|
||
@override | ||
void onLoad() { | ||
sprite = game.gridSprite; | ||
sprite = game.selectionSprite; | ||
} | ||
|
||
@override | ||
void onInitialState(BoardState state) => updateBackground(state); | ||
|
||
@override | ||
void onNewState(BoardState state) => updateBackground(state); | ||
|
||
Future<void> updateBackground(BoardState state) async { | ||
final backgroundLocation = state.table.background; | ||
var background = backgroundLocation == null | ||
? null | ||
: (await game.assetManager.loadPack(backgroundLocation.namespace)) | ||
?.getBackgroundItem(backgroundLocation.id); | ||
background ??= game.assetManager.packs | ||
.map((pack) => pack.value.getBackgroundItems(pack.key).firstOrNull) | ||
.nonNulls | ||
.firstOrNull; | ||
if (background == null) return; | ||
sprite = await game.assetManager.loadSprite(background.item.texture); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.