Skip to content

Commit

Permalink
Add pack reorder system and configurable packs on create
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Sep 5, 2024
1 parent 835086c commit ee50377
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 162 deletions.
2 changes: 1 addition & 1 deletion api/lib/src/event/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class ShuffleCellRequest extends ClientWorldEvent
@MappableClass()
final class PacksChangeRequest extends ClientWorldEvent
with PacksChangeRequestMappable {
final Set<String> packs;
final List<String> packs;

PacksChangeRequest(this.packs);
}
13 changes: 9 additions & 4 deletions api/lib/src/event/event.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,8 @@ class PacksChangeRequestMapper extends SubClassMapperBase<PacksChangeRequest> {
@override
final String id = 'PacksChangeRequest';

static Set<String> _$packs(PacksChangeRequest v) => v.packs;
static const Field<PacksChangeRequest, Set<String>> _f$packs =
static List<String> _$packs(PacksChangeRequest v) => v.packs;
static const Field<PacksChangeRequest, List<String>> _f$packs =
Field('packs', _$packs);

@override
Expand Down Expand Up @@ -1498,8 +1498,9 @@ extension PacksChangeRequestValueCopy<$R, $Out>

abstract class PacksChangeRequestCopyWith<$R, $In extends PacksChangeRequest,
$Out> implements ClientWorldEventCopyWith<$R, $In, $Out> {
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs;
@override
$R call({Set<String>? packs});
$R call({List<String>? packs});
PacksChangeRequestCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}
Expand All @@ -1513,7 +1514,11 @@ class _PacksChangeRequestCopyWithImpl<$R, $Out>
late final ClassMapperBase<PacksChangeRequest> $mapper =
PacksChangeRequestMapper.ensureInitialized();
@override
$R call({Set<String>? packs}) =>
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs =>
ListCopyWith($value.packs, (v, t) => ObjectCopyWith(v, $identity, t),
(v) => call(packs: v));
@override
$R call({List<String>? packs}) =>
$apply(FieldCopyWithData({if (packs != null) #packs: packs}));
@override
PacksChangeRequest $make(CopyWithData data) =>
Expand Down
2 changes: 1 addition & 1 deletion api/lib/src/event/process/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool isValidClientEvent(
table: state.table,
info: state.info,
id: channel,
packsSignature: assetManager.createSignature(state.info.packs),
packsSignature: assetManager.createSignature(state.info.packs.toSet()),
teamMembers: state.teamMembers,
),
channel ?? kAnyChannel,
Expand Down
4 changes: 2 additions & 2 deletions api/lib/src/models/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ part 'info.mapper.dart';
@MappableClass()
class GameInfo with GameInfoMappable {
final Map<String, GameTeam> teams;
final Set<String> packs;
final List<String> packs;

const GameInfo({
this.teams = const {},
this.packs = const {},
this.packs = const [],
});
}

Expand Down
15 changes: 10 additions & 5 deletions api/lib/src/models/info.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class GameInfoMapper extends ClassMapperBase<GameInfo> {
static Map<String, GameTeam> _$teams(GameInfo v) => v.teams;
static const Field<GameInfo, Map<String, GameTeam>> _f$teams =
Field('teams', _$teams, opt: true, def: const {});
static Set<String> _$packs(GameInfo v) => v.packs;
static const Field<GameInfo, Set<String>> _f$packs =
Field('packs', _$packs, opt: true, def: const {});
static List<String> _$packs(GameInfo v) => v.packs;
static const Field<GameInfo, List<String>> _f$packs =
Field('packs', _$packs, opt: true, def: const []);

@override
final MappableFields<GameInfo> fields = const {
Expand Down Expand Up @@ -171,7 +171,8 @@ abstract class GameInfoCopyWith<$R, $In extends GameInfo, $Out>
implements ClassCopyWith<$R, $In, $Out> {
MapCopyWith<$R, String, GameTeam, GameTeamCopyWith<$R, GameTeam, GameTeam>>
get teams;
$R call({Map<String, GameTeam>? teams, Set<String>? packs});
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs;
$R call({Map<String, GameTeam>? teams, List<String>? packs});
GameInfoCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}

Expand All @@ -188,7 +189,11 @@ class _GameInfoCopyWithImpl<$R, $Out>
get teams => MapCopyWith(
$value.teams, (v, t) => v.copyWith.$chain(t), (v) => call(teams: v));
@override
$R call({Map<String, GameTeam>? teams, Set<String>? packs}) =>
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs =>
ListCopyWith($value.packs, (v, t) => ObjectCopyWith(v, $identity, t),
(v) => call(packs: v));
@override
$R call({Map<String, GameTeam>? teams, List<String>? packs}) =>
$apply(FieldCopyWithData({
if (teams != null) #teams: teams,
if (packs != null) #packs: packs
Expand Down
6 changes: 5 additions & 1 deletion app/lib/board/hand/deck.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ class DeckDefinitionHandItem extends HandItem<PackItem<DeckDefinition>> {
@override
void moveItem(HandItemDropZone zone) {
if (zone is! GameCell) return;
final location = zone.toDefinition();
bloc.process(ObjectsSpawned(
zone.toDefinition(),
location,
item.item.figures
.map((e) => GameObject(
asset: ItemLocation(item.namespace, e.name),
variation: e.variation))
.toList()));
if (bloc.state.switchCellOnMove) {
bloc.process(CellSwitched(location));
}
}
}
7 changes: 6 additions & 1 deletion app/lib/board/hand/figure.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flame/widgets.dart';
import 'package:quokka/bloc/world/local.dart';
import 'package:quokka/bloc/world/state.dart';
import 'package:quokka/board/cell.dart';
import 'package:quokka/board/hand/item.dart';
Expand Down Expand Up @@ -26,10 +27,14 @@ class FigureDefinitionHandItem
@override
void moveItem(HandItemDropZone zone) {
if (zone is! GameCell) return;
bloc.process(ObjectsSpawned(zone.toDefinition(), [
final location = zone.toDefinition();
bloc.process(ObjectsSpawned(location, [
GameObject(
asset: ItemLocation(item.$1.namespace, item.$1.id),
variation: item.$2)
]));
if (bloc.state.switchCellOnMove) {
bloc.process(CellSwitched(location));
}
}
}
17 changes: 15 additions & 2 deletions app/lib/board/hand/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class GameHand extends CustomPainterComponent
HandItemDropZone {
final _scrollView = ScrollViewComponent(direction: Axis.horizontal);

/// Should hand be redrawn
bool _isDirty = true;

GameHand() : super(anchor: Anchor.topLeft, painter: GameHandCustomPainter());

@override
Expand All @@ -59,10 +62,20 @@ class GameHand extends CustomPainterComponent
}

@override
void onInitialState(ClientWorldState state) => _buildHand(state);
void update(double dt) {
if (_isDirty) {
_isDirty = false;
if (isMounted) {
_buildHand(bloc.state);
}
}
}

@override
void onInitialState(ClientWorldState state) => _isDirty = true;

@override
void onNewState(ClientWorldState state) => _buildHand(state);
void onNewState(ClientWorldState state) => _isDirty = true;

@override
void onParentResize(Vector2 maxSize) {
Expand Down
13 changes: 10 additions & 3 deletions app/lib/helpers/secondary.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';

mixin SecondaryTapCallbacks {
bool onSecondaryTapUp(TapUpInfo info) => false;
}

mixin DetailsTapCallbacks on SecondaryTapCallbacks, DoubleTapCallbacks {
Vector2 _position = Vector2.zero();
Vector2? _position;

@override
@mustCallSuper
Expand All @@ -19,12 +20,18 @@ mixin DetailsTapCallbacks on SecondaryTapCallbacks, DoubleTapCallbacks {
@override
@mustCallSuper
void onDoubleTapDown(DoubleTapDownEvent event) {
_position = event.devicePosition;
_position = event.deviceKind == PointerDeviceKind.touch
? event.devicePosition
: null;
}

@override
@mustCallSuper
void onDoubleTapUp(DoubleTapEvent event) => onContextMenu(_position);
void onDoubleTapUp(DoubleTapEvent event) {
final position = _position;
if (position == null) return;
onContextMenu(position);
}

void onContextMenu(Vector2 position);
}
4 changes: 3 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,7 @@
"export": "Export",
"editInfo": "Edit information",
"invalidPacks": "The server requested packs that doesn't exist on this client",
"switchCellOnMove": "Switch cell on move"
"switchCellOnMove": "Switch cell on move",
"addPack": "Add pack",
"removePack": "Remove pack"
}
Loading

0 comments on commit ee50377

Please sign in to comment.