-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: TsxProviderBase with test function #72
base: main
Are you sure you want to change the base?
Conversation
…ontracts // corrected and extended README.md
I've got some questions about the checklist:
|
Super!
The checklist is copied from Flame, you can create an example directory if we don't have one (shame on us 😅). |
I would consider just breaking current implementations, as long as you are willing to write a PR for Overall it's hard to me to tell if this PR makes sense without concrete examples, maybe tests would help with that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to understand why TsxProviderBase
had to be a separate class. If it is just to avoid breaking filename
getter, then I think making that breaking change should be fine.
@@ -29,9 +29,15 @@ Load a TMX file into a string by any means, and then pass the string to TileMapP | |||
final TiledMap mapTmx = TileMapParser.parseTmx(tmxBody); | |||
``` | |||
|
|||
If your tmx file includes a external tsx reference, you have to add a CustomParser | |||
If your tmx file includes a external tsx reference, you have to add a CustomParser. This can either be done by using extending the TsxProviderBase, which can match multiple files, or by extending TsxProvider, which only matches on file by its name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your tmx file includes a external tsx reference, you have to add a CustomParser. This can either be done by using extending the TsxProviderBase, which can match multiple files, or by extending TsxProvider, which only matches on file by its name. | |
If your tmx file includes a external tsx reference, you have to add a CustomParser. This can either be done by extending the TsxProviderBase, which can match multiple files, or by extending TsxProvider, which only matches on file by its name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops missed that on 😅
abstract class TsxProviderBase { | ||
/// Given a filename this function should check whether this Provider | ||
/// can provide this source. | ||
bool checkProvidable(String filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word "check" in checkProvidable
seems to indicate that this method is going to perform some validation on the given filename. How does canProvide
sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that does sound better 👍
@benni-tec any updates on this? :) |
Not yet. My fork currently does everything I need for my current project. I do plan to submit proper PRs for this and the other issues I've opened, however I am currently pretty time constrained. As of now my current project should be wrapped up in January, I am currently planning to clean up and submit PRs then. Is this something that is time-sensitive for you? If so I will see if can get the PRs done this year! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few comments, over all it looks good :)
@@ -29,9 +29,15 @@ Load a TMX file into a string by any means, and then pass the string to TileMapP | |||
final TiledMap mapTmx = TileMapParser.parseTmx(tmxBody); | |||
``` | |||
|
|||
If your tmx file includes a external tsx reference, you have to add a CustomParser | |||
If your tmx file includes a external tsx reference, you have to add a CustomParser. This can either be done by using extending the TsxProviderBase, which can match multiple files, or by extending TsxProvider, which only matches on file by its name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we don't have the markdown linter activated here, the max line length on markdown should be 100.
```dart | ||
final String tmxBody = /* ... */; | ||
final TiledMap mapTmx = TileMapParser.parseTmx(tmxBody, tsx: CustomTsxProvider()); | ||
final TiledMap mapTmx = TileMapParser.parseTmx(tmxBody, tsxProviders: [SingleTsxProvider(), MultipleTsxProvider()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split up line with trailing comma
|
||
XmlParser(this.element, {super.tsxProviders, super.templateProviders}); | ||
|
||
factory XmlParser.fromString( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a named constructor instead of a factory
|
||
JsonParser(this.json, {super.tsxProviders, super.templateProviders}); | ||
|
||
factory JsonParser.fromString( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this can be a named constructor
@@ -34,3 +34,7 @@ class Template { | |||
object: parser.getSingleChildOrNullAs('object', TiledObject.parse), | |||
); | |||
} | |||
|
|||
class TemplateReference { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
// TODO: why is this here? same as parseTmx??? | ||
// static Future<TiledMap> fromString( | ||
// String contents, { | ||
// List<ParserProvider>? tsxProviders, | ||
// List<ParserProvider>? templateProviders, | ||
// List<ImagePathProvider>? imageProviders, | ||
// }) async { | ||
// final tsxSourcePaths = XmlDocument.parse(contents) | ||
// .rootElement | ||
// .children | ||
// .whereType<XmlElement>() | ||
// .where((element) => element.name.local == 'tileset') | ||
// .map((e) => e.getAttribute('source')); | ||
// | ||
// final tsxProviders = await Future.wait( | ||
// tsxSourcePaths | ||
// .where((key) => key != null) | ||
// .map((key) async => tsxProviderFunction(key!)), | ||
// ); | ||
// | ||
// return TileMapParser.parseTmx( | ||
// contents, | ||
// tsxList: tsxProviders.isEmpty ? null : tsxProviders, | ||
// ); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
@@ -286,7 +289,41 @@ class TiledMap { | |||
); | |||
} | |||
|
|||
factory TiledMap.parse(Parser parser, {List<TsxProvider>? tsxList}) { | |||
static TiledMap parseJson( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a factory just like parseTmx
, also needs some dartdocs
LFTM (looks fine to me!) |
Thanks for the review, I didn't have to time yet to write a proper comment: I have generalised into a generic Provider that can also be used for templates, therby also resolving #73, also as being extensible to more easily discover the location of images in I also moved the methods from TileMapParser into TiledMap since there were already parsing method there, and I always thought it was confusing to have this in a different class that does nothing otherwise. While moving it over I also made the names nicer and more descriptive. The I took the liberty of adding the Lists of However I split them into multiple Lists so one for tmx and one for templates. This however does not allow to integrate the same mechanism for images (e.g. of tilesets), because I don't think the actual loading of the images is supposed to be in this library and nothing is ever done with them I don't think that is a big deal. However I could also only pass one List and the |
Description
Currently a
TsxProvider
needs a getter for the filename it can provider. This PR seeks to introduce a new base classTsxProviderBase
which instead uses abool checkProvidable(String filename)
function to determine if aTsxProviderBase
is able to provide the source.To accomplish this it also has
Parser getSourceBase(String filename)
andParser? getCachedSourceBase(String filename)
methods to retrieve the source when needed.While do not like attaching Base to everything this naming scheme seems to be the easiest option to not break current implementations.
This new functionality is usefull for example to resolve all .tsx-files relative to a single directory.
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
While the internal functionig does change and new APIs are exposed I have recreated the old behaviour in
TsxProvider
as a sub class of the newTsxProviderBase
. Therefore classes extendingTsxProvider
should work as before with no breaking changes.However classes only implementing it will require additional methods, however if only implemented they should directly implement
TsxProviderBase
since (apart from the implementation of the old behaviour)TsxProvider
does not offer more functionality. It is simply a Wrapper to emulate the old behaviour and not break convention.Migration instructions
All classes only implementing
TsxProvider
should eitherTsxProvider
if the old API is needed (this allows you to not have to look at any new functionality) orTsxProviderBase
.Related Issues
Completes #70
Allows for usecase described in #69