Skip to content

Commit

Permalink
refactor: remove old crossword (#479)
Browse files Browse the repository at this point in the history
* chore: remove old crossword

* refactor: remove unused
  • Loading branch information
jsgalarraga authored May 11, 2024
1 parent cc07fdd commit 3039172
Show file tree
Hide file tree
Showing 31 changed files with 12 additions and 2,859 deletions.
60 changes: 0 additions & 60 deletions lib/crossword/bloc/crossword_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class CrosswordBloc extends Bloc<CrosswordEvent, CrosswordState> {
_subscriptions = subscriptionsMap ?? {},
super(const CrosswordState()) {
on<BoardSectionRequested>(_onBoardSectionRequested);
on<WordSelected>(_onWordSelected);
on<WordUnselected>(_onWordUnselected);
on<BoardLoadingInformationRequested>(_onBoardLoadingInformationRequested);
on<LoadedSectionsSuspended>(_onLoadedSectionsSuspended);
on<BoardSectionLoaded>(_onBoardSectionLoaded);
Expand Down Expand Up @@ -121,64 +119,6 @@ class CrosswordBloc extends Bloc<CrosswordEvent, CrosswordState> {
}
}

(int, int) _findWordInSection(
CrosswordState state,
Word word,
(int, int) section, {
int attempt = 1,
}) {
final sections = state.sections;

// TODO(Ayad): If it fails because the section is not loaded we
// should fetch the section
if (sections[section]!.words.contains(word)) {
return section;
}

// TODO(Ayad): control error handle
if (attempt >= 3) {
throw Exception('Word not found in crossword');
}

final previousSection = word.axis == Axis.horizontal
? (section.$1 - 1, section.$2)
: (section.$1, section.$2 - 1);

return _findWordInSection(
state,
word,
previousSection,
attempt: attempt + 1,
);
}

void _onWordSelected(
WordSelected event,
Emitter<CrosswordState> emit,
) {
final section = _findWordInSection(
state,
event.word,
event.section,
);

emit(
state.copyWith(
selectedWord: WordSelection(
section: section,
word: event.word,
),
),
);
}

void _onWordUnselected(
WordUnselected event,
Emitter<CrosswordState> emit,
) {
emit(state.removeSelectedWord());
}

FutureOr<void> _onBoardLoadingInformationRequested(
BoardLoadingInformationRequested event,
Emitter<CrosswordState> emit,
Expand Down
17 changes: 0 additions & 17 deletions lib/crossword/bloc/crossword_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ class LoadedSectionsSuspended extends CrosswordEvent {
List<Object> get props => [loadedSections];
}

class WordSelected extends CrosswordEvent {
const WordSelected(this.section, this.word);

final (int, int) section;
final Word word;

@override
List<Object> get props => [section, word];
}

class WordUnselected extends CrosswordEvent {
const WordUnselected();

@override
List<Object> get props => [];
}

class BoardLoadingInformationRequested extends CrosswordEvent {
const BoardLoadingInformationRequested();

Expand Down
47 changes: 0 additions & 47 deletions lib/crossword/bloc/crossword_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,18 @@ enum CrosswordStatus {
failure,
}

enum WordStatus {
solved,
pending,
invalid,
}

enum BoardStatus {
inProgress,
resetInProgress,
}

class WordSelection extends Equatable {
WordSelection({
required this.section,
required this.word,
WordStatus? solvedStatus,
}) : solvedStatus = solvedStatus ??
(word.solvedTimestamp != null
? WordStatus.solved
: WordStatus.pending);

final (int, int) section;
final Word word;
final WordStatus solvedStatus;

WordSelection copyWith({WordStatus? solvedStatus}) {
return WordSelection(
section: section,
word: word,
solvedStatus: solvedStatus ?? this.solvedStatus,
);
}

@override
List<Object> get props => [section, word, solvedStatus];
}

class CrosswordState extends Equatable {
const CrosswordState({
this.status = CrosswordStatus.initial,
this.gameStatus = GameStatus.inProgress,
this.boardStatus = BoardStatus.inProgress,
this.sectionSize = 0,
this.sections = const {},
this.selectedWord,
this.zoomLimit = 0.35,
this.mascotVisible = true,
});
Expand All @@ -60,7 +27,6 @@ class CrosswordState extends Equatable {
final BoardStatus boardStatus;
final int sectionSize;
final Map<(int, int), BoardSection> sections;
final WordSelection? selectedWord;
final double zoomLimit;
final bool mascotVisible;

Expand All @@ -70,7 +36,6 @@ class CrosswordState extends Equatable {
BoardStatus? boardStatus,
int? sectionSize,
Map<(int, int), BoardSection>? sections,
WordSelection? selectedWord,
double? zoomLimit,
bool? mascotVisible,
}) {
Expand All @@ -80,30 +45,18 @@ class CrosswordState extends Equatable {
boardStatus: boardStatus ?? this.boardStatus,
sectionSize: sectionSize ?? this.sectionSize,
sections: sections ?? this.sections,
selectedWord: selectedWord ?? this.selectedWord,
zoomLimit: zoomLimit ?? this.zoomLimit,
mascotVisible: mascotVisible ?? this.mascotVisible,
);
}

CrosswordState removeSelectedWord() {
return CrosswordState(
status: status,
sectionSize: sectionSize,
sections: sections,
zoomLimit: zoomLimit,
mascotVisible: mascotVisible,
);
}

@override
List<Object?> get props => [
status,
gameStatus,
boardStatus,
sectionSize,
sections,
selectedWord,
zoomLimit,
mascotVisible,
];
Expand Down
1 change: 0 additions & 1 deletion lib/crossword/crossword.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'bloc/crossword_bloc.dart';
export 'game/game.dart';
export 'view/view.dart';
26 changes: 0 additions & 26 deletions lib/crossword/extensions/characters_rectangle.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/crossword/extensions/extensions.dart

This file was deleted.

12 changes: 0 additions & 12 deletions lib/crossword/extensions/word_size.dart

This file was deleted.

Loading

0 comments on commit 3039172

Please sign in to comment.