Skip to content

Commit

Permalink
shuffle un-drawn cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmslitaren committed Dec 16, 2024
1 parent 49f6d1d commit f5b01ad
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 119 deletions.
69 changes: 44 additions & 25 deletions frosthaven_assistant/lib/Layout/menus/remove_card_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:frosthaven_assistant/Model/MonsterAbility.dart';
import 'package:frosthaven_assistant/Resource/commands/remove_card_command.dart';
import 'package:frosthaven_assistant/Resource/commands/reorder_ability_list_command.dart';
import 'package:frosthaven_assistant/Resource/commands/shuffle_drawn_ability_card_command.dart';

import '../../Resource/settings.dart';
import '../../Resource/state/game_state.dart';
Expand Down Expand Up @@ -29,7 +30,6 @@ class RemoveCardMenuState extends State<RemoveCardMenu> {

@override
Widget build(BuildContext context) {

bool isInDrawPile = false;
for (var item in _gameState.currentAbilityDecks) {
if (item.name == widget.card.deck) {
Expand All @@ -46,10 +46,11 @@ class RemoveCardMenuState extends State<RemoveCardMenu> {

return Container(
width: 300,
height: 180,
height: 210,
decoration: BoxDecoration(
image: DecorationImage(
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.8), BlendMode.dstATop),
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.8), BlendMode.dstATop),
image: AssetImage(getIt<Settings>().darkMode.value
? 'assets/images/bg/dark_bg.png'
: 'assets/images/bg/white_bg.png'),
Expand All @@ -58,40 +59,58 @@ class RemoveCardMenuState extends State<RemoveCardMenu> {
),
child: Column(children: [
const SizedBox(
height: 20,
height: 10,
),
TextButton(
onPressed: () {
_gameState.action(RemoveCardCommand(widget.card));

Navigator.pop(context);
},
child: Text("Remove ${widget.card.title}\n(card nr: ${widget.card.nr})",
textAlign: TextAlign.center, style: const TextStyle(fontSize: 20))),
child: Text(
"Remove ${widget.card.title}\n(card nr: ${widget.card.nr})",
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20))),
const SizedBox(
height: 20,
height: 10,
),
if (isInDrawPile) TextButton(
onPressed: () {
int oldIndex = 0;
int newIndex = 0;
for (var item in _gameState.currentAbilityDecks) {
if (item.name == widget.card.deck) {
var list = item.drawPile.getList();
for (int i = 0; i < list.length; i++) {
if (list[i].nr == widget.card.nr) {
oldIndex = i;
break;
if (isInDrawPile)
TextButton(
onPressed: () {
int oldIndex = 0;
int newIndex = 0;
//todo: no logic in ui
for (var item in _gameState.currentAbilityDecks) {
if (item.name == widget.card.deck) {
var list = item.drawPile.getList();
for (int i = 0; i < list.length; i++) {
if (list[i].nr == widget.card.nr) {
oldIndex = i;
break;
}
}
break;
}
break;
}
}
_gameState.action(ReorderAbilityListCommand(widget.card.deck, newIndex, oldIndex));
_gameState.action(ReorderAbilityListCommand(
widget.card.deck, newIndex, oldIndex));

Navigator.pop(context);
},
child: const Text("Send to Bottom", style: TextStyle(fontSize: 20))),
Navigator.pop(context);
},
child: const Text("Send to Bottom",
style: TextStyle(fontSize: 20))),
if (isInDrawPile)
const SizedBox(
height: 10,
),
if (isInDrawPile)
TextButton(
onPressed: () {
_gameState
.action(ShuffleDrawnAbilityCardCommand(widget.card.deck));
Navigator.pop(context);
},
child: const Text("Shuffle un-drawn Cards",
style: TextStyle(fontSize: 20))),
]));
}
}
51 changes: 31 additions & 20 deletions frosthaven_assistant/lib/Layout/menus/select_scenario_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
if (_gameState.currentCampaign.value != campaign) {
_gameState.action(SetCampaignCommand(campaign));
}
_foundScenarios =
_gameData.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys.toList();
_foundScenarios = _gameData
.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys
.toList();

//special hack for solo BladeSwarm
if (campaign == "Solo" || campaign == "Trail of Ashes") {
Expand All @@ -81,14 +82,16 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
}
}

if (campaign == "Solo" && getIt<Settings>().showCustomContent.value == false) {
if (campaign == "Solo" &&
getIt<Settings>().showCustomContent.value == false) {
_foundScenarios.removeWhere((scenario) {
List<String> strings = scenario.split(':');
strings[0] = strings[0].replaceFirst(" ", "Å");
String characterName = strings[0].split("Å")[1];
if (_gameData.modelData.value.entries.any((element) =>
GameMethods.isCustomCampaign(element.value.edition) &&
element.value.characters.any((element) => element.name == characterName))) {
element.value.characters
.any((element) => element.name == characterName))) {
return true;
}

Expand All @@ -106,9 +109,9 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
});

//sort random dungeon first for visibility of special feature
if(_foundScenarios.last == "#Random Dungeon") {
if (_foundScenarios.last == "#Random Dungeon") {
_foundScenarios.insert(0, _foundScenarios.last);
_foundScenarios.removeAt(_foundScenarios.length-1);
_foundScenarios.removeAt(_foundScenarios.length - 1);
}

if (campaign != "Solo") {
Expand All @@ -121,15 +124,18 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
List<String> results = [];
if (enteredKeyword.isEmpty) {
// if the search field is empty or only contains white-space, we'll display all
results =
_gameData.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys.toList();
results = _gameData
.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys
.toList();
if (_gameState.currentCampaign.value != "Solo") {
results.insert(0, "custom");
}
} else {
results = _gameData.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys
results = _gameData
.modelData.value[_gameState.currentCampaign.value]!.scenarios.keys
.toList()
.where((user) => user.toLowerCase().contains(enteredKeyword.toLowerCase()))
.where((user) =>
user.toLowerCase().contains(enteredKeyword.toLowerCase()))
.toList();
results.sort((a, b) {
int? aNr = findNrFromScenarioName(a);
Expand Down Expand Up @@ -175,9 +181,11 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {

String text = strings[1];
for (String key in _gameData.modelData.value.keys) {
for (CharacterClass character in _gameData.modelData.value[key]!.characters) {
for (CharacterClass character
in _gameData.modelData.value[key]!.characters) {
if (character.name == characterName) {
if (character.hidden && !_gameState.unlockedClasses.contains(character.id)) {
if (character.hidden &&
!_gameState.unlockedClasses.contains(character.id)) {
text = "???";
}
break;
Expand Down Expand Up @@ -231,10 +239,11 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
}
}
}
return [Wrap(
children: retVal,
)];
return retVal;
return [
Wrap(
children: retVal,
)
];
}

@override
Expand All @@ -249,12 +258,12 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
const SizedBox(
height: 20,
),

Column(children: [
const Text("Set Scenario", style: TextStyle(fontSize: 18)),
ExpansionTile(
key: UniqueKey(),
title: Text("Current Campaign: ${_gameState.currentCampaign.value}"),
title: Text(
"Current Campaign: ${_gameState.currentCampaign.value}"),
children: buildCampaignButtons(),
),
]),
Expand Down Expand Up @@ -296,11 +305,13 @@ class SelectScenarioMenuState extends State<SelectScenarioMenu> {
onEditingComplete: () {
if (_foundScenarios.isNotEmpty) {
Navigator.pop(context);
_gameState.action(SetScenarioCommand(_foundScenarios[0], false));
_gameState.action(SetScenarioCommand(
_foundScenarios[0], false));
}
},
decoration: const InputDecoration(
labelText: 'Set Scenario', suffixIcon: Icon(Icons.search)),
labelText: 'Set Scenario',
suffixIcon: Icon(Icons.search)),
)),
),
const SizedBox(
Expand Down
25 changes: 21 additions & 4 deletions frosthaven_assistant/lib/Layout/menus/send_to_bottom_menu.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:frosthaven_assistant/Resource/commands/reorder_modifier_list_command.dart';

import '../../Resource/commands/shuffle_amd_card_command.dart';
import '../../Resource/settings.dart';
import '../../Resource/state/game_state.dart';
import '../../services/service_locator.dart';
Expand All @@ -12,7 +13,10 @@ class SendToBottomMenu extends StatefulWidget {
final bool allies;

const SendToBottomMenu(
{super.key, required this.currentIndex, required this.length, required this.allies});
{super.key,
required this.currentIndex,
required this.length,
required this.allies});

@override
SendToBottomMenuState createState() => SendToBottomMenuState();
Expand All @@ -33,7 +37,8 @@ class SendToBottomMenuState extends State<SendToBottomMenu> {
height: 140,
decoration: BoxDecoration(
image: DecorationImage(
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.8), BlendMode.dstATop),
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.8), BlendMode.dstATop),
image: AssetImage(getIt<Settings>().darkMode.value
? 'assets/images/bg/dark_bg.png'
: 'assets/images/bg/white_bg.png'),
Expand All @@ -47,10 +52,22 @@ class SendToBottomMenuState extends State<SendToBottomMenu> {
TextButton(
onPressed: () {
int oldIndex = widget.length - 1 - widget.currentIndex;
_gameState.action(ReorderModifierListCommand(0, oldIndex, widget.allies));
_gameState.action(
ReorderModifierListCommand(0, oldIndex, widget.allies));
Navigator.pop(context);
},
child: const Text("Send to Bottom", style: TextStyle(fontSize: 20))),
child:
const Text("Send to Bottom", style: TextStyle(fontSize: 20))),
const SizedBox(
height: 20,
),
TextButton(
onPressed: () {
_gameState.action(ShuffleAMDCardCommand(widget.allies));
Navigator.pop(context);
},
child: const Text("Shuffle un-drawn Cards",
style: TextStyle(fontSize: 20))),
]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import '../../services/service_locator.dart';
import '../state/game_state.dart';

class ShuffleAMDCardCommand extends Command {
final bool allyDeck;
ShuffleAMDCardCommand(this.allyDeck);

@override
void execute() {
ModifierDeck deck = allyDeck
? getIt<GameState>().modifierDeckAllies
: getIt<GameState>().modifierDeck;

deck.shuffleUnDrawn(stateAccess);
}

@override
void undo() {}

@override
String describe() {
return "Extra AMD deck shuffle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:collection/collection.dart';

import '../state/game_state.dart';

class ShuffleDrawnAbilityCardCommand extends Command {
final String deck;
ShuffleDrawnAbilityCardCommand(this.deck);

@override
void execute() {
Monster? monster = GameMethods.getCurrentMonsters()
.firstWhereOrNull((element) => element.type.deck == deck);
if (monster != null) {
MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck);
deck?.shuffleUnDrawn(stateAccess);
}
}

@override
void undo() {}

@override
String describe() {
return "Drawn ability deck shuffle";
}
}
Loading

0 comments on commit f5b01ad

Please sign in to comment.