Skip to content

Commit

Permalink
Add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 15, 2024
1 parent 22835af commit 0c2fa0e
Show file tree
Hide file tree
Showing 22 changed files with 487 additions and 89 deletions.
2 changes: 1 addition & 1 deletion app/android/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.989.0)
aws-partitions (1.990.0)
aws-sdk-core (3.209.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
Expand Down
7 changes: 7 additions & 0 deletions app/lib/bloc/world/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class WorldBloc extends Bloc<PlayableWorldEvent, ClientWorldState> {
on<DrawerViewChanged>((event, emit) {
emit(state.copyWith(drawerView: event.view));
});
on<SearchTermChanged>((event, emit) {
emit(state.copyWith(searchTerm: event.term));
});
on<ShowDuplicatesChanged>((event, emit) {
emit(
state.copyWith(showDuplicates: event.value ?? !state.showDuplicates));
});
}

Future<void> save() async {
Expand Down
17 changes: 17 additions & 0 deletions app/lib/bloc/world/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,20 @@ final class DrawerViewChanged extends LocalWorldEvent

DrawerViewChanged(this.view);
}

@MappableClass()
final class SearchTermChanged extends LocalWorldEvent
with SearchTermChangedMappable {
final String term;

SearchTermChanged(this.term);
}

@MappableClass()
final class ShowDuplicatesChanged extends LocalWorldEvent
with ShowDuplicatesChangedMappable {
final bool? value;

ShowDuplicatesChanged(this.value);
ShowDuplicatesChanged.toggle() : value = null;
}
238 changes: 238 additions & 0 deletions app/lib/bloc/world/local.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,241 @@ class _DrawerViewChangedCopyWithImpl<$R, $Out>
Then<$Out2, $R2> t) =>
_DrawerViewChangedCopyWithImpl($value, $cast, t);
}

class SearchTermChangedMapper extends SubClassMapperBase<SearchTermChanged> {
SearchTermChangedMapper._();

static SearchTermChangedMapper? _instance;
static SearchTermChangedMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = SearchTermChangedMapper._());
LocalWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
}
return _instance!;
}

@override
final String id = 'SearchTermChanged';

static String _$term(SearchTermChanged v) => v.term;
static const Field<SearchTermChanged, String> _f$term = Field('term', _$term);

@override
final MappableFields<SearchTermChanged> fields = const {
#term: _f$term,
};

@override
final String discriminatorKey = 'type';
@override
final dynamic discriminatorValue = 'SearchTermChanged';
@override
late final ClassMapperBase superMapper =
LocalWorldEventMapper.ensureInitialized();

static SearchTermChanged _instantiate(DecodingData data) {
return SearchTermChanged(data.dec(_f$term));
}

@override
final Function instantiate = _instantiate;

static SearchTermChanged fromMap(Map<String, dynamic> map) {
return ensureInitialized().decodeMap<SearchTermChanged>(map);
}

static SearchTermChanged fromJson(String json) {
return ensureInitialized().decodeJson<SearchTermChanged>(json);
}
}

mixin SearchTermChangedMappable {
String toJson() {
return SearchTermChangedMapper.ensureInitialized()
.encodeJson<SearchTermChanged>(this as SearchTermChanged);
}

Map<String, dynamic> toMap() {
return SearchTermChangedMapper.ensureInitialized()
.encodeMap<SearchTermChanged>(this as SearchTermChanged);
}

SearchTermChangedCopyWith<SearchTermChanged, SearchTermChanged,
SearchTermChanged>
get copyWith => _SearchTermChangedCopyWithImpl(
this as SearchTermChanged, $identity, $identity);
@override
String toString() {
return SearchTermChangedMapper.ensureInitialized()
.stringifyValue(this as SearchTermChanged);
}

@override
bool operator ==(Object other) {
return SearchTermChangedMapper.ensureInitialized()
.equalsValue(this as SearchTermChanged, other);
}

@override
int get hashCode {
return SearchTermChangedMapper.ensureInitialized()
.hashValue(this as SearchTermChanged);
}
}

extension SearchTermChangedValueCopy<$R, $Out>
on ObjectCopyWith<$R, SearchTermChanged, $Out> {
SearchTermChangedCopyWith<$R, SearchTermChanged, $Out>
get $asSearchTermChanged =>
$base.as((v, t, t2) => _SearchTermChangedCopyWithImpl(v, t, t2));
}

abstract class SearchTermChangedCopyWith<$R, $In extends SearchTermChanged,
$Out> implements LocalWorldEventCopyWith<$R, $In, $Out> {
@override
$R call({String? term});
SearchTermChangedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}

