game<T extends GameObject> method
The game of the first FynkelView on screen, as a T: the root it
shows (FynkelViewState.root), made by the game's FynkelApp or
FynkelGame or given to the view, whatever type that was made for;
for a view of a world, its FynkelGame's. Throws a StateError when
there's no view, or its game isn't a T.
Implementation
T game<T extends GameObject>() {
final views = find.byType(FynkelView).evaluate();
if (views.isEmpty) throw StateError('game found no FynkelView on screen: pump the app first');
final view = views.first;
final game = ((view as StatefulElement).state as FynkelViewState).root ?? FynkelGame.maybeOf(view)?.game;
if (game == null) {
throw StateError('game found a FynkelView of a world, with no game: reach what it shows through its world');
}
if (game is! T) throw StateError('game<$T> found a ${game.runtimeType}, which is not a $T');
return game;
}