-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove roles seed, reimplement choose roles algorithm
- Loading branch information
Showing
10 changed files
with
164 additions
and
189 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,46 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:provider/provider.dart"; | ||
|
||
import "../utils/errors.dart"; | ||
import "../utils/game_controller.dart"; | ||
import "../utils/ui.dart"; | ||
import "../widgets/confirmation_dialog.dart"; | ||
import "../widgets/list_tiles/text_field.dart"; | ||
|
||
class DebugMenuScreen extends StatelessWidget { | ||
const DebugMenuScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final controller = context.watch<GameController>(); | ||
return Scaffold( | ||
appBar: AppBar(title: const Text("Меню отладки")), | ||
body: ListView( | ||
children: [ | ||
TextFieldListTile( | ||
leading: const Icon(Icons.casino), | ||
title: const Text("Зерно генератора ролей"), | ||
subtitle: const Text("При изменении игра будет перезапущена"), | ||
keyboardType: TextInputType.number, | ||
initialText: controller.rolesSeed?.toString() ?? "", | ||
labelText: "Зерно генератора ролей", | ||
onSubmit: (value) async { | ||
final seed = int.tryParse(value); | ||
if (seed != null) { | ||
final res = await showDialog<bool>( | ||
context: context, | ||
builder: (context) => const ConfirmationDialog( | ||
title: Text("Применить настройки?"), | ||
content: Text("Текущая игра будет перезапущена. Продолжить?"), | ||
), | ||
); | ||
if (res ?? false) { | ||
controller | ||
..rolesSeed = seed | ||
..stopGame(); | ||
Widget build(BuildContext context) => Scaffold( | ||
appBar: AppBar(title: const Text("Меню отладки")), | ||
body: ListView( | ||
children: [ | ||
TextFieldListTile( | ||
leading: const Icon(Icons.arrow_forward), | ||
title: const Text("Перейти к экрану"), | ||
initialText: "/", | ||
labelText: "Путь", | ||
validator: (value) { | ||
if (value == null || value.isEmpty) { | ||
return "Введите путь"; | ||
} | ||
if (!value.startsWith("/")) { | ||
return "Путь должен начинаться с /"; | ||
} | ||
return null; | ||
}, | ||
onSubmit: (value) async { | ||
try { | ||
await Navigator.pushNamed(context, value); | ||
} catch (e) { | ||
if (!context.mounted) { | ||
throw ContextNotMountedError(); | ||
return; | ||
} | ||
showSnackBar( | ||
context, | ||
const SnackBar(content: Text("Игра перезапущена")), | ||
await showSimpleDialog( | ||
context: context, | ||
title: const Text("Ошибка"), | ||
content: Text(e.toString()), | ||
); | ||
} | ||
} | ||
}, | ||
), | ||
TextFieldListTile( | ||
leading: const Icon(Icons.arrow_forward), | ||
title: const Text("Перейти к экрану"), | ||
initialText: "/", | ||
labelText: "Путь", | ||
validator: (value) { | ||
if (value == null || value.isEmpty) { | ||
return "Введите путь"; | ||
} | ||
if (!value.startsWith("/")) { | ||
return "Путь должен начинаться с /"; | ||
} | ||
return null; | ||
}, | ||
onSubmit: (value) async { | ||
try { | ||
await Navigator.pushNamed(context, value); | ||
} catch (e) { | ||
if (!context.mounted) { | ||
return; | ||
} | ||
await showSimpleDialog( | ||
context: context, | ||
title: const Text("Ошибка"), | ||
content: Text(e.toString()), | ||
); | ||
} | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} |
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,64 +1,50 @@ | ||
import "dart:math"; | ||
|
||
import "package:flutter/material.dart"; | ||
import "package:provider/provider.dart"; | ||
|
||
import "../game/player.dart"; | ||
import "../utils/game_controller.dart"; | ||
import "../utils/log.dart"; | ||
import "../utils/ui.dart"; | ||
|
||
class RolesScreen extends StatelessWidget { | ||
static final _log = Logger("RolesScreen"); | ||
|
||
const RolesScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final controller = context.watch<GameController>(); | ||
final players = controller.isGameInitialized | ||
? controller.players | ||
: controller.rolesSeed != null | ||
? generatePlayers(random: Random(controller.rolesSeed), nicknames: controller.nicknames) | ||
: const <Player>[]; | ||
if (players.isEmpty) { | ||
_log.warning("Players is empty"); | ||
} | ||
final players = controller.players; | ||
assert(players.isNotEmpty, "Players must be non-empty. Is the game running?"); | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text("Раздача ролей"), | ||
), | ||
body: players.isNotEmpty | ||
? PageView.builder( | ||
itemCount: players.length, | ||
itemBuilder: (context, index) { | ||
final player = players[index]; | ||
final String topText; | ||
if (player.nickname != null) { | ||
topText = "${player.nickname} (Игрок #${player.number})"; | ||
} else { | ||
topText = "Игрок #${player.number}"; | ||
} | ||
return Center( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
topText, | ||
style: const TextStyle(fontSize: 20), | ||
textAlign: TextAlign.center, | ||
), | ||
Text( | ||
player.role.prettyName, | ||
style: const TextStyle(fontSize: 48), | ||
textAlign: TextAlign.center, | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
) | ||
: const Center(child: Text(r"¯\_(ツ)_/¯", style: TextStyle(fontSize: 48))), | ||
body: PageView.builder( | ||
itemCount: players.length, | ||
itemBuilder: (context, index) { | ||
final player = players[index]; | ||
final String topText; | ||
if (player.nickname != null) { | ||
topText = "${player.nickname} (Игрок #${player.number})"; | ||
} else { | ||
topText = "Игрок #${player.number}"; | ||
} | ||
return Center( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
topText, | ||
style: const TextStyle(fontSize: 20), | ||
textAlign: TextAlign.center, | ||
), | ||
Text( | ||
player.role.prettyName, | ||
style: const TextStyle(fontSize: 48), | ||
textAlign: TextAlign.center, | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
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.