Previously the `mounted`, `loaded` and `removed` completers for
`FlameGame` weren't called since `FlameGame` doesn't go through the
normal component lifecycle flow, this PR adds so that the completers are
completed properly.
Closes#3003
This PR transfers the
[flame_texturepacker](https://github.com/Brixto/flame_texturepacker) to
the monorepo and updates it to be compatible with the rest of the
structure (linting etc).
When camera is following a component and trying to follow another target
I got an exception:
```
dart:core Iterable.forEach
package:flame/src/camera/camera_component.dart 326:25 CameraComponent.stop
package:flame/src/camera/camera_component.dart 309:5 CameraComponent.follow
test/camera/camera_component_test.dart 69:14 main.<fn>.<fn>
package:flame_test/src/test_flame_game.dart 80:21 testWithGame.<fn>
Concurrent modification during iteration: _Set len:0.
```
Copying viewfinder children before iterating through it and removing
child from parent does the trick, as we are not iterating through the
same list as we are removing items from, but rather a copy of it.
I tried to use camera from `game` provided in the test but it is AFAIK
not mounted and will hence not queue modifications (adds and removes).
Hence I create a new camera and mount it.
Updated package dependencies for flame_isolate.
Added support for TailoredIsolate and computeStream (called
isolateComputeStream in flame_isolate).
Updated the example package with new sprites created by yours truly, and
updated the license for the package, now that there is no assets with
copy-left CC license remaining.
### Migration instructions
Computation function is renamed from `isolate` to `isolateCompute`.
There are future breaking changes that are, as of now, mitigated with a
`@Deprecated` annotation with information regarding what function to use
instead.
Since the user might want to use the `ComponentKey` after it has been
assigned it should be made public.
It also updates `Consumer.key` to `Consumer.widgetKey` in flame_riverpod
to avoid a name clash. (Slightly breaking)
### Migration instructions
If you are using `consumer.key` from flame_riverpod you have to now use
`consumer.widgetKey` instead.
## Related Issues
Closes#2985
Previously, the `PolygonComponent.containsPoint()` and
`.containsLocalPoint()` functions consisted of duplicate code that
checked whether a given point lies within a convex polygon. They didn't
function properly with concave polygons.
I created a new `_containsPoint()` function that is called from both
functions to reduce redundancies. This new function uses a different
approach to figure out whether a point lies within a polygon, which
should also work for concave polygons, or even polygons with holes. The
algorithm is vaguely explained within code comments, and is visualized
in this post: https://stackoverflow.com/a/218081/5008997
---------
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.2 to 3.1.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/pallets/jinja/releases">jinja2's
releases</a>.</em></p>
<blockquote>
<h2>3.1.3</h2>
<p>This is a fix release for the 3.1.x feature branch.</p>
<ul>
<li>Fix for <a
href="https://github.com/pallets/jinja/security/advisories/GHSA-h5c8-rqwp-cp95">GHSA-h5c8-rqwp-cp95</a>.
You are affected if you are using <code>xmlattr</code> and passing user
input as attribute keys.</li>
<li>Changes: <a
href="https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-3">https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-3</a></li>
<li>Milestone: <a
href="https://github.com/pallets/jinja/milestone/15?closed=1">https://github.com/pallets/jinja/milestone/15?closed=1</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/pallets/jinja/blob/main/CHANGES.rst">jinja2's
changelog</a>.</em></p>
<blockquote>
<h2>Version 3.1.3</h2>
<p>Released 2024-01-10</p>
<ul>
<li>Fix compiler error when checking if required blocks in parent
templates are
empty. :pr:<code>1858</code></li>
<li><code>xmlattr</code> filter does not allow keys with spaces.
GHSA-h5c8-rqwp-cp95</li>
<li>Make error messages stemming from invalid nesting of <code>{% trans
%}</code> blocks
more helpful. :pr:<code>1918</code></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="d9de4bb215"><code>d9de4bb</code></a>
release version 3.1.3</li>
<li><a
href="50124e1656"><code>50124e1</code></a>
skip test pypi</li>
<li><a
href="9ea7222ef3"><code>9ea7222</code></a>
use trusted publishing</li>
<li><a
href="da703f7aae"><code>da703f7</code></a>
use trusted publishing</li>
<li><a
href="bce1746925"><code>bce1746</code></a>
use trusted publishing</li>
<li><a
href="7277d8068b"><code>7277d80</code></a>
update pre-commit hooks</li>
<li><a
href="5c8a105224"><code>5c8a105</code></a>
Make nested-trans-block exceptions nicer (<a
href="https://redirect.github.com/pallets/jinja/issues/1918">#1918</a>)</li>
<li><a
href="19a55db3b4"><code>19a55db</code></a>
Make nested-trans-block exceptions nicer</li>
<li><a
href="716795349a"><code>7167953</code></a>
Merge pull request from GHSA-h5c8-rqwp-cp95</li>
<li><a
href="7dd3680e6e"><code>7dd3680</code></a>
xmlattr filter disallows keys with spaces</li>
<li>Additional commits viewable in <a
href="https://github.com/pallets/jinja/compare/3.1.2...3.1.3">compare
view</a></li>
</ul>
</details>
<br />
[](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/flame-engine/flame/network/alerts).
</details>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR adds a template parameter to the `RiverpodGameMixin` as it is
done with all other mixins on `FlameGame` throughout the codebase. This
allows to use this mixin on `FlameGame`s that use a different `World`
(for example `Forge2DGame` with `Forge2DWorld`).
I have not created an issue as the solution is straigtforward and this
PR implements the solution.
This PR improves the documentation for the component lifecycle, in
particular for the `onLoad` method being executed before `onGameResize`
and `onMount`.
Closes#2969
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
Adds a new argument callback to all `raycast*` methods that lets the
user ignore hitboxes dynamically. The callback is called with every
prospective hitbox, and the hitbox is only considered when the callback
returns `true`.
This is faster, in the general case, than the current `ignoreHitboxes`
aproach. And it lets the developer have dynamic rules about what the
rays collide with. (For example, a line-of-fire raycast should take
friendlies into account, but could easily ignore other enemies that get
in the way.)
Closes#2966
This PR changes the return type of RiverpodComponentMixin.onLoad to
match that of Component.onLoad.
This resolves#2961 which describes an error preventing use of
RiverpodComponentMixin on Component subclasses that return a Future in
their implementation of onLoad due to a signature mismatch.
Closes#2961.
---------
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
To easily be able to spot whether a it is a hitbox that is being drawn
in `debugMode = true` it is now yellow instead of purple like the other
debug boxes.
Previously the point sent in to `containsLocalPoint` for
`GestureHitboxes` didn't take the parent transformation into
consideration, this is fixed in this PR.
With these new notifiers you can get notified when the current animation
or sprite changes in the group components.
The value notifier is not initialized unless the user tries to use it,
so it doesn't carry any extra weight on the components.
Remove the Projector interface that is no longer used for coordinate
transformations.
While this is exposed to end-users there is not much point in doing so
as it was always an internal detail of our implementation.
Since our last batch of removals of the old event system, this was left
orphaned.
I don't think deprecation is necessary as it is very unlikely that
anyone is using this interface (and if they are, they can easily declare
their own as we do not care about it anywhere).
This interface is no longer necessary to interop with Flame in any way
shape or form.
If you wish to use it internally in your game you can just declare it
yourself.
In #2943 a persistent frame callback was added to
RiverpodAwareGameWidget's state class, in order to handle multiple
requests in rapid succession to rebuild the widget safely, in response
to [this
thread](https://discord.com/channels/509714518008528896/516639688581316629/1186421112217813062)
on the Discord.
<details>
<summary>Walkthrough of issue with previous block</summary>
**Stage 1:**
forceBuild has been called for the first time, `_isForceBuilding` set to
true
**Stage 2:**
forceBuild has been called a second time before the setState has
completed. `_hasQueuedBuild` is set to true.
**Stage 3:**
The persistent callback is hit. As `_hasQueuedBuild` is true,
`_isForceBuilding` is set to true again, `_hasQueuedBuild` is set to
false / consumed, forceBuild is called again.
**Stage 4:**
Inside forceBuild, `_isForceBuilding` is still true as it was set inside
the persistent frame callback. Repeat Stage 2
</details>
N/A
`SpawnComponent` didn't had the ability to not auto start. This PR adds
a new attribute in order to customize that.
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
The `visibleGameSize` should be based on the virtual size of the
viewport, otherwise it won't work for `FixedResolutionViewport` for
example.
We noticed this when using the `ScreenHitbox` in a world that was looked
upon by a camera with a `FixedResolutionViewport`.
This PR improves the Space Shooter Tutorial as a whole by moving the
setting of component's attributes from their `onLoad` method, to their
constructors.
The forceRebuild function now has an "isDirty" check to determine
whether setState should be called. Previously, setState was uncritically
invoked which *could* produce the Flutter framework error that occurs
when setState is called while widgets are still being rebuilt.
The setState call inside ref.watch has been replaced with a call to
forceRebuild, and forceRebuild now has checks to prevent setState from
being called while a build is in progress. A persistent frame callback
has been added to reset supporting flags.
N/A. Customer reported issue[ via
Discord.](https://discord.com/channels/509714518008528896/1186421112217813062/1186908306179100723)
Added missing fields from the GameWidget default constructor to the
RiverpodAwareGameWidget constructor.
This PR was already discussed on the Discord server with spydon.
This PR is not a breaking change.
Fixes a logic error which prevented values in `MemoryCache` from being
updated when calling `setValue` with a preexisting `key`.
Replace or remove this text.
This adds the `selfPositioning` argument to the `SpawnComponent` so that
you can set the position of your components within the `factory` without
it getting overwritten be a random position for the `area`.
Closes#2923
This PR adds `margin` and `spacing` properties to the `SpriteSheet`
APIs. This will allow loading images that have margin and spacing in the
tiles.
---------
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
When performing a pointer hit test using PolygonHitbox, there may be a
discrepancy between the expected range and the range in which the hit
test succeeds. If the polygon shape has an offset at the top left, the
hit test will behave as if there is no offset.
Investigation revealed that the cause was in the calculation of
containsLocalPoint() in the PolygonComponent. The unnecessary offset
calculation was removed, and the hit test is now performed in the
expected range.
Closes#2758
---------
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>