class _SearchTermChangedCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, SearchTermChanged, $Out>
implements SearchTermChangedCopyWith<$R, SearchTermChanged, $Out> {
_SearchTermChangedCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<SearchTermChanged> $mapper =
SearchTermChangedMapper.ensureInitialized();
@override
$R call({String? term}) =>
$apply(FieldCopyWithData({if (term != null) #term: term}));
@override
SearchTermChanged $make(CopyWithData data) =>
SearchTermChanged(data.get(#term, or: $value.term));

@override
SearchTermChangedCopyWith<$R2, SearchTermChanged, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t) =>
_SearchTermChangedCopyWithImpl($value, $cast, t);
}

class ShowDuplicatesChangedMapper
extends SubClassMapperBase<ShowDuplicatesChanged> {
ShowDuplicatesChangedMapper._();

static ShowDuplicatesChangedMapper? _instance;
static ShowDuplicatesChangedMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = ShowDuplicatesChangedMapper._());
LocalWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
}
return _instance!;
}

@override
final String id = 'ShowDuplicatesChanged';

static bool? _$value(ShowDuplicatesChanged v) => v.value;
static const Field<ShowDuplicatesChanged, bool> _f$value =
Field('value', _$value);

@override
final MappableFields<ShowDuplicatesChanged> fields = const {
#value: _f$value,
};

@override
final String discriminatorKey = 'type';
@override
final dynamic discriminatorValue = 'ShowDuplicatesChanged';
@override
late final ClassMapperBase superMapper =
LocalWorldEventMapper.ensureInitialized();

static ShowDuplicatesChanged _instantiate(DecodingData data) {
return ShowDuplicatesChanged(data.dec(_f$value));
}

@override
final Function instantiate = _instantiate;

static ShowDuplicatesChanged fromMap(Map<String, dynamic> map) {
return ensureInitialized().decodeMap<ShowDuplicatesChanged>(map);
}

static ShowDuplicatesChanged fromJson(String json) {
return ensureInitialized().decodeJson<ShowDuplicatesChanged>(json);
}
}

mixin ShowDuplicatesChangedMappable {
String toJson() {
return ShowDuplicatesChangedMapper.ensureInitialized()
.encodeJson<ShowDuplicatesChanged>(this as ShowDuplicatesChanged);
}

Map<String, dynamic> toMap() {
return ShowDuplicatesChangedMapper.ensureInitialized()
.encodeMap<ShowDuplicatesChanged>(this as ShowDuplicatesChanged);
}

ShowDuplicatesChangedCopyWith<ShowDuplicatesChanged, ShowDuplicatesChanged,
ShowDuplicatesChanged>
get copyWith => _ShowDuplicatesChangedCopyWithImpl(
this as ShowDuplicatesChanged, $identity, $identity);
@override
String toString() {
return ShowDuplicatesChangedMapper.ensureInitialized()
.stringifyValue(this as ShowDuplicatesChanged);
}

@override
bool operator ==(Object other) {
return ShowDuplicatesChangedMapper.ensureInitialized()
.equalsValue(this as ShowDuplicatesChanged, other);
}

@override
int get hashCode {
return ShowDuplicatesChangedMapper.ensureInitialized()
.hashValue(this as ShowDuplicatesChanged);
}
}

extension ShowDuplicatesChangedValueCopy<$R, $Out>
on ObjectCopyWith<$R, ShowDuplicatesChanged, $Out> {
ShowDuplicatesChangedCopyWith<$R, ShowDuplicatesChanged, $Out>
get $asShowDuplicatesChanged =>
$base.as((v, t, t2) => _ShowDuplicatesChangedCopyWithImpl(v, t, t2));
}

abstract class ShowDuplicatesChangedCopyWith<
$R,
$In extends ShowDuplicatesChanged,
$Out> implements LocalWorldEventCopyWith<$R, $In, $Out> {
@override
$R call({bool? value});
ShowDuplicatesChangedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}

class _ShowDuplicatesChangedCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, ShowDuplicatesChanged, $Out>
implements ShowDuplicatesChangedCopyWith<$R, ShowDuplicatesChanged, $Out> {
_ShowDuplicatesChangedCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<ShowDuplicatesChanged> $mapper =
ShowDuplicatesChangedMapper.ensureInitialized();
@override
$R call({Object? value = $none}) =>
$apply(FieldCopyWithData({if (value != $none) #value: value}));
@override
ShowDuplicatesChanged $make(CopyWithData data) =>
ShowDuplicatesChanged(data.get(#value, or: $value.value));

@override
ShowDuplicatesChangedCopyWith<$R2, ShowDuplicatesChanged, $Out2>
$chain<$R2, $Out2>(Then<$Out2, $R2> t) =>
_ShowDuplicatesChangedCopyWithImpl($value, $cast, t);
}
4 changes: 4 additions & 0 deletions app/lib/bloc/world/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ final class ClientWorldState with ClientWorldStateMappable {
final ItemLocation? selectedDeck;
final bool showHand, switchCellOnMove;
final DrawerView drawerView;
final String searchTerm;
final bool showDuplicates;

const ClientWorldState({
required this.multiplayer,
Expand All @@ -41,6 +43,8 @@ final class ClientWorldState with ClientWorldStateMappable {
this.showHand = false,
this.switchCellOnMove = false,
this.drawerView = DrawerView.chat,
this.searchTerm = '',
this.showDuplicates = false,
});

SetonixFileSystem get fileSystem => assetManager.fileSystem;
Expand Down
28 changes: 23 additions & 5 deletions app/lib/bloc/world/state.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ class ClientWorldStateMapper extends ClassMapperBase<ClientWorldState> {
static DrawerView _$drawerView(ClientWorldState v) => v.drawerView;
static const Field<ClientWorldState, DrawerView> _f$drawerView =
Field('drawerView', _$drawerView, opt: true, def: DrawerView.chat);
static String _$searchTerm(ClientWorldState v) => v.searchTerm;
static const Field<ClientWorldState, String> _f$searchTerm =
Field('searchTerm', _$searchTerm, opt: true, def: '');
static bool _$showDuplicates(ClientWorldState v) => v.showDuplicates;
static const Field<ClientWorldState, bool> _f$showDuplicates =
Field('showDuplicates', _$showDuplicates, opt: true, def: true);

@override
final MappableFields<ClientWorldState> fields = const {
Expand All @@ -155,6 +161,8 @@ class ClientWorldStateMapper extends ClassMapperBase<ClientWorldState> {
#showHand: _f$showHand,
#switchCellOnMove: _f$switchCellOnMove,
#drawerView: _f$drawerView,
#searchTerm: _f$searchTerm,
#showDuplicates: _f$showDuplicates,
};

static ClientWorldState _instantiate(DecodingData data) {
Expand All @@ -167,7 +175,9 @@ class ClientWorldStateMapper extends ClassMapperBase<ClientWorldState> {
selectedDeck: data.dec(_f$selectedDeck),
showHand: data.dec(_f$showHand),
switchCellOnMove: data.dec(_f$switchCellOnMove),
drawerView: data.dec(_f$drawerView));
drawerView: data.dec(_f$drawerView),
searchTerm: data.dec(_f$searchTerm),
showDuplicates: data.dec(_f$showDuplicates));
}

@override
Expand Down Expand Up @@ -237,7 +247,9 @@ abstract class ClientWorldStateCopyWith<$R, $In extends ClientWorldState, $Out>
ItemLocation? selectedDeck,
bool? showHand,
bool? switchCellOnMove,
DrawerView? drawerView});
DrawerView? drawerView,
String? searchTerm,
bool? showDuplicates});
ClientWorldStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}
Expand Down Expand Up @@ -270,7 +282,9 @@ class _ClientWorldStateCopyWithImpl<$R, $Out>
Object? selectedDeck = $none,
bool? showHand,
bool? switchCellOnMove,
DrawerView? drawerView}) =>
DrawerView? drawerView,
String? searchTerm,
bool? showDuplicates}) =>
$apply(FieldCopyWithData({
if (multiplayer != null) #multiplayer: multiplayer,
if (colorScheme != null) #colorScheme: colorScheme,
Expand All @@ -280,7 +294,9 @@ class _ClientWorldStateCopyWithImpl<$R, $Out>
if (selectedDeck != $none) #selectedDeck: selectedDeck,
if (showHand != null) #showHand: showHand,
if (switchCellOnMove != null) #switchCellOnMove: switchCellOnMove,
if (drawerView != null) #drawerView: drawerView
if (drawerView != null) #drawerView: drawerView,
if (searchTerm != null) #searchTerm: searchTerm,
if (showDuplicates != null) #showDuplicates: showDuplicates
}));
@override
ClientWorldState $make(CopyWithData data) => ClientWorldState(
Expand All @@ -293,7 +309,9 @@ class _ClientWorldStateCopyWithImpl<$R, $Out>
showHand: data.get(#showHand, or: $value.showHand),
switchCellOnMove:
data.get(#switchCellOnMove, or: $value.switchCellOnMove),
drawerView: data.get(#drawerView, or: $value.drawerView));
drawerView: data.get(#drawerView, or: $value.drawerView),
searchTerm: data.get(#searchTerm, or: $value.searchTerm),
showDuplicates: data.get(#showDuplicates, or: $value.showDuplicates));

@override
ClientWorldStateCopyWith<$R2, ClientWorldState, $Out2> $chain<$R2, $Out2>(
Expand Down
5 changes: 5 additions & 0 deletions app/lib/board/hand/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flame/widgets.dart';
import 'package:setonix/bloc/world/state.dart';
import 'package:setonix/board/cell.dart';
import 'package:setonix/board/hand/item.dart';
import 'package:setonix/helpers/string.dart';
import 'package:setonix_api/setonix_api.dart';

class BoardDefinitionHandItem extends HandItem<PackItem<BoardDefinition>> {
Expand All @@ -13,6 +14,10 @@ class BoardDefinitionHandItem extends HandItem<PackItem<BoardDefinition>> {
return translation.getBoardTranslation(item.id).name;
}

bool matches(ClientWorldState state, String term) =>
item.location.toString().equalsIgnoreCase(term) ||
getLabel(state).equalsIgnoreCase(term);

@override
Future<Sprite?> loadIcon(ClientWorldState state) =>
getAssetManager(state).loadBoardSprite(item.location);
Expand Down
Loading

0 comments on commit 0c2fa0e

Please sign in to comment.