mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 00:48:47 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			39 lines
		
	
	
		
			744 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			744 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:ui';
 | |
| 
 | |
| import 'package:flame/components/mixins/has_game_ref.dart';
 | |
| import 'package:flame/game/base_game.dart';
 | |
| import 'package:test/test.dart';
 | |
| 
 | |
| import 'package:flame/components/component.dart';
 | |
| 
 | |
| class MyGame extends BaseGame {
 | |
|   bool calledFoo = false;
 | |
|   void foo() {
 | |
|     calledFoo = true;
 | |
|   }
 | |
| }
 | |
| 
 | |
| class MyComponent extends PositionComponent with HasGameRef<MyGame> {
 | |
|   @override
 | |
|   void update(double dt) {}
 | |
| 
 | |
|   @override
 | |
|   void render(Canvas c) {}
 | |
| 
 | |
|   void foo() {
 | |
|     gameRef.foo();
 | |
|   }
 | |
| }
 | |
| 
 | |
| void main() {
 | |
|   group('has game ref test', () {
 | |
|     test('simple test', () {
 | |
|       final MyComponent c = MyComponent();
 | |
|       final MyGame game = MyGame();
 | |
|       game.add(c);
 | |
|       c.foo();
 | |
|       expect(game.calledFoo, true);
 | |
|     });
 | |
|   });
 | |
| }
 | 
