From 9222d018258fffbff54c4ab3d2c441019d48d234 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Thu, 8 Sep 2022 23:34:46 +0200 Subject: [PATCH] chore!: Introduce Melos and bump versions (#53) Introduces Melos Adds .github files Bumps Dart to 2.18.0 --- .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/1_bug.md | 46 +++++ .github/ISSUE_TEMPLATE/2_feature.md | 21 ++ .github/ISSUE_TEMPLATE/3_improvement.md | 24 +++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/pull_request_template.md | 46 +++++ .github/workflows/title-validation.yml | 14 ++ .gitignore | 37 +++- CONTRIBUTING.md | 186 +++++++++++++++++ melos.yaml | 66 ++++++ CHANGELOG.md => packages/tiled/CHANGELOG.md | 0 LICENSE => packages/tiled/LICENSE | 0 packages/tiled/README.md | 1 + .../tiled/analysis_options.yaml | 0 {lib => packages/tiled/lib}/src/chunk.dart | 2 +- .../tiled/lib}/src/common/enums.dart | 0 .../tiled/lib}/src/common/flips.dart | 0 .../tiled/lib}/src/common/frame.dart | 11 +- .../tiled/lib}/src/common/gid.dart | 0 .../tiled/lib}/src/common/point.dart | 13 +- .../tiled/lib}/src/common/property.dart | 15 +- .../tiled/lib}/src/common/tiled_image.dart | 20 +- .../lib}/src/editor_setting/chunk_size.dart | 11 +- .../src/editor_setting/editor_setting.dart | 12 +- .../tiled/lib}/src/editor_setting/export.dart | 11 +- {lib => packages/tiled/lib}/src/layer.dart | 193 ++++++------------ .../tiled/lib}/src/objects/text.dart | 31 ++- .../tiled/lib}/src/objects/tiled_object.dart | 7 +- {lib => packages/tiled/lib}/src/parser.dart | 4 +- {lib => packages/tiled/lib}/src/template.dart | 11 +- .../tiled/lib}/src/tile_map_parser.dart | 0 .../tiled/lib}/src/tiled_map.dart | 17 +- .../tiled/lib}/src/tileset/grid.dart | 13 +- .../tiled/lib}/src/tileset/terrain.dart | 13 +- .../tiled/lib}/src/tileset/tile.dart | 51 ++--- .../tiled/lib}/src/tileset/tile_offset.dart | 11 +- .../tiled/lib}/src/tileset/tileset.dart | 2 +- .../lib}/src/tileset/wang/wang_color.dart | 20 +- .../tiled/lib}/src/tileset/wang/wang_set.dart | 2 +- .../lib}/src/tileset/wang/wang_tile.dart | 28 +-- .../tiled/lib}/src/tsx_provider.dart | 0 {lib => packages/tiled/lib}/tiled.dart | 3 +- pubspec.yaml => packages/tiled/pubspec.yaml | 9 +- .../tiled/test}/complexmap_infinite_test.dart | 0 .../tiled/test}/fixtures/coins.png | Bin .../tiled/test}/fixtures/complexmap.json | 0 .../tiled/test}/fixtures/complexmap.tmx | 0 .../test}/fixtures/complexmap_infinite.tmx | 0 .../test}/fixtures/external_tileset_1.tsx | 0 .../test}/fixtures/external_tileset_2.tsx | 0 .../test}/fixtures/external_tileset_map.tmx | 0 .../tiled/test}/fixtures/floortileset.png | Bin .../tiled/test}/fixtures/icons.png | Bin .../tiled/test}/fixtures/icons.xcf | Bin .../tiled/test}/fixtures/image1.png | Bin .../tiled/test}/fixtures/image2.png | Bin .../tiled/test}/fixtures/imagelayer.tmx | 0 .../fixtures/isometric_grass_and_water.png | Bin .../fixtures/isometric_grass_and_water.tmx | 0 .../isometric_staggered_grass_and_water.json | 0 .../isometric_staggered_grass_and_water.tmx | 0 .../tiled/test}/fixtures/level1.png | Bin .../tiled/test}/fixtures/map.tmx | 0 .../tiled/test}/fixtures/map_images.tmx | 0 .../fixtures/map_with_multiple_tilesets.tmx | 0 .../fixtures/map_with_spacing_margin.tmx | 0 .../fixtures/map_with_tile_collision.tsx | 0 .../tiled/test}/fixtures/objectgroup.json | 0 .../tiled/test}/fixtures/objectgroup.tmx | 0 .../tiled/test}/fixtures/rectangle.tmx | 0 .../tiled/test}/fixtures/test.tmx | 0 .../tiled/test}/fixtures/test_base64_gzip.tmx | 0 .../tiled/test}/fixtures/test_csv.tmx | 0 .../tiled/test}/fixtures/test_old.tmx | 0 .../tiled/test}/fixtures/testbase64only.json | 0 .../tiled/test}/fixtures/testcsv.json | 0 .../tiled/test}/fixtures/testgzip.json | 0 .../tiled/test}/fixtures/testoverflow.tmx | 0 .../tiled/test}/fixtures/testoverflow_csv.tmx | 0 .../tiled/test}/fixtures/testzlib.json | 0 .../test}/fixtures/tileid_over_tilecount.tsx | 0 .../tiled/test}/fixtures/tileset.tsx | 0 .../fixtures/tilesets_deviant_milkian_1.png | Bin .../tiled/test}/image_layer_test.dart | 0 .../tiled/test}/isometric_staggered_test.dart | 0 .../tiled/test}/isometric_test.dart | 0 {test => packages/tiled/test}/layer_test.dart | 0 {test => packages/tiled/test}/map_test.dart | 12 +- .../tiled/test}/object_group_test.dart | 0 .../tiled/test}/overflow_bug_test.dart | 2 + .../tiled/test}/parser_compare_test.dart | 0 .../tiled/test}/parser_test.dart | 22 +- .../tiled/test}/rectangle_map_test.dart | 0 {test => packages/tiled/test}/tile_test.dart | 0 .../tiled/test}/tileset_test.dart | 0 .../tiled/test}/tmx_object_test.dart | 0 96 files changed, 675 insertions(+), 318 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/1_bug.md create mode 100644 .github/ISSUE_TEMPLATE/2_feature.md create mode 100644 .github/ISSUE_TEMPLATE/3_improvement.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/title-validation.yml create mode 100644 CONTRIBUTING.md create mode 100644 melos.yaml rename CHANGELOG.md => packages/tiled/CHANGELOG.md (100%) rename LICENSE => packages/tiled/LICENSE (100%) create mode 120000 packages/tiled/README.md rename analysis_options.yaml => packages/tiled/analysis_options.yaml (100%) rename {lib => packages/tiled/lib}/src/chunk.dart (98%) rename {lib => packages/tiled/lib}/src/common/enums.dart (100%) rename {lib => packages/tiled/lib}/src/common/flips.dart (100%) rename {lib => packages/tiled/lib}/src/common/frame.dart (74%) rename {lib => packages/tiled/lib}/src/common/gid.dart (100%) rename {lib => packages/tiled/lib}/src/common/point.dart (72%) rename {lib => packages/tiled/lib}/src/common/property.dart (80%) rename {lib => packages/tiled/lib}/src/common/tiled_image.dart (80%) rename {lib => packages/tiled/lib}/src/editor_setting/chunk_size.dart (68%) rename {lib => packages/tiled/lib}/src/editor_setting/editor_setting.dart (64%) rename {lib => packages/tiled/lib}/src/editor_setting/export.dart (71%) rename {lib => packages/tiled/lib}/src/layer.dart (82%) rename {lib => packages/tiled/lib}/src/objects/text.dart (74%) rename {lib => packages/tiled/lib}/src/objects/tiled_object.dart (97%) rename {lib => packages/tiled/lib}/src/parser.dart (98%) rename {lib => packages/tiled/lib}/src/template.dart (76%) rename {lib => packages/tiled/lib}/src/tile_map_parser.dart (100%) rename {lib => packages/tiled/lib}/src/tiled_map.dart (96%) rename {lib => packages/tiled/lib}/src/tileset/grid.dart (76%) rename {lib => packages/tiled/lib}/src/tileset/terrain.dart (71%) rename {lib => packages/tiled/lib}/src/tileset/tile.dart (58%) rename {lib => packages/tiled/lib}/src/tileset/tile_offset.dart (76%) rename {lib => packages/tiled/lib}/src/tileset/tileset.dart (99%) rename {lib => packages/tiled/lib}/src/tileset/wang/wang_color.dart (67%) rename {lib => packages/tiled/lib}/src/tileset/wang/wang_set.dart (97%) rename {lib => packages/tiled/lib}/src/tileset/wang/wang_tile.dart (74%) rename {lib => packages/tiled/lib}/src/tsx_provider.dart (100%) rename {lib => packages/tiled/lib}/tiled.dart (96%) rename pubspec.yaml => packages/tiled/pubspec.yaml (78%) rename {test => packages/tiled/test}/complexmap_infinite_test.dart (100%) rename {test => packages/tiled/test}/fixtures/coins.png (100%) rename {test => packages/tiled/test}/fixtures/complexmap.json (100%) rename {test => packages/tiled/test}/fixtures/complexmap.tmx (100%) rename {test => packages/tiled/test}/fixtures/complexmap_infinite.tmx (100%) rename {test => packages/tiled/test}/fixtures/external_tileset_1.tsx (100%) rename {test => packages/tiled/test}/fixtures/external_tileset_2.tsx (100%) rename {test => packages/tiled/test}/fixtures/external_tileset_map.tmx (100%) rename {test => packages/tiled/test}/fixtures/floortileset.png (100%) rename {test => packages/tiled/test}/fixtures/icons.png (100%) rename {test => packages/tiled/test}/fixtures/icons.xcf (100%) rename {test => packages/tiled/test}/fixtures/image1.png (100%) rename {test => packages/tiled/test}/fixtures/image2.png (100%) rename {test => packages/tiled/test}/fixtures/imagelayer.tmx (100%) rename {test => packages/tiled/test}/fixtures/isometric_grass_and_water.png (100%) rename {test => packages/tiled/test}/fixtures/isometric_grass_and_water.tmx (100%) rename {test => packages/tiled/test}/fixtures/isometric_staggered_grass_and_water.json (100%) rename {test => packages/tiled/test}/fixtures/isometric_staggered_grass_and_water.tmx (100%) rename {test => packages/tiled/test}/fixtures/level1.png (100%) rename {test => packages/tiled/test}/fixtures/map.tmx (100%) rename {test => packages/tiled/test}/fixtures/map_images.tmx (100%) rename {test => packages/tiled/test}/fixtures/map_with_multiple_tilesets.tmx (100%) rename {test => packages/tiled/test}/fixtures/map_with_spacing_margin.tmx (100%) rename {test => packages/tiled/test}/fixtures/map_with_tile_collision.tsx (100%) rename {test => packages/tiled/test}/fixtures/objectgroup.json (100%) rename {test => packages/tiled/test}/fixtures/objectgroup.tmx (100%) rename {test => packages/tiled/test}/fixtures/rectangle.tmx (100%) rename {test => packages/tiled/test}/fixtures/test.tmx (100%) rename {test => packages/tiled/test}/fixtures/test_base64_gzip.tmx (100%) rename {test => packages/tiled/test}/fixtures/test_csv.tmx (100%) rename {test => packages/tiled/test}/fixtures/test_old.tmx (100%) rename {test => packages/tiled/test}/fixtures/testbase64only.json (100%) rename {test => packages/tiled/test}/fixtures/testcsv.json (100%) rename {test => packages/tiled/test}/fixtures/testgzip.json (100%) rename {test => packages/tiled/test}/fixtures/testoverflow.tmx (100%) rename {test => packages/tiled/test}/fixtures/testoverflow_csv.tmx (100%) rename {test => packages/tiled/test}/fixtures/testzlib.json (100%) rename {test => packages/tiled/test}/fixtures/tileid_over_tilecount.tsx (100%) rename {test => packages/tiled/test}/fixtures/tileset.tsx (100%) rename {test => packages/tiled/test}/fixtures/tilesets_deviant_milkian_1.png (100%) rename {test => packages/tiled/test}/image_layer_test.dart (100%) rename {test => packages/tiled/test}/isometric_staggered_test.dart (100%) rename {test => packages/tiled/test}/isometric_test.dart (100%) rename {test => packages/tiled/test}/layer_test.dart (100%) rename {test => packages/tiled/test}/map_test.dart (92%) rename {test => packages/tiled/test}/object_group_test.dart (100%) rename {test => packages/tiled/test}/overflow_bug_test.dart (97%) rename {test => packages/tiled/test}/parser_compare_test.dart (100%) rename {test => packages/tiled/test}/parser_test.dart (97%) rename {test => packages/tiled/test}/rectangle_map_test.dart (100%) rename {test => packages/tiled/test}/tile_test.dart (100%) rename {test => packages/tiled/test}/tileset_test.dart (100%) rename {test => packages/tiled/test}/tmx_object_test.dart (100%) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..fd95805 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: bluefireoss diff --git a/.github/ISSUE_TEMPLATE/1_bug.md b/.github/ISSUE_TEMPLATE/1_bug.md new file mode 100644 index 0000000..94e0e81 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/1_bug.md @@ -0,0 +1,46 @@ +--- +name: Bug report. +about: You are using the tiled dart library but you are noticing some strange behaviour, that it throws an unexpected exception, or that it is not working according to the specifications. +title: '' +labels: 'bug' +assignees: '' + +--- + + + + +# Current bug behaviour + + +# Expected behaviour + + +# Steps to reproduce + + + +# Flutter doctor output + +``` +Output of: flutter doctor -v +``` + +# More environment information + + +# Log information + +``` +Enter log information in this code block +``` + +# More information + + + diff --git a/.github/ISSUE_TEMPLATE/2_feature.md b/.github/ISSUE_TEMPLATE/2_feature.md new file mode 100644 index 0000000..41f0f4a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/2_feature.md @@ -0,0 +1,21 @@ +--- +name: Feature request. +about: Suggest a new feature for the Tiled library. +title: '' +labels: 'enhancement' +assignees: '' + +--- + + + +# Problem to solve + + +# Proposal + + +# More information + + + diff --git a/.github/ISSUE_TEMPLATE/3_improvement.md b/.github/ISSUE_TEMPLATE/3_improvement.md new file mode 100644 index 0000000..a8f7c66 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/3_improvement.md @@ -0,0 +1,24 @@ +--- +name: Improvement suggestion. +about: Something in the Dart Tiled library can be improved. +title: '' +labels: 'enhancement' +assignees: '' + +--- + + + +# What could be improved + + +# Why should this be improved + + +# Any risks? + + +# More information + + + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0e0eda5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Join us on Discord! + url: https://discord.gg/pxrBmy4 + about: Ask your questions to the community! diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..3fb5caa --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,46 @@ +# Description + + + +## Checklist + + + +- [ ] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc). +- [ ] I have read the [Contributor Guide] and followed the process outlined for submitting PRs. +- [ ] I have updated/added tests for ALL new/updated/fixed functionality. +- [ ] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`. +- [ ] I have updated/added relevant examples in `examples`. + +## Breaking Change + + + +- [ ] Yes, this is a breaking change. +- [ ] No, this is *not* a breaking change. + + + +## Related Issues + + + + +[issue database]: https://github.com/flame-engine/tiled.dart/issues +[Contributor Guide]: https://github.com/flame-engine/flame/blob/main/CONTRIBUTING.md +[Flame Style Guide]: https://github.com/flame-engine/flame/blob/main/STYLEGUIDE.md +[Conventional Commit]: https://conventionalcommits.org diff --git a/.github/workflows/title-validation.yml b/.github/workflows/title-validation.yml new file mode 100644 index 0000000..e3011a1 --- /dev/null +++ b/.github/workflows/title-validation.yml @@ -0,0 +1,14 @@ +name: title-validation + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + validate-pr-title: + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 51e76a8..f3543a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,29 @@ -/packages -/build - -/.pub +.DS_Store +.atom/ +.idea +**/*.iml +.packages +.dart_tool/ +.pub/ pubspec.lock +packages/flame/doc/api/ +.flutter-plugins +.vscode/ +**/.flutter-plugins +**/.flutter-plugins-dependencies +**/pubspec_overrides.yaml -# IDEs -/.idea +android/ +ios/ +desktop/ +build/ +_build/ +**/doc/ -.packages -.dart_tool -.vscode/ -coverage/ -doc/ +coverage +**/failures + +.fvm +Makefile +!doc/_sphinx/Makefile +.bak diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1c1f27f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,186 @@ +# Contribution Guidelines + +**Note:** If these contribution guidelines are not followed your issue or PR might be closed, so +please read these instructions carefully. + + +## Contribution types + +### Bug Reports + - If you find a bug, please first report it using [Github issues]. + - First check if there is not already an issue for it; duplicated issues will be closed. + + +### Bug Fix + - If you'd like to submit a fix for a bug, please read the [How To](#how-to-contribute) for how to + send a Pull Request. + - Indicate on the open issue that you are working on fixing the bug and the issue will be assigned + to you. + - Write `Fixes #xxxx` in your PR text, where xxxx is the issue number (if there is one). + - Include a test that isolates the bug and verifies that it was fixed. + + +### New Features + - If you'd like to add a feature to the library that doesn't already exist, feel free to describe + the feature in a new [GitHub issue]. + - You can also join us on [Discord] to discuss some initials + thoughts. + - If you'd like to implement the new feature, please wait for feedback from the project maintainers + before spending too much time writing the code. In some cases, enhancements may not align well + with the project objectives at the time. + - Implement the code for the new feature and please read the [How To](#how-to-contribute). + + +### Documentation & Miscellaneous + - If you have suggestions for improvements to the documentation, tutorial or examples (or something + else), we would love to hear about it. + - As always first file a [Github issue]. + - Implement the changes to the documentation, please read the [How To](#how-to-contribute). + + +## How To Contribute + +### Requirements +For a contribution to be accepted: + +- Documentation should always be updated or added.* +- Examples should always be updated or added.* +- Tests should always be updated or added.* +- Format the Dart code accordingly with `flutter format`. +- Your code should pass the analyzer checks `melos run analyze`. +- Your code should pass all tests `melos run test`. +- Start your PR title with a [conventional commit] type + (`feat:`, `fix:` etc). + +*When applicable. + +If the contribution doesn't meet these criteria, a maintainer will discuss it with you on the issue +or PR. You can still continue to add more commits to the branch you have sent the Pull Request from +and it will be automatically reflected in the PR. + + +## Open an issue and fork the repository + - If it is a bigger change or a new feature, first of all + [file a bug or feature report][GitHub issues], so that we can discuss what direction to follow. + - [Fork the project][fork guide] on GitHub. + - Clone the forked repository to your local development machine + (e.g. `git clone git@github.com:/tiled.dart.git`). + + +### Environment Setup +The Dart Tiled library uses [Melos] to manage the project and dependencies. + +To install Melos, run the following command from your terminal: + +```bash +flutter pub global activate melos +``` + +Next, at the root of your locally cloned repository bootstrap the projects dependencies: + +```bash +melos bootstrap +``` + +The bootstrap command locally links all dependencies within the project without having to +provide manual [`dependency_overrides`][pubspec doc]. This allows all +plugins, examples and tests to build from the local clone project. You should only need to run this +command once. + +> You do not need to run `flutter pub get` once bootstrap has been completed. + + +### Performing changes + - Create a new local branch from `main` (e.g. `git checkout -b my-new-feature`) + - Make your changes (try to split them up with one PR per feature/fix). + - When committing your changes, make sure that each commit message is clear + (e.g. `git commit -m 'Take in an optional horizontal offset'`). + - Push your new branch to your own fork into the same remote branch + (e.g. `git push origin my-username.my-new-feature`, replace `origin` if you use another remote.) + + +### Breaking changes + +When doing breaking changes a deprecation tag should be added when possible and contain a message +that conveys to the user what which version that the deprecated method/field will be removed in and +what method they should use instead to perform the task. The version specified should be at least +two versions after the current one, such that there will be at least one stable release where the +users get to see the deprecation warning and in the version after that (or a later version) the +deprecated entity should be removed. + +Example (if the current version is v1.3.0): + +```dart +@Deprecated('Will be removed in v1.5.0, use nonDeprecatedFeature() instead') +void deprecatedFeature() {} +``` + + +### Open a pull request + +Go to the [pull request page of tiled.dart][PRs] and in the top +of the page it will ask you if you want to open a pull request from your newly created branch. + +The title of the pull request should start with a [conventional commit] type. + +Examples of such types: + - `fix:` - patches a bug and is not a new feature. + - `feat:` - introduces a new feature. + - `docs:` - updates or adds documentation or examples. + - `test:` - updates or adds tests. + - `refactor:` - refactors code but doesn't introduce any changes or additions to the public API. + +If you introduce a **breaking change** the conventional commit type MUST end with an exclamation +mark (e.g. `feat!: Remove the position argument from PositionComponent`). + +Examples of PR titles: + - feat: Hexagon support + - fix: Avoid infinite loop when parsing tiles + - docs: Add a hexagon tile example + - docs: Improve the Mandarin README + - test: Add infinity test for `Layer` + - refactor: Optimize the structure of the parsing loop + + +# Maintainers + +These instructions are for the maintainers of tiled.dart. + + +## Merging a pull request + +When merging a pull request, make sure that the title of the merge commit has the correct +conventional commit tag and a descriptive title. This is extra important since sometimes the title +of the PR doesn't reflect what GitHub defaults to for the merge commit title (if the title has been +changed during the life time of the PR for example). + +All the default text should be removed from the commit message and the PR description and the +instructions from the "Migration instruction" (if the PR is breaking) should be copied into the +commit message. + + +## Creating a release + +There are a few things to think about when doing a release: + + - Search through the codebase for `@Deprecated` methods/fields and remove the ones that are marked + for removal in the version that you are intending to release. + - Create a PR containing the changes for removing the deprecated entities. + - Run `melos version -V : -V :` for Melos to generate + `CHANGELOG.md` files. + - Go through the PRs with breaking changes and add migration documentation to the changelog. + There should be migration docs on each PR, if they haven't been copied to the commit message. + - Run `melos publish` to make sure that there aren't any problems with any of the packages and make + sure that all the versions are correct. + - Once you are satisfied with the result of the dry run, run `melos publish --no-dry-run` + - Create a PR containing the updated changelog and `pubspec.yaml` files. + + +[GitHub issue]: https://github.com/flame-engine/tiled.dart/issues/new +[GitHub issues]: https://github.com/flame-engine/tiled.dart/issues/new +[PRs]: https://github.com/flame-engine/tiled.dart/pulls +[fork guide]: https://guides.github.com/activities/forking/#fork +[Discord]: https://discord.gg/pxrBmy4 +[Melos]: https://github.com/invertase/melos +[pubspec doc]: https://dart.dev/tools/pub/pubspec +[conventional commit]: https://www.conventionalcommits.org diff --git a/melos.yaml b/melos.yaml new file mode 100644 index 0000000..acbdb19 --- /dev/null +++ b/melos.yaml @@ -0,0 +1,66 @@ +name: Tiled +repository: https://github.com/flame-engine/tiled.dart + +packages: + - packages/** + +command: + bootstrap: + # Uses the pubspec_overrides.yaml instead of having Melos modifying the lock file. + usePubspecOverrides: true + + version: + # Generate commit links in package changelogs. + linkToCommits: true + # Only allow versioning to happen on main branch. + branch: main + # Additionally build a changelog at the root of the workspace. + workspaceChangelog: true + +scripts: + lint:all: + run: melos run analyze && melos run format + description: Run all static analysis checks. + + analyze: + run: | + melos exec -c 10 -- \ + flutter analyze --fatal-infos + description: Run `flutter analyze` for all packages. + + format: + run: melos exec flutter format . --fix + description: Run `flutter format` for all packages. + + format-check: + run: melos exec flutter format . --set-exit-if-changed + description: Run `flutter format` checks for all packages. + + dartdoc: + run: melos exec flutter pub run dartdoc + description: Run dartdoc checks for all packages. + + test:select: + run: melos exec -- flutter test + select-package: + dir-exists: + - test + description: Run `flutter test` for selected packages. + + test: + run: melos run test:select --no-select + description: Run all Flutter tests in this project. + + coverage: + run: | + melos exec -- flutter test --coverage && + melos exec -- genhtml coverage/lcov.info --output-directory=coverage/ + select-package: + dir-exists: test + description: Generate coverage for the selected package. + + update-goldens: + run: melos exec -- flutter test --update-goldens + select-package: + dir-exists: test + description: Re-generate all golden test files diff --git a/CHANGELOG.md b/packages/tiled/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to packages/tiled/CHANGELOG.md diff --git a/LICENSE b/packages/tiled/LICENSE similarity index 100% rename from LICENSE rename to packages/tiled/LICENSE diff --git a/packages/tiled/README.md b/packages/tiled/README.md new file mode 120000 index 0000000..fe84005 --- /dev/null +++ b/packages/tiled/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/analysis_options.yaml b/packages/tiled/analysis_options.yaml similarity index 100% rename from analysis_options.yaml rename to packages/tiled/analysis_options.yaml diff --git a/lib/src/chunk.dart b/packages/tiled/lib/src/chunk.dart similarity index 98% rename from lib/src/chunk.dart rename to packages/tiled/lib/src/chunk.dart index 3eddac6..e306604 100644 --- a/lib/src/chunk.dart +++ b/packages/tiled/lib/src/chunk.dart @@ -41,7 +41,7 @@ class Chunk { required this.width, }) : tileData = Gid.generate(data, width, height); - static Chunk parse( + factory Chunk.parse( Parser parser, FileEncoding encoding, Compression? compression, diff --git a/lib/src/common/enums.dart b/packages/tiled/lib/src/common/enums.dart similarity index 100% rename from lib/src/common/enums.dart rename to packages/tiled/lib/src/common/enums.dart diff --git a/lib/src/common/flips.dart b/packages/tiled/lib/src/common/flips.dart similarity index 100% rename from lib/src/common/flips.dart rename to packages/tiled/lib/src/common/flips.dart diff --git a/lib/src/common/frame.dart b/packages/tiled/lib/src/common/frame.dart similarity index 74% rename from lib/src/common/frame.dart rename to packages/tiled/lib/src/common/frame.dart index ffd6228..72e4633 100644 --- a/lib/src/common/frame.dart +++ b/packages/tiled/lib/src/common/frame.dart @@ -17,10 +17,9 @@ class Frame { required this.duration, }); - static Frame parse(Parser parser) { - return Frame( - tileId: parser.getInt('tileid'), - duration: parser.getInt('duration'), - ); - } + Frame.parse(Parser parser) + : this( + tileId: parser.getInt('tileid'), + duration: parser.getInt('duration'), + ); } diff --git a/lib/src/common/gid.dart b/packages/tiled/lib/src/common/gid.dart similarity index 100% rename from lib/src/common/gid.dart rename to packages/tiled/lib/src/common/gid.dart diff --git a/lib/src/common/point.dart b/packages/tiled/lib/src/common/point.dart similarity index 72% rename from lib/src/common/point.dart rename to packages/tiled/lib/src/common/point.dart index 6676038..6db84ef 100644 --- a/lib/src/common/point.dart +++ b/packages/tiled/lib/src/common/point.dart @@ -13,14 +13,13 @@ class Point { Point({required this.x, required this.y}); - static Point parse(Parser parser) { - return Point( - x: parser.getDouble('x'), - y: parser.getDouble('y'), - ); - } + Point.parse(Parser parser) + : this( + x: parser.getDouble('x'), + y: parser.getDouble('y'), + ); - static Point parseFromString(String point) { + factory Point.parseFromString(String point) { final split = point.split(','); return Point( x: double.parse(split[0]), diff --git a/lib/src/common/property.dart b/packages/tiled/lib/src/common/property.dart similarity index 80% rename from lib/src/common/property.dart rename to packages/tiled/lib/src/common/property.dart index 7e0762f..3360b27 100644 --- a/lib/src/common/property.dart +++ b/packages/tiled/lib/src/common/property.dart @@ -15,7 +15,7 @@ part of tiled; class Property { String name; PropertyType type; - // TODO(luan) support other property types + // TODO(luan): support other property types String value; Property({ @@ -24,13 +24,12 @@ class Property { required this.value, }); - static Property parse(Parser parser) { - return Property( - name: parser.getString('name'), - type: parser.getPropertyType('type', defaults: PropertyType.string), - value: parser.getString('value'), - ); - } + Property.parse(Parser parser) + : this( + name: parser.getString('name'), + type: parser.getPropertyType('type', defaults: PropertyType.string), + value: parser.getString('value'), + ); } extension PropertiesParser on Parser { diff --git a/lib/src/common/tiled_image.dart b/packages/tiled/lib/src/common/tiled_image.dart similarity index 80% rename from lib/src/common/tiled_image.dart rename to packages/tiled/lib/src/common/tiled_image.dart index 70d2aec..ed4bdad 100644 --- a/lib/src/common/tiled_image.dart +++ b/packages/tiled/lib/src/common/tiled_image.dart @@ -5,7 +5,8 @@ part of tiled; /// /// /// -/// * format: Used for embedded images, in combination with a data child element. +/// * format: Used for embedded images, in combination with a data child +/// element. /// Valid values are file extensions like png, gif, jpg, bmp, etc. /// * source: The reference to the tileset image file (Tiled supports most /// common image formats). Only used if the image is not embedded. @@ -32,15 +33,14 @@ class TiledImage { this.trans, }); - static TiledImage parse(Parser parser) { - return TiledImage( - source: parser.getStringOrNull('source'), - format: parser.getStringOrNull('format'), - width: parser.getIntOrNull('width'), - height: parser.getIntOrNull('height'), - trans: parser.getStringOrNull('trans'), - ); - } + TiledImage.parse(Parser parser) + : this( + source: parser.getStringOrNull('source'), + format: parser.getStringOrNull('format'), + width: parser.getIntOrNull('width'), + height: parser.getIntOrNull('height'), + trans: parser.getStringOrNull('trans'), + ); /// Needed for getTiledImages in TileMap; /// Images are equal if their source is equal. diff --git a/lib/src/editor_setting/chunk_size.dart b/packages/tiled/lib/src/editor_setting/chunk_size.dart similarity index 68% rename from lib/src/editor_setting/chunk_size.dart rename to packages/tiled/lib/src/editor_setting/chunk_size.dart index 1b62ca2..f4167ed 100644 --- a/lib/src/editor_setting/chunk_size.dart +++ b/packages/tiled/lib/src/editor_setting/chunk_size.dart @@ -13,10 +13,9 @@ class ChunkSize { ChunkSize({required this.width, required this.height}); - static ChunkSize parse(Parser parser) { - return ChunkSize( - width: parser.getInt('width', defaults: 16), - height: parser.getInt('height', defaults: 16), - ); - } + ChunkSize.parse(Parser parser) + : this( + width: parser.getInt('width', defaults: 16), + height: parser.getInt('height', defaults: 16), + ); } diff --git a/lib/src/editor_setting/editor_setting.dart b/packages/tiled/lib/src/editor_setting/editor_setting.dart similarity index 64% rename from lib/src/editor_setting/editor_setting.dart rename to packages/tiled/lib/src/editor_setting/editor_setting.dart index 8778a01..d27dc03 100644 --- a/lib/src/editor_setting/editor_setting.dart +++ b/packages/tiled/lib/src/editor_setting/editor_setting.dart @@ -14,10 +14,10 @@ class EditorSetting { EditorSetting({required this.chunkSize, required this.export}); - static EditorSetting parse(Parser parser) { - return EditorSetting( - chunkSize: parser.getSingleChildOrNullAs('chunksize', ChunkSize.parse), - export: parser.getSingleChildOrNullAs('export', Export.parse), - ); - } + EditorSetting.parse(Parser parser) + : this( + chunkSize: + parser.getSingleChildOrNullAs('chunksize', ChunkSize.parse), + export: parser.getSingleChildOrNullAs('export', Export.parse), + ); } diff --git a/lib/src/editor_setting/export.dart b/packages/tiled/lib/src/editor_setting/export.dart similarity index 71% rename from lib/src/editor_setting/export.dart rename to packages/tiled/lib/src/editor_setting/export.dart index 840af79..ec395ea 100644 --- a/lib/src/editor_setting/export.dart +++ b/packages/tiled/lib/src/editor_setting/export.dart @@ -16,10 +16,9 @@ class Export { required this.target, }); - static Export parse(Parser parser) { - return Export( - format: parser.getString('format'), - target: parser.getString('target'), - ); - } + Export.parse(Parser parser) + : this( + format: parser.getString('format'), + target: parser.getString('target'), + ); } diff --git a/lib/src/layer.dart b/packages/tiled/lib/src/layer.dart similarity index 82% rename from lib/src/layer.dart rename to packages/tiled/lib/src/layer.dart index b8ecb11..4a73de1 100644 --- a/lib/src/layer.dart +++ b/packages/tiled/lib/src/layer.dart @@ -331,7 +331,6 @@ abstract class Layer { decompressed = GZipDecoder().decodeBytes(decodedString); break; case Compression.zstd: - // TODO(luan) zstd compression not supported in dart throw UnsupportedError('zstd is an unsupported compression'); case null: decompressed = decodedString; @@ -381,22 +380,22 @@ class TileLayer extends Layer { List>? tileData; TileLayer({ - int? id, - required String name, - String? class_, - int x = 0, - int y = 0, - double offsetX = 0, - double offsetY = 0, - double parallaxX = 1, - double parallaxY = 1, - int? startX, - int? startY, - String? tintColorHex, - Color? tintColor, - double opacity = 1, - bool visible = true, - List properties = const [], + super.id, + required super.name, + super.class_, + super.x, + super.y, + super.offsetX, + super.offsetY, + super.parallaxX, + super.parallaxY, + super.startX, + super.startY, + super.tintColorHex, + super.tintColor, + super.opacity, + super.visible, + super.properties, required this.width, required this.height, this.compression, @@ -405,23 +404,7 @@ class TileLayer extends Layer { this.data, }) : tileData = maybeGenerate(data, width, height), super( - id: id, - name: name, type: LayerType.tileLayer, - class_: class_, - x: x, - y: y, - offsetX: offsetX, - offsetY: offsetY, - parallaxX: parallaxX, - parallaxY: parallaxY, - startX: startX, - startY: startY, - tintColorHex: tintColorHex, - tintColor: tintColor, - opacity: opacity, - visible: visible, - properties: properties, ); static List>? maybeGenerate( @@ -458,44 +441,28 @@ class ObjectGroup extends Layer { Color color; ObjectGroup({ - int? id, - required String name, - String? class_, - int x = 0, - int y = 0, - double offsetX = 0, - double offsetY = 0, - double parallaxX = 1, - double parallaxY = 1, - int? startX, - int? startY, - String? tintColorHex, - Color? tintColor, - double opacity = 1, - bool visible = true, - List properties = const [], + super.id, + required super.name, + super.class_, + super.x, + super.y, + super.offsetX, + super.offsetY, + super.parallaxX, + super.parallaxY, + super.startX, + super.startY, + super.tintColorHex, + super.tintColor, + super.opacity, + super.visible, + super.properties, this.drawOrder = DrawOrder.topDown, required this.objects, this.colorHex = defaultColorHex, this.color = defaultColor, }) : super( - id: id, - name: name, type: LayerType.objectGroup, - class_: class_, - x: x, - y: y, - offsetX: offsetX, - offsetY: offsetY, - parallaxX: parallaxX, - parallaxY: parallaxY, - startX: startX, - startY: startY, - tintColorHex: tintColorHex, - tintColor: tintColor, - opacity: opacity, - visible: visible, - properties: properties, ); } @@ -520,45 +487,29 @@ class ImageLayer extends Layer { bool repeatY; ImageLayer({ - int? id, - required String name, - String? class_, - int x = 0, - int y = 0, - double offsetX = 0, - double offsetY = 0, - double parallaxX = 1, - double parallaxY = 1, - int? startX, - int? startY, - String? tintColorHex, - Color? tintColor, - double opacity = 1, - bool visible = true, - List properties = const [], + super.id, + required super.name, + super.class_, + super.x, + super.y, + super.offsetX, + super.offsetY, + super.parallaxX, + super.parallaxY, + super.startX, + super.startY, + super.tintColorHex, + super.tintColor, + super.opacity, + super.visible, + super.properties, required this.image, required this.repeatX, required this.repeatY, this.transparentColorHex, this.transparentColor, }) : super( - id: id, - name: name, type: LayerType.imageLayer, - class_: class_, - x: x, - y: y, - offsetX: offsetX, - offsetY: offsetY, - parallaxX: parallaxX, - parallaxY: parallaxY, - startX: startX, - startY: startY, - tintColorHex: tintColorHex, - tintColor: tintColor, - opacity: opacity, - visible: visible, - properties: properties, ); } @@ -567,40 +518,24 @@ class Group extends Layer { List layers; Group({ - int? id, - required String name, - String? class_, - int x = 0, - int y = 0, - double offsetX = 0, - double offsetY = 0, - double parallaxX = 1, - double parallaxY = 1, - int? startX, - int? startY, - String? tintColorHex, - Color? tintColor, - double opacity = 1, - bool visible = true, - List properties = const [], + super.id, + required super.name, + super.class_, + super.x, + super.y, + super.offsetX, + super.offsetY, + super.parallaxX, + super.parallaxY, + super.startX, + super.startY, + super.tintColorHex, + super.tintColor, + super.opacity, + super.visible, + super.properties, required this.layers, }) : super( - id: id, - name: name, type: LayerType.imageLayer, - class_: class_, - x: x, - y: y, - offsetX: offsetX, - offsetY: offsetY, - parallaxX: parallaxX, - parallaxY: parallaxY, - startX: startX, - startY: startY, - tintColorHex: tintColorHex, - tintColor: tintColor, - opacity: opacity, - visible: visible, - properties: properties, ); } diff --git a/lib/src/objects/text.dart b/packages/tiled/lib/src/objects/text.dart similarity index 74% rename from lib/src/objects/text.dart rename to packages/tiled/lib/src/objects/text.dart index fcac8e8..5ac76e3 100644 --- a/lib/src/objects/text.dart +++ b/packages/tiled/lib/src/objects/text.dart @@ -69,20 +69,19 @@ class Text { this.wrap = false, }); - static Text parse(Parser parser) { - return Text( - fontFamily: parser.getString('fontFamily', defaults: 'sans-serif'), - pixelSize: parser.getInt('pixelSize', defaults: 16), - color: parser.getString('color', defaults: '#000000'), - text: parser.getString('text', defaults: ''), - hAlign: parser.getHAlign('hAlign', defaults: HAlign.left), - vAlign: parser.getVAlign('vAlign', defaults: VAlign.top), - bold: parser.getBool('bold', defaults: false), - italic: parser.getBool('italic', defaults: false), - underline: parser.getBool('underline', defaults: false), - strikeout: parser.getBool('strikeout', defaults: false), - kerning: parser.getBool('kerning', defaults: true), - wrap: parser.getBool('wrap', defaults: false), - ); - } + Text.parse(Parser parser) + : this( + fontFamily: parser.getString('fontFamily', defaults: 'sans-serif'), + pixelSize: parser.getInt('pixelSize', defaults: 16), + color: parser.getString('color', defaults: '#000000'), + text: parser.getString('text', defaults: ''), + hAlign: parser.getHAlign('hAlign', defaults: HAlign.left), + vAlign: parser.getVAlign('vAlign', defaults: VAlign.top), + bold: parser.getBool('bold', defaults: false), + italic: parser.getBool('italic', defaults: false), + underline: parser.getBool('underline', defaults: false), + strikeout: parser.getBool('strikeout', defaults: false), + kerning: parser.getBool('kerning', defaults: true), + wrap: parser.getBool('wrap', defaults: false), + ); } diff --git a/lib/src/objects/tiled_object.dart b/packages/tiled/lib/src/objects/tiled_object.dart similarity index 97% rename from lib/src/objects/tiled_object.dart rename to packages/tiled/lib/src/objects/tiled_object.dart index bdf70fc..239b1bb 100644 --- a/lib/src/objects/tiled_object.dart +++ b/packages/tiled/lib/src/objects/tiled_object.dart @@ -98,7 +98,7 @@ class TiledObject { bool get isEllipse => ellipse; bool get isRectangle => rectangle; - static TiledObject parse(Parser parser) { + factory TiledObject.parse(Parser parser) { final x = parser.getDouble('x', defaults: 0); final y = parser.getDouble('y', defaults: 0); final height = parser.getDouble('height', defaults: 0); @@ -109,8 +109,9 @@ class TiledObject { final gid = parser.getIntOrNull('gid'); final name = parser.getString('name', defaults: ''); - // Tiled 1.9 and above versions running in compatibilty mode set to "Tiled 1.8" will - // still write out "Class" property as "type". So try both before using default value. + // Tiled 1.9 and above versions running in compatibilty mode set to + // "Tiled 1.8" will still write out "Class" property as "type". So try both + // before using default value. final type = parser.getString( 'class', defaults: parser.getString('type', defaults: ''), diff --git a/lib/src/parser.dart b/packages/tiled/lib/src/parser.dart similarity index 98% rename from lib/src/parser.dart rename to packages/tiled/lib/src/parser.dart index 6f4c40a..3cd278a 100644 --- a/lib/src/parser.dart +++ b/packages/tiled/lib/src/parser.dart @@ -21,7 +21,7 @@ class XmlParser extends Parser { return element.children .whereType() .where((e) => e.name.local == name) - .map((e) => XmlParser(e)) + .map(XmlParser.new) .toList(); } @@ -29,7 +29,7 @@ class XmlParser extends Parser { return element.children .whereType() .where((e) => names.contains(e.name.local)) - .map((e) => XmlParser(e)) + .map(XmlParser.new) .toList(); } diff --git a/lib/src/template.dart b/packages/tiled/lib/src/template.dart similarity index 76% rename from lib/src/template.dart rename to packages/tiled/lib/src/template.dart index 8cc34c4..40d1acb 100644 --- a/lib/src/template.dart +++ b/packages/tiled/lib/src/template.dart @@ -28,10 +28,9 @@ class Template { this.object, }); - static Template parse(Parser parser) { - return Template( - tileSet: parser.getSingleChildOrNullAs('tileset', Tileset.parse), - object: parser.getSingleChildOrNullAs('object', TiledObject.parse), - ); - } + Template.parse(Parser parser) + : this( + tileSet: parser.getSingleChildOrNullAs('tileset', Tileset.parse), + object: parser.getSingleChildOrNullAs('object', TiledObject.parse), + ); } diff --git a/lib/src/tile_map_parser.dart b/packages/tiled/lib/src/tile_map_parser.dart similarity index 100% rename from lib/src/tile_map_parser.dart rename to packages/tiled/lib/src/tile_map_parser.dart diff --git a/lib/src/tiled_map.dart b/packages/tiled/lib/src/tiled_map.dart similarity index 96% rename from lib/src/tiled_map.dart rename to packages/tiled/lib/src/tiled_map.dart index 5e25d54..e1a4e29 100644 --- a/lib/src/tiled_map.dart +++ b/packages/tiled/lib/src/tiled_map.dart @@ -28,7 +28,8 @@ part of tiled; /// * staggerindex: For staggered and hexagonal maps, determines whether the /// “even” or “odd” indexes along the staggered axis are shifted. (since 0.11) /// * backgroundcolor: The background color of the map. (optional, may include -/// alpha value since 0.15 in the form #AARRGGBB. Defaults to fully transparent.) +/// alpha value since 0.15 in the form #AARRGGBB.) +/// Defaults to fully transparent. /// * nextlayerid: Stores the next available ID for new layers. This number is /// stored to prevent reuse of the same ID after layers have been removed. /// (since 1.2) (defaults to the highest layer id in the file + 1) @@ -148,27 +149,25 @@ class TiledMap { } // Convenience Methods - Tile tileByGid(int tileGid) { + Tile? tileByGid(int tileGid) { if (tileGid == 0) { return Tile(localId: -1); } final tileset = tilesetByTileGId(tileGid); final firstGid = tileset.firstGid ?? 0; - return tileset.tiles.firstWhere( + return tileset.tiles.firstWhereOrNull( (element) => element.localId == (tileGid - firstGid), - orElse: null, ); } - Tile tileByLocalId(String tileSetName, int localId) { + Tile? tileByLocalId(String tileSetName, int localId) { final tileset = tilesetByName(tileSetName); - return tileset.tiles.firstWhere( + return tileset.tiles.firstWhereOrNull( (element) => element.localId == localId, - orElse: null, ); } - Tile tileByPhrase(String tilePhrase) { + Tile? tileByPhrase(String tilePhrase) { final split = tilePhrase.split('|'); if (split.length != 2) { throw ArgumentError( @@ -255,7 +254,7 @@ class TiledMap { ); } - static TiledMap parse(Parser parser, {List? tsxList}) { + factory TiledMap.parse(Parser parser, {List? tsxList}) { final backgroundColorHex = parser.getStringOrNull('backgroundcolor'); final backgroundColor = parser.getColorOrNull('backgroundcolor'); final compressionLevel = parser.getInt('compressionlevel', defaults: -1); diff --git a/lib/src/tileset/grid.dart b/packages/tiled/lib/src/tileset/grid.dart similarity index 76% rename from lib/src/tileset/grid.dart rename to packages/tiled/lib/src/tileset/grid.dart index 035558d..3dc26cf 100644 --- a/lib/src/tileset/grid.dart +++ b/packages/tiled/lib/src/tileset/grid.dart @@ -23,11 +23,10 @@ class Grid { required this.orientation, }); - static Grid parse(Parser parser) { - return Grid( - width: parser.getInt('width'), - height: parser.getInt('height'), - orientation: parser.getGridOrientation('orientation'), - ); - } + Grid.parse(Parser parser) + : this( + width: parser.getInt('width'), + height: parser.getInt('height'), + orientation: parser.getGridOrientation('orientation'), + ); } diff --git a/lib/src/tileset/terrain.dart b/packages/tiled/lib/src/tileset/terrain.dart similarity index 71% rename from lib/src/tileset/terrain.dart rename to packages/tiled/lib/src/tileset/terrain.dart index cf48b15..c27ad4e 100644 --- a/lib/src/tileset/terrain.dart +++ b/packages/tiled/lib/src/tileset/terrain.dart @@ -20,11 +20,10 @@ class Terrain { this.properties = const [], }); - static Terrain parse(Parser parser) { - return Terrain( - name: parser.getString('name'), - tile: parser.getInt('name'), - properties: parser.getProperties(), - ); - } + Terrain.parse(Parser parser) + : this( + name: parser.getString('name'), + tile: parser.getInt('name'), + properties: parser.getProperties(), + ); } diff --git a/lib/src/tileset/tile.dart b/packages/tiled/lib/src/tileset/tile.dart similarity index 58% rename from lib/src/tileset/tile.dart rename to packages/tiled/lib/src/tileset/tile.dart index cd3abcf..059a134 100644 --- a/lib/src/tileset/tile.dart +++ b/packages/tiled/lib/src/tileset/tile.dart @@ -48,31 +48,32 @@ class Tile { /// Will be same as [type]. String? get class_ => type; - static Tile parse(Parser parser) { - return Tile( - localId: parser.getInt('id'), + Tile.parse(Parser parser) + : this( + localId: parser.getInt('id'), - /// Tiled 1.9 "type" has been moved to "class" - type: parser.getStringOrNull('class') ?? parser.getStringOrNull('type'), + /// Tiled 1.9 "type" has been moved to "class" + type: + parser.getStringOrNull('class') ?? parser.getStringOrNull('type'), - probability: parser.getDouble('probability', defaults: 0), - terrain: parser - .getStringOrNull('terrain') - ?.split(',') - .map(int.parse) - .toList() ?? - [], - image: parser.getSingleChildOrNullAs('image', TiledImage.parse), - objectGroup: parser.getSingleChildOrNullAs('objectgroup', Layer.parse), - animation: parser.formatSpecificParsing( - (json) => json.getChildrenAs('animation', Frame.parse), - (xml) => - xml - .getSingleChildOrNull('animation') - ?.getChildrenAs('frame', Frame.parse) ?? - [], - ), - properties: parser.getProperties(), - ); - } + probability: parser.getDouble('probability', defaults: 0), + terrain: parser + .getStringOrNull('terrain') + ?.split(',') + .map(int.parse) + .toList() ?? + [], + image: parser.getSingleChildOrNullAs('image', TiledImage.parse), + objectGroup: + parser.getSingleChildOrNullAs('objectgroup', Layer.parse), + animation: parser.formatSpecificParsing( + (json) => json.getChildrenAs('animation', Frame.parse), + (xml) => + xml + .getSingleChildOrNull('animation') + ?.getChildrenAs('frame', Frame.parse) ?? + [], + ), + properties: parser.getProperties(), + ); } diff --git a/lib/src/tileset/tile_offset.dart b/packages/tiled/lib/src/tileset/tile_offset.dart similarity index 76% rename from lib/src/tileset/tile_offset.dart rename to packages/tiled/lib/src/tileset/tile_offset.dart index 775c4f3..3b6c985 100644 --- a/lib/src/tileset/tile_offset.dart +++ b/packages/tiled/lib/src/tileset/tile_offset.dart @@ -20,10 +20,9 @@ class TileOffset { required this.y, }); - static TileOffset parse(Parser parser) { - return TileOffset( - x: parser.getInt('x', defaults: 0), - y: parser.getInt('y', defaults: 0), - ); - } + TileOffset.parse(Parser parser) + : this( + x: parser.getInt('x', defaults: 0), + y: parser.getInt('y', defaults: 0), + ); } diff --git a/lib/src/tileset/tileset.dart b/packages/tiled/lib/src/tileset/tileset.dart similarity index 99% rename from lib/src/tileset/tileset.dart rename to packages/tiled/lib/src/tileset/tileset.dart index bde4a92..bdaa1bc 100644 --- a/lib/src/tileset/tileset.dart +++ b/packages/tiled/lib/src/tileset/tileset.dart @@ -97,7 +97,7 @@ class Tileset { tileCount = this.tiles.length; } - static Tileset parse(Parser parser, {TsxProvider? tsx}) { + factory Tileset.parse(Parser parser, {TsxProvider? tsx}) { final backgroundColor = parser.getStringOrNull('backgroundcolor'); final columns = parser.getIntOrNull('columns'); final firstGid = parser.getIntOrNull('firstgid'); diff --git a/lib/src/tileset/wang/wang_color.dart b/packages/tiled/lib/src/tileset/wang/wang_color.dart similarity index 67% rename from lib/src/tileset/wang/wang_color.dart rename to packages/tiled/lib/src/tileset/wang/wang_color.dart index 9653bf0..f8ef3f0 100644 --- a/lib/src/tileset/wang/wang_color.dart +++ b/packages/tiled/lib/src/tileset/wang/wang_color.dart @@ -9,7 +9,8 @@ part of tiled; /// * name: The name of this color. /// * color: The color in #RRGGBB format (example: #c17d11). /// * tile: The tile ID of the tile representing this color. -/// * probability: The relative probability that this color is chosen over others in case of multiple options. (defaults to 0) +/// * probability: The relative probability that this color is chosen over +/// others in case of multiple options. (defaults to 0) /// /// Can contain at most one: class WangColor { @@ -28,13 +29,12 @@ class WangColor { this.properties = const [], }); - static WangColor parse(Parser parser) { - return WangColor( - name: parser.getString('name'), - color: parser.getString('color'), - tile: parser.getInt('tile'), - probability: parser.getDouble('probability', defaults: 0), - properties: parser.getProperties(), - ); - } + WangColor.parse(Parser parser) + : this( + name: parser.getString('name'), + color: parser.getString('color'), + tile: parser.getInt('tile'), + probability: parser.getDouble('probability', defaults: 0), + properties: parser.getProperties(), + ); } diff --git a/lib/src/tileset/wang/wang_set.dart b/packages/tiled/lib/src/tileset/wang/wang_set.dart similarity index 97% rename from lib/src/tileset/wang/wang_set.dart rename to packages/tiled/lib/src/tileset/wang/wang_set.dart index 0375d7d..c87bb54 100644 --- a/lib/src/tileset/wang/wang_set.dart +++ b/packages/tiled/lib/src/tileset/wang/wang_set.dart @@ -32,7 +32,7 @@ class WangSet { this.properties = const [], }); - static WangSet parse(Parser parser) { + factory WangSet.parse(Parser parser) { final colors = parser.formatSpecificParsing( (json) => [ json.getChildrenAs('cornercolors', WangColor.parse), diff --git a/lib/src/tileset/wang/wang_tile.dart b/packages/tiled/lib/src/tileset/wang/wang_tile.dart similarity index 74% rename from lib/src/tileset/wang/wang_tile.dart rename to packages/tiled/lib/src/tileset/wang/wang_tile.dart index 26f8490..a069d5d 100644 --- a/lib/src/tileset/wang/wang_tile.dart +++ b/packages/tiled/lib/src/tileset/wang/wang_tile.dart @@ -34,20 +34,20 @@ class WangTile { this.dFlip = false, }); - static WangTile parse(Parser parser) { - return WangTile( - tileId: parser.getInt('tileid'), - wangId: parseWangIds( - parser.formatSpecificParsing( - (json) => json.getIntList('wangid'), - (xml) => xml.getString('wangid').split(',').map(int.parse).toList(), - ), - ), - hFlip: parser.getBool('hflip', defaults: false), - vFlip: parser.getBool('vflip', defaults: false), - dFlip: parser.getBool('dflip', defaults: false), - ); - } + WangTile.parse(Parser parser) + : this( + tileId: parser.getInt('tileid'), + wangId: parseWangIds( + parser.formatSpecificParsing( + (json) => json.getIntList('wangid'), + (xml) => + xml.getString('wangid').split(',').map(int.parse).toList(), + ), + ), + hFlip: parser.getBool('hflip', defaults: false), + vFlip: parser.getBool('vflip', defaults: false), + dFlip: parser.getBool('dflip', defaults: false), + ); static List parseWangIds(List value) { final bytes = Uint8List.fromList(value); diff --git a/lib/src/tsx_provider.dart b/packages/tiled/lib/src/tsx_provider.dart similarity index 100% rename from lib/src/tsx_provider.dart rename to packages/tiled/lib/src/tsx_provider.dart diff --git a/lib/tiled.dart b/packages/tiled/lib/tiled.dart similarity index 96% rename from lib/tiled.dart rename to packages/tiled/lib/tiled.dart index 939e264..4907cc5 100644 --- a/lib/tiled.dart +++ b/packages/tiled/lib/tiled.dart @@ -7,10 +7,10 @@ import 'dart:typed_data'; import 'dart:ui'; import 'package:archive/archive.dart'; +import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; import 'package:xml/xml.dart'; -part 'src/parser.dart'; part 'src/chunk.dart'; part 'src/common/enums.dart'; part 'src/common/flips.dart'; @@ -25,6 +25,7 @@ part 'src/editor_setting/export.dart'; part 'src/layer.dart'; part 'src/objects/text.dart'; part 'src/objects/tiled_object.dart'; +part 'src/parser.dart'; part 'src/template.dart'; part 'src/tile_map_parser.dart'; part 'src/tiled_map.dart'; diff --git a/pubspec.yaml b/packages/tiled/pubspec.yaml similarity index 78% rename from pubspec.yaml rename to packages/tiled/pubspec.yaml index 06aee40..0d2c5bd 100644 --- a/pubspec.yaml +++ b/packages/tiled/pubspec.yaml @@ -4,15 +4,16 @@ description: A Dart Tiled library. Parse your TMX files into useful representati homepage: https://github.com/flame-engine/tiled.dart environment: - sdk: ">=2.14.0 <3.0.0" + sdk: ">=2.18.0 <3.0.0" dependencies: + archive: ^3.3.0 + collection: ^1.16.0 flutter: sdk: flutter - archive: ^3.3.0 meta: ^1.7.0 xml: ^5.4.1 dev_dependencies: + dartdoc: ^4.1.0 + flame_lint: ^0.1.2 test: any - dartdoc: ^0.42.0 - flame_lint: ^0.0.1 diff --git a/test/complexmap_infinite_test.dart b/packages/tiled/test/complexmap_infinite_test.dart similarity index 100% rename from test/complexmap_infinite_test.dart rename to packages/tiled/test/complexmap_infinite_test.dart diff --git a/test/fixtures/coins.png b/packages/tiled/test/fixtures/coins.png similarity index 100% rename from test/fixtures/coins.png rename to packages/tiled/test/fixtures/coins.png diff --git a/test/fixtures/complexmap.json b/packages/tiled/test/fixtures/complexmap.json similarity index 100% rename from test/fixtures/complexmap.json rename to packages/tiled/test/fixtures/complexmap.json diff --git a/test/fixtures/complexmap.tmx b/packages/tiled/test/fixtures/complexmap.tmx similarity index 100% rename from test/fixtures/complexmap.tmx rename to packages/tiled/test/fixtures/complexmap.tmx diff --git a/test/fixtures/complexmap_infinite.tmx b/packages/tiled/test/fixtures/complexmap_infinite.tmx similarity index 100% rename from test/fixtures/complexmap_infinite.tmx rename to packages/tiled/test/fixtures/complexmap_infinite.tmx diff --git a/test/fixtures/external_tileset_1.tsx b/packages/tiled/test/fixtures/external_tileset_1.tsx similarity index 100% rename from test/fixtures/external_tileset_1.tsx rename to packages/tiled/test/fixtures/external_tileset_1.tsx diff --git a/test/fixtures/external_tileset_2.tsx b/packages/tiled/test/fixtures/external_tileset_2.tsx similarity index 100% rename from test/fixtures/external_tileset_2.tsx rename to packages/tiled/test/fixtures/external_tileset_2.tsx diff --git a/test/fixtures/external_tileset_map.tmx b/packages/tiled/test/fixtures/external_tileset_map.tmx similarity index 100% rename from test/fixtures/external_tileset_map.tmx rename to packages/tiled/test/fixtures/external_tileset_map.tmx diff --git a/test/fixtures/floortileset.png b/packages/tiled/test/fixtures/floortileset.png similarity index 100% rename from test/fixtures/floortileset.png rename to packages/tiled/test/fixtures/floortileset.png diff --git a/test/fixtures/icons.png b/packages/tiled/test/fixtures/icons.png similarity index 100% rename from test/fixtures/icons.png rename to packages/tiled/test/fixtures/icons.png diff --git a/test/fixtures/icons.xcf b/packages/tiled/test/fixtures/icons.xcf similarity index 100% rename from test/fixtures/icons.xcf rename to packages/tiled/test/fixtures/icons.xcf diff --git a/test/fixtures/image1.png b/packages/tiled/test/fixtures/image1.png similarity index 100% rename from test/fixtures/image1.png rename to packages/tiled/test/fixtures/image1.png diff --git a/test/fixtures/image2.png b/packages/tiled/test/fixtures/image2.png similarity index 100% rename from test/fixtures/image2.png rename to packages/tiled/test/fixtures/image2.png diff --git a/test/fixtures/imagelayer.tmx b/packages/tiled/test/fixtures/imagelayer.tmx similarity index 100% rename from test/fixtures/imagelayer.tmx rename to packages/tiled/test/fixtures/imagelayer.tmx diff --git a/test/fixtures/isometric_grass_and_water.png b/packages/tiled/test/fixtures/isometric_grass_and_water.png similarity index 100% rename from test/fixtures/isometric_grass_and_water.png rename to packages/tiled/test/fixtures/isometric_grass_and_water.png diff --git a/test/fixtures/isometric_grass_and_water.tmx b/packages/tiled/test/fixtures/isometric_grass_and_water.tmx similarity index 100% rename from test/fixtures/isometric_grass_and_water.tmx rename to packages/tiled/test/fixtures/isometric_grass_and_water.tmx diff --git a/test/fixtures/isometric_staggered_grass_and_water.json b/packages/tiled/test/fixtures/isometric_staggered_grass_and_water.json similarity index 100% rename from test/fixtures/isometric_staggered_grass_and_water.json rename to packages/tiled/test/fixtures/isometric_staggered_grass_and_water.json diff --git a/test/fixtures/isometric_staggered_grass_and_water.tmx b/packages/tiled/test/fixtures/isometric_staggered_grass_and_water.tmx similarity index 100% rename from test/fixtures/isometric_staggered_grass_and_water.tmx rename to packages/tiled/test/fixtures/isometric_staggered_grass_and_water.tmx diff --git a/test/fixtures/level1.png b/packages/tiled/test/fixtures/level1.png similarity index 100% rename from test/fixtures/level1.png rename to packages/tiled/test/fixtures/level1.png diff --git a/test/fixtures/map.tmx b/packages/tiled/test/fixtures/map.tmx similarity index 100% rename from test/fixtures/map.tmx rename to packages/tiled/test/fixtures/map.tmx diff --git a/test/fixtures/map_images.tmx b/packages/tiled/test/fixtures/map_images.tmx similarity index 100% rename from test/fixtures/map_images.tmx rename to packages/tiled/test/fixtures/map_images.tmx diff --git a/test/fixtures/map_with_multiple_tilesets.tmx b/packages/tiled/test/fixtures/map_with_multiple_tilesets.tmx similarity index 100% rename from test/fixtures/map_with_multiple_tilesets.tmx rename to packages/tiled/test/fixtures/map_with_multiple_tilesets.tmx diff --git a/test/fixtures/map_with_spacing_margin.tmx b/packages/tiled/test/fixtures/map_with_spacing_margin.tmx similarity index 100% rename from test/fixtures/map_with_spacing_margin.tmx rename to packages/tiled/test/fixtures/map_with_spacing_margin.tmx diff --git a/test/fixtures/map_with_tile_collision.tsx b/packages/tiled/test/fixtures/map_with_tile_collision.tsx similarity index 100% rename from test/fixtures/map_with_tile_collision.tsx rename to packages/tiled/test/fixtures/map_with_tile_collision.tsx diff --git a/test/fixtures/objectgroup.json b/packages/tiled/test/fixtures/objectgroup.json similarity index 100% rename from test/fixtures/objectgroup.json rename to packages/tiled/test/fixtures/objectgroup.json diff --git a/test/fixtures/objectgroup.tmx b/packages/tiled/test/fixtures/objectgroup.tmx similarity index 100% rename from test/fixtures/objectgroup.tmx rename to packages/tiled/test/fixtures/objectgroup.tmx diff --git a/test/fixtures/rectangle.tmx b/packages/tiled/test/fixtures/rectangle.tmx similarity index 100% rename from test/fixtures/rectangle.tmx rename to packages/tiled/test/fixtures/rectangle.tmx diff --git a/test/fixtures/test.tmx b/packages/tiled/test/fixtures/test.tmx similarity index 100% rename from test/fixtures/test.tmx rename to packages/tiled/test/fixtures/test.tmx diff --git a/test/fixtures/test_base64_gzip.tmx b/packages/tiled/test/fixtures/test_base64_gzip.tmx similarity index 100% rename from test/fixtures/test_base64_gzip.tmx rename to packages/tiled/test/fixtures/test_base64_gzip.tmx diff --git a/test/fixtures/test_csv.tmx b/packages/tiled/test/fixtures/test_csv.tmx similarity index 100% rename from test/fixtures/test_csv.tmx rename to packages/tiled/test/fixtures/test_csv.tmx diff --git a/test/fixtures/test_old.tmx b/packages/tiled/test/fixtures/test_old.tmx similarity index 100% rename from test/fixtures/test_old.tmx rename to packages/tiled/test/fixtures/test_old.tmx diff --git a/test/fixtures/testbase64only.json b/packages/tiled/test/fixtures/testbase64only.json similarity index 100% rename from test/fixtures/testbase64only.json rename to packages/tiled/test/fixtures/testbase64only.json diff --git a/test/fixtures/testcsv.json b/packages/tiled/test/fixtures/testcsv.json similarity index 100% rename from test/fixtures/testcsv.json rename to packages/tiled/test/fixtures/testcsv.json diff --git a/test/fixtures/testgzip.json b/packages/tiled/test/fixtures/testgzip.json similarity index 100% rename from test/fixtures/testgzip.json rename to packages/tiled/test/fixtures/testgzip.json diff --git a/test/fixtures/testoverflow.tmx b/packages/tiled/test/fixtures/testoverflow.tmx similarity index 100% rename from test/fixtures/testoverflow.tmx rename to packages/tiled/test/fixtures/testoverflow.tmx diff --git a/test/fixtures/testoverflow_csv.tmx b/packages/tiled/test/fixtures/testoverflow_csv.tmx similarity index 100% rename from test/fixtures/testoverflow_csv.tmx rename to packages/tiled/test/fixtures/testoverflow_csv.tmx diff --git a/test/fixtures/testzlib.json b/packages/tiled/test/fixtures/testzlib.json similarity index 100% rename from test/fixtures/testzlib.json rename to packages/tiled/test/fixtures/testzlib.json diff --git a/test/fixtures/tileid_over_tilecount.tsx b/packages/tiled/test/fixtures/tileid_over_tilecount.tsx similarity index 100% rename from test/fixtures/tileid_over_tilecount.tsx rename to packages/tiled/test/fixtures/tileid_over_tilecount.tsx diff --git a/test/fixtures/tileset.tsx b/packages/tiled/test/fixtures/tileset.tsx similarity index 100% rename from test/fixtures/tileset.tsx rename to packages/tiled/test/fixtures/tileset.tsx diff --git a/test/fixtures/tilesets_deviant_milkian_1.png b/packages/tiled/test/fixtures/tilesets_deviant_milkian_1.png similarity index 100% rename from test/fixtures/tilesets_deviant_milkian_1.png rename to packages/tiled/test/fixtures/tilesets_deviant_milkian_1.png diff --git a/test/image_layer_test.dart b/packages/tiled/test/image_layer_test.dart similarity index 100% rename from test/image_layer_test.dart rename to packages/tiled/test/image_layer_test.dart diff --git a/test/isometric_staggered_test.dart b/packages/tiled/test/isometric_staggered_test.dart similarity index 100% rename from test/isometric_staggered_test.dart rename to packages/tiled/test/isometric_staggered_test.dart diff --git a/test/isometric_test.dart b/packages/tiled/test/isometric_test.dart similarity index 100% rename from test/isometric_test.dart rename to packages/tiled/test/isometric_test.dart diff --git a/test/layer_test.dart b/packages/tiled/test/layer_test.dart similarity index 100% rename from test/layer_test.dart rename to packages/tiled/test/layer_test.dart diff --git a/test/map_test.dart b/packages/tiled/test/map_test.dart similarity index 92% rename from test/map_test.dart rename to packages/tiled/test/map_test.dart index b7273fd..3525347 100644 --- a/test/map_test.dart +++ b/packages/tiled/test/map_test.dart @@ -57,7 +57,7 @@ void main() { test('returns an empty Tile if GID is 0', () { final tile = map.tileByGid(0); - expect(tile.isEmpty, isTrue); + expect(tile?.isEmpty, isTrue); }); test('GID = 4 && with tileId = 2', () { @@ -65,8 +65,8 @@ void main() { // Tile 2 => gid = 5 + 2 = 6 final tile = map.tileByGid(7); - expect(tile.localId, equals(2)); - expect(tile.properties.first.name, equals('name')); + expect(tile?.localId, equals(2)); + expect(tile?.properties.first.name, equals('name')); }); }); @@ -89,12 +89,12 @@ void main() { }); test('there should be no tile with a Gid of 0', () { - expect(map.tileByGid(0).localId, equals(-1)); + expect(map.tileByGid(0)?.localId, equals(-1)); }); group('returns a tile', () { late Tile tile; - setUp(() => tile = map.tileByLocalId('Humans', 0)); + setUp(() => tile = map.tileByLocalId('Humans', 0)!); test('with the expected local tile ID', () { expect(tile.localId, equals(0)); @@ -140,7 +140,7 @@ void main() { group('returns a tile', () { late Tile tile; - setUp(() => tile = map.tileByPhrase('Humans|0')); + setUp(() => tile = map.tileByPhrase('Humans|0')!); test('with the expected local tile ID', () { expect(tile.localId, equals(0)); diff --git a/test/object_group_test.dart b/packages/tiled/test/object_group_test.dart similarity index 100% rename from test/object_group_test.dart rename to packages/tiled/test/object_group_test.dart diff --git a/test/overflow_bug_test.dart b/packages/tiled/test/overflow_bug_test.dart similarity index 97% rename from test/overflow_bug_test.dart rename to packages/tiled/test/overflow_bug_test.dart index 7f46770..27e62b7 100644 --- a/test/overflow_bug_test.dart +++ b/packages/tiled/test/overflow_bug_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_print + import 'dart:io'; import 'package:test/test.dart'; diff --git a/test/parser_compare_test.dart b/packages/tiled/test/parser_compare_test.dart similarity index 100% rename from test/parser_compare_test.dart rename to packages/tiled/test/parser_compare_test.dart diff --git a/test/parser_test.dart b/packages/tiled/test/parser_test.dart similarity index 97% rename from test/parser_test.dart rename to packages/tiled/test/parser_test.dart index bc8d104..b9e0624 100644 --- a/test/parser_test.dart +++ b/packages/tiled/test/parser_test.dart @@ -142,8 +142,10 @@ void main() { test('has its width = 10', () => expect(layer.width, equals(10))); test('has its height = 10', () => expect(layer.height, equals(10))); - // This test is very simple. Theoretically, if this case works, they should all work. - // It's a 10x10 matrix because anything smaller seems to default to gzip in Tiled (bug?). + // This test is very simple. Theoretically, if this case works, they + // should all work. + // It's a 10x10 matrix because anything smaller seems to default to gzip + // in Tiled (bug?). test('populates its tile matrix', () { List getDataRow(int idx) { return layer.tileData![idx].map((e) => e.tile).toList(); @@ -240,14 +242,14 @@ void main() { final gid = tileset.firstGid!; - final tile1 = map.tileByGid(gid); + final tile1 = map.tileByGid(gid)!; expect(tile1.image!.source, equals('image1.png')); expect( tileset.computeDrawRect(tile1), equals(const Rectangle(0, 0, 32, 32)), ); - final tile2 = map.tileByGid(gid + 1); + final tile2 = map.tileByGid(gid + 1)!; expect(tile2.image!.source, equals('image2.png')); expect( tileset.computeDrawRect(tile2), @@ -266,7 +268,7 @@ void main() { tsxList: [CustomTsxProvider.parse('tileid_over_tilecount.tsx')], ); expect(map.tilesets[0].tileCount, 137); - final tile = map.tileByGid(1); + final tile = map.tileByGid(1)!; expect(tile.localId, 0); expect(tile.type, 'first_tile'); }); @@ -379,6 +381,11 @@ class CustomTsxProvider extends TsxProvider { CustomTsxProvider._(this.data, this._filename); + factory CustomTsxProvider.parse(String filename) { + final xml = File('./test/fixtures/$filename').readAsStringSync(); + return CustomTsxProvider._(xml, filename); + } + @override String get filename => _filename; @@ -392,9 +399,4 @@ class CustomTsxProvider extends TsxProvider { Parser? getCachedSource() { return getSource(''); } - - static CustomTsxProvider parse(String filename) { - final xml = File('./test/fixtures/$filename').readAsStringSync(); - return CustomTsxProvider._(xml, filename); - } } diff --git a/test/rectangle_map_test.dart b/packages/tiled/test/rectangle_map_test.dart similarity index 100% rename from test/rectangle_map_test.dart rename to packages/tiled/test/rectangle_map_test.dart diff --git a/test/tile_test.dart b/packages/tiled/test/tile_test.dart similarity index 100% rename from test/tile_test.dart rename to packages/tiled/test/tile_test.dart diff --git a/test/tileset_test.dart b/packages/tiled/test/tileset_test.dart similarity index 100% rename from test/tileset_test.dart rename to packages/tiled/test/tileset_test.dart diff --git a/test/tmx_object_test.dart b/packages/tiled/test/tmx_object_test.dart similarity index 100% rename from test/tmx_object_test.dart rename to packages/tiled/test/tmx_object_test.dart