-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructured DB communication added Nomo Webon Kit Dart for eth fetching from Nomo App
- Loading branch information
Showing
29 changed files
with
1,969 additions
and
201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "packages/webon_kit_dart"] | ||
path = packages/webon_kit_dart | ||
url = https://github.com/nomo-app/webon-kit-dart.git |
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,7 +1,6 @@ | ||
import 'dart:io'; | ||
import 'package:flaptron_3000/functions/gameoverdialog.dart'; | ||
import 'package:flaptron_3000/functions/showdisplaynamedialog.dart'; | ||
import 'package:flaptron_3000/model/bird.dart'; | ||
import 'package:flaptron_3000/model/player.dart'; | ||
import 'package:flaptron_3000/pages/bird_grid_page.dart'; | ||
import 'package:flaptron_3000/pages/profile_setting_page.dart'; | ||
|
@@ -14,21 +13,8 @@ import 'package:flutter/material.dart'; | |
import 'package:flaptron_3000/widgets/birdWidget.dart'; | ||
import 'level/background_web.dart'; | ||
|
||
final Bird bird = Bird( | ||
gifPath: 'assets/gifs/bird.gif', | ||
screenXPos: 0.4, | ||
height: 80, | ||
width: 80); | ||
|
||
final gameHandler = GameHandler(Player( | ||
name: 'Test', | ||
score: 0, | ||
bird: bird,)); | ||
|
||
final size = | ||
MediaQueryData | ||
.fromView(PlatformDispatcher.instance.views.first) | ||
.size; | ||
MediaQueryData.fromView(PlatformDispatcher.instance.views.first).size; | ||
|
||
class HomePage extends StatefulWidget { | ||
const HomePage({super.key}); | ||
|
@@ -38,33 +24,38 @@ class HomePage extends StatefulWidget { | |
} | ||
|
||
class _HomePageState extends State<HomePage> { | ||
GameHandler? gameHandler; | ||
|
||
@override | ||
void dispose() { | ||
gameHandler.audioManager.dispose(); | ||
gameHandler?.audioManager.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
WidgetsBinding.instance!.addPostFrameCallback((_) { | ||
LocalStorage.init(); | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
_initializeUser(); | ||
FireStoreService.fetchUsers(); | ||
}); | ||
} | ||
|
||
Future<void> _initializeUser() async { | ||
bool? isLoggedIn = LocalStorage.getBool('isLoggedIn'); | ||
if (isLoggedIn == null || !isLoggedIn) { | ||
final playerId = LocalStorage.getPlayerId(); | ||
final PlayerM? player; | ||
if (playerId.isEmpty) { | ||
Map<String, String?>? result = await showDisplayNameDialog(context); | ||
String playerName = result['name'] ?? ''; | ||
String email = result['email'] ?? '[email protected]'; | ||
FireStoreService.addUser(playerName, email, 0); | ||
LocalStorage.setDisplayName(playerName); | ||
LocalStorage.setEmail(email); | ||
await LocalStorage.setBool('isLoggedIn', true); | ||
player = await FireStoreServiceM() | ||
.addPlayer(username: playerName, email: email); | ||
await LocalStorage.setPlayerId(playerId); | ||
} else { | ||
player = await FireStoreServiceM().getPlayer(playerId); | ||
} | ||
if (player == null) return; | ||
gameHandler = GameHandler(player); | ||
setState(() {}); | ||
} | ||
|
||
bool isDesktop() { | ||
|
@@ -73,13 +64,16 @@ class _HomePageState extends State<HomePage> { | |
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (gameHandler == null) { | ||
return const BackgroundImageWeb(); | ||
} | ||
return ListenableBuilder( | ||
listenable: gameHandler, | ||
listenable: gameHandler!, | ||
builder: (context, child) { | ||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { | ||
if (gameHandler.isGameOver) { | ||
if (gameHandler!.isGameOver) { | ||
showDialogGameOver( | ||
context, gameHandler.player.score, gameHandler.resetGame); | ||
context, gameHandler!.player.score, gameHandler!.resetGame); | ||
} | ||
}); | ||
return Scaffold( | ||
|
@@ -88,67 +82,63 @@ class _HomePageState extends State<HomePage> { | |
Expanded( | ||
child: GestureDetector( | ||
onTapDown: (details) { | ||
if (gameHandler.isGamePaused) { | ||
gameHandler.resumeGame(); | ||
if (gameHandler!.isGamePaused) { | ||
gameHandler!.resumeGame(); | ||
return; | ||
} | ||
if (gameHandler.isMenu) { | ||
gameHandler.startGame(); | ||
if (gameHandler!.isMenu) { | ||
gameHandler!.startGame(); | ||
return; | ||
} | ||
if (gameHandler.isPlaying) { | ||
gameHandler.jump(); | ||
if (gameHandler!.isPlaying) { | ||
gameHandler!.jump(); | ||
return; | ||
} | ||
}, | ||
onHorizontalDragUpdate: (details) { | ||
if (details.primaryDelta != null && | ||
details.primaryDelta! < 0) { | ||
// Only increase speed if swiping right | ||
gameHandler.boost(); | ||
gameHandler!.boost(); | ||
} | ||
}, | ||
child: Stack( | ||
children: [ | ||
const BackgroundImageWeb(), | ||
Positioned( | ||
top: size.height * gameHandler.player.bird.pos.dy, | ||
left: size.width * gameHandler.player.bird.pos.dx, | ||
child: BirdWidget(bird: gameHandler.player.bird), | ||
top: size.height * gameHandler!.player.bird.pos.dy, | ||
left: size.width * gameHandler!.player.bird.pos.dx, | ||
child: ListenableBuilder( | ||
listenable: gameHandler!.player, | ||
builder: (context, _) => | ||
BirdWidget(bird: gameHandler!.player.bird)), | ||
), | ||
if (!gameHandler.isPlaying) | ||
if (!gameHandler!.isPlaying) | ||
const TapHintAnimation(birdYAxi: .5), | ||
...gameHandler.obstacleManager.obstacles, | ||
...gameHandler.bitcoinManager.bitcoins | ||
.map((bitcoin) => | ||
Positioned( | ||
left: bitcoin.pos.dx - 50, | ||
top: bitcoin.pos.dy - 50, | ||
width: 100, | ||
height: 100, | ||
child: bitcoin, | ||
)) | ||
...gameHandler!.obstacleManager.obstacles, | ||
...gameHandler!.bitcoinManager.bitcoins | ||
.map((bitcoin) => Positioned( | ||
left: bitcoin.pos.dx - 50, | ||
top: bitcoin.pos.dy - 50, | ||
width: 100, | ||
height: 100, | ||
child: bitcoin, | ||
)) | ||
.toList(), | ||
Positioned( | ||
top: 20, | ||
left: 20, | ||
child: Text( | ||
'High Score: ${gameHandler.player.highScore}', | ||
'High Score: ${gameHandler!.player.highScore}', | ||
style: const TextStyle( | ||
color: Colors.deepOrangeAccent, fontSize: 24), | ||
), | ||
), | ||
Positioned( | ||
top: MediaQuery | ||
.of(context) | ||
.size | ||
.width * 0.3, | ||
left: MediaQuery | ||
.of(context) | ||
.size | ||
.width * 0.5, | ||
top: MediaQuery.of(context).size.width * 0.3, | ||
left: MediaQuery.of(context).size.width * 0.5, | ||
child: Text( | ||
'${gameHandler.player.score}', | ||
'${gameHandler!.player.score}', | ||
style: const TextStyle( | ||
color: Colors.orangeAccent, | ||
fontSize: 34, | ||
|
@@ -166,25 +156,25 @@ class _HomePageState extends State<HomePage> { | |
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
IconButton( | ||
icon: Icon(gameHandler.audioManager.isMuted | ||
icon: Icon(gameHandler!.audioManager.isMuted | ||
? Icons.volume_off | ||
: Icons.volume_up), | ||
onPressed: () { | ||
gameHandler.toggleMute(); | ||
gameHandler!.toggleMute(); | ||
}, | ||
), | ||
IconButton( | ||
icon: Icon(gameHandler.isGamePaused | ||
icon: Icon(gameHandler!.isGamePaused | ||
? Icons.play_arrow | ||
: Icons.pause), | ||
onPressed: () { | ||
gameHandler.togglePauseGame(); | ||
gameHandler!.togglePauseGame(); | ||
}, | ||
), | ||
const Spacer(), | ||
IconButton( | ||
onPressed: () { | ||
gameHandler.pauseGame(); | ||
gameHandler!.pauseGame(); | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
|
@@ -198,12 +188,13 @@ class _HomePageState extends State<HomePage> { | |
), | ||
IconButton( | ||
onPressed: () { | ||
gameHandler.pauseGame(); | ||
gameHandler!.pauseGame(); | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
ProfileSettingsPage(bird:bird,))); | ||
builder: (context) => ProfileSettingsPage( | ||
player: gameHandler!.player, | ||
))); | ||
}, | ||
icon: const Icon( | ||
Icons.settings, | ||
|
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class NFTModel { | ||
final String name; | ||
final String description; | ||
final String contract; | ||
final String image_url; | ||
final String identifier; | ||
final String collection; | ||
final String token_standard; | ||
|
||
NFTModel( | ||
{required this.name, | ||
required this.description, | ||
required this.contract, | ||
required this.image_url, | ||
required this.identifier, | ||
required this.collection, | ||
required this.token_standard}); | ||
|
||
factory NFTModel.fromJson(Map<String, dynamic> json) { | ||
return NFTModel( | ||
name: json['name'], | ||
description: json['description'], | ||
contract: json['contract'], | ||
image_url: json['image_url'], | ||
identifier: json['identifier'], | ||
collection: json['collection'], | ||
token_standard: json['token_standard'], | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'name': name, | ||
'description': description, | ||
'contract': contract, | ||
'image_url': image_url, | ||
'identifier': identifier, | ||
'collection': collection, | ||
'token_standard': token_standard, | ||
}; | ||
} | ||
} |
Oops, something went wrong.