Skip to content

Commit

Permalink
refactor: board generator (#586)
Browse files Browse the repository at this point in the history
* refactor: move models to folder

* refactor: rename package to board generator

* refactor: rename scripts folder to tool

* docs: update readme

* chore: update gitignore

* Update packages/board_generator/README.md

Co-authored-by: Alejandro Santiago <dev@alestiago.com>

* refactor: move tool outside of lib

---------

Co-authored-by: Alejandro Santiago <dev@alestiago.com>
  • Loading branch information
jsgalarraga and alestiago authored Jun 25, 2024
1 parent f2c359f commit 3e9507a
Show file tree
Hide file tree
Showing 36 changed files with 72 additions and 47 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/board_generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: board_uploader
name: board_generator

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -7,8 +7,8 @@ concurrency:
on:
pull_request:
paths:
- "packages/board_uploader/**"
- ".github/workflows/board_uploader.yaml"
- "packages/board_generator/**"
- ".github/workflows/board_generator.yaml"
branches:
- main

Expand All @@ -17,6 +17,7 @@ jobs:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
with:
dart_sdk: stable
working_directory: packages/board_uploader
working_directory: packages/board_generator
coverage_excludes: "**/*.g.dart"
min_coverage: 20
min_coverage: 100
check_ignore: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: board_generator_playground
name: board_uploader

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -7,8 +7,8 @@ concurrency:
on:
pull_request:
paths:
- "packages/board_generator_playground/**"
- ".github/workflows/board_generator_playground.yaml"
- "packages/board_uploader/**"
- ".github/workflows/board_uploader.yaml"
branches:
- main

Expand All @@ -17,7 +17,6 @@ jobs:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
with:
dart_sdk: stable
working_directory: packages/board_generator_playground
working_directory: packages/board_uploader
coverage_excludes: "**/*.g.dart"
min_coverage: 100
check_ignore: true
min_coverage: 20
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ build/
pubspec.lock

**/**.csv
/**_crossword.txt
/board.txt
**/**_crossword.txt
**/board_**.txt
27 changes: 27 additions & 0 deletions packages/board_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Board Generator

Package used to experiment with the board generation process.

## 📝 Getting a list of words

To generate a board, you need a set of words and clues that will be used as an input. Create a `words.csv` file inside the `tool` directory with the following format:

```none
word,"clue"
flutter,"Open source framework to build multi-platform applications"
firebase,"Mobile and web app development platform by Google"
```

If you need some inspiration, you can always [ask gemini](https://g.co/gemini/share/488086554d89) for help.

## 🧩 Generating a board

You can either generate a symmetrical crossword or an asymmetrical one by running its corresponding script from the `tool` directory.

```bash
dart asymmetrical_generation.dart
```

You can customize the size of the generated board by updating the `bounds` parameter in the `Crossword`.

The script will generate two outputs, a visual representation of the crossword in `asymmetrical_crossword.txt` and a csv file (`board_asymmetrical.txt`) with the position, direction, words and clues for the generated board. The csv is ready to be used by the `board_uploader` package to store the new board in firestore.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ library;

export 'src/crossword.dart';
export 'src/generators/generators.dart';
export 'src/horizontal_line_of_symmetry.dart';
export 'src/models/models.dart';
export 'src/sort_words.dart';
export 'src/word_pool.dart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';

/// {@template character_map}
/// Maps a [Location] to a [CharacterData].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// coverage:ignore-file

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';

/// {@template asymmetrical_crossword_generator}
/// A simple crossword generator that populates a crossword without
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// coverage:ignore-file

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';

/// {@template crossword_generator}
/// A generator that populates a [Crossword] with words from a [WordPool].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// coverage:ignore-file

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';

/// {@template symmetrical_crossword_generator}
/// A simple crossword generator that populates a crossword with an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';
import 'package:equatable/equatable.dart';

/// A set of bounds that define a rectangular region in the crossword puzzle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';
import 'package:equatable/equatable.dart';

/// {@template character_data}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';

/// {@template horizontal_line_of_symmetry}
/// An horizontal line of symmetry.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export 'bounds.dart';
export 'character_data.dart';
export 'direction.dart';
export 'horizontal_line_of_symmetry.dart';
export 'location.dart';
export 'word_candidate.dart';
export 'word_pool.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/board_generator.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:equatable/equatable.dart';

/// {@template word_candidate}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';
import 'package:meta/meta.dart';

/// {@template word_pool}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: board_generator_playground
description: Ephemeral package used to experiment with the board generation process.
name: board_generator
description: Package used to experiment with the board generation process.
version: 0.1.0+1
publish_to: none

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_literals_to_create_immutables

import 'package:board_generator_playground/src/crossword.dart';
import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/src/crossword.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:test/test.dart';

import 'fixtures/crosswords.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:board_generator_playground/src/crossword.dart';
import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/src/crossword.dart';
import 'package:board_generator/src/models/models.dart';

/// {@template crossword1}
/// A pre-defined crossword for testing.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator/board_generator.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:board_generator_playground/src/models/location.dart';
import 'package:board_generator/src/models/location.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:board_generator_playground/src/sort_words.dart';
import 'package:board_generator/src/sort_words.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_literals_to_create_immutables

import 'package:board_generator_playground/src/models/models.dart';
import 'package:board_generator_playground/src/word_pool.dart';
import 'package:board_generator/src/models/models.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:io';

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator_playground/scripts/model/model.dart';
import 'package:board_generator/board_generator.dart';
import 'package:csv/csv.dart';

import 'model/model.dart';

void main({void Function(String) log = print}) {
final fileString = File('words.csv').readAsStringSync();
final rows = const CsvToListConverter().convert(fileString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:io';

import 'package:board_generator_playground/board_generator_playground.dart';
import 'package:board_generator_playground/scripts/model/model.dart';
import 'package:board_generator/board_generator.dart';
import 'package:csv/csv.dart';

import 'model/model.dart';

void main({
void Function(String) log = print,
}) {
Expand Down
3 changes: 0 additions & 3 deletions packages/board_generator_playground/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion packages/board_uploader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package is responsible for dividing the board into sections and uploading i

### Dividing the board in sections

Add a `board.txt` file inside the `assets` folder with the board generated by the `board_generator_playground` package.
Add a `board.txt` file inside the `assets` folder with the board generated by the `board_generator` package.
Once the board is generated, create the sections and upload them to Firestore by running:

```sh
Expand Down

0 comments on commit 3e9507a

Please sign in to comment.