238 Commits

Author SHA1 Message Date
d12e45444e docs: Remove references to Tappable and Draggable (#2912)
We still had some references to `Tappable` and `Draggable`, this PR
removes them and removes a superfluous test for `TapCallbacks`.

---------

Co-authored-by: jonathan <sharyari@gmail.com>
2023-12-09 16:09:45 +01:00
8c3cb72541 feat: Scrollable TextBoxComponent (#2901)
This PR introduces a new ScrollTextBoxComponent, enhancing the existing
text box functionalities with scrollable text capabilities. This
component, built on top of the existing TextBoxComponent, is designed to
handle scrollable text, thereby providing a better user interface for
games that require displaying longer text content.

Added docs and and an example.

---------

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
2023-12-08 19:53:45 +00:00
63994ebcd8 fix!: Add DisplacementEvent to fix delta coordinate transformations for drag events (#2871)
This adds `DisplacementEvent` to fix delta coordinate transformations
for drag events, to be used instead of `PositionEvent`.
Drag Events now expose the start and end position, as well as the delta,
correctly transformed by the camera and zoom.
This also ensures that drag events, once starts, do not get lost if the
drag update leaves the component bounds.



* if you are using `DragUpdateEvent` events, the `devicePosition`,
`canvasPosition`, `localPosition`, and `delta` are deprecated as they
are unclear.
* use `xStartPosition` to get the position at the start of the drag
event ("from")
* use `xEndPosition` to get the position at the end of the drag event
("to")
* if you want the delta, use `localDelta`. it now already considers the
camera zoom. no need to manually account for that
* now you keep receiving drag events for the same component even if the
mouse leaves the component (breaking)

---------

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2023-11-30 16:40:26 +01:00
0fd2662d4b refactor!: Replace Offset with opacityFrom and opacityTo in ColorEffect (#2876)
`ColorEffect`'s API was a bit confusing because it used `Offset` for
getting values of opacity start and end from user. This PR changes that
to use optional `opacityFrom` and `opacityTo` double parameters. It also
adds validate checks on these value to make sure that are between 0 and
1.
2023-11-27 14:21:18 +01:00
f42d0e73be docs: Fix naming of drag- and tap-callbacks examples (#2873)
Fix naming of drag- and tap-callbacks examples
2023-11-26 17:55:35 +00:00
37f7b12f57 fix: Use world on tap_callbacks_example (#2875)
Use world on tap_callbacks_example. We should just standardize all
examples to use the world unless there is a reason not to, in order to
avoid confusing users.
2023-11-26 17:32:59 +00:00
39edc70206 docs: Fix Hover Callbacks so the tap used in the example respects the zoom (#2874)
Fix Hover Callbacks so the tap used in the example respects the zoom.

The example happens to use a tap event to create new squares. However,
since the tap event is bound to the Game instead of the World, had it
had any zoom applied (which it didn't), or any other camera transform,
the squares would have been created on the wrong place. This sends a bad
example to new users and can cause confusion.
2023-11-26 18:26:00 +01:00
d51cd584c7 fix: Minor issues due Flutter 3.16 (#2856)
With the last Flutter version, a few issues were introduced in Flame sourcebase. This PR solves that.
2023-11-16 17:50:39 -03:00
03f4e56ffe chore: Bump Forge2D to 0.12.2 (#2836)
Bumps forge2d to 0.12.2

Migration instructions:
The gravity and bullet are now field setters and getters, so if you
before had `setGravity(Vector2(0, -10))` then you now do `gravity =
Vector2(0, -10);` and if you previously had `body.setBullet(true);` you
now do `body.isBullet = true;`.
2023-11-03 22:58:49 +01:00
5b67b8f14a fix: Remove deprecations for 1.10.0 (#2809)
Removed deprecations for 1.10.0 and fixes some small unreleased regressions found when going through the examples.
2023-10-11 15:57:25 +02:00
97fff0ed2b feat: Add advanced button component (#2742)
New button with support for multiple states:
<img width="278" alt="image"
src="https://github.com/flame-engine/flame/assets/18004353/041c1105-8991-4976-b1a2-0553c149ec4e">
2023-10-10 21:43:28 +02:00
4c762f94d4 feat: Introduce the FixedResolutionViewport (#2796)
This enables you to zoom when using the CameraComponent.withFixedResolution constructor, without disabling the fixed resolution after doing so, by introducing a new viewport the FixedResolutionViewport.
2023-10-10 00:20:05 +02:00
ab329f718a feat: Backdrop (static backgrounds) component for CameraComponent (#2787)
This PR adds a backdrop component to the `CameraComponent` which renders
behind the world.
With this change the rendering order looks like this:
```
backdrop
world
viewport
viewfinder
```

In the following example you can see a `ParallaxComponent` attached to
the backdrop, a player and some other components attached to the world,
and some texts attached to the viewfinder and viewport:

![image](https://github.com/flame-engine/flame/assets/744771/a0b2fe0e-bff3-4d1d-a2d1-ddd3199bbdab)
2023-10-03 17:26:36 +00:00
35290757f3 docs: Fix broken links to code in examples (#2789)
Fixing broken links to issue #2618
2023-10-03 11:55:27 +00:00
71f7b475e3 refactor: Mark semantically final variables as final (or const) proper [DCM] (#2783)
I was playing around with the rule avoid-global-state
While I don't think we should enable it, because we do have several totally legitimate cases of what the rule considers global state, it did help me find any current cases where the things just should be final constants.
So this PR will mark semantically final variables as final (or const) proper, exclusively on examples (no violations on actual src code are legit).
2023-10-02 09:45:42 +02:00
350cb07e82 chore: Fix some broken flame_forge2d links (#2764)
Some links were not converted when we renamed a directory from forge2d
to flame_forge2d.
2023-09-22 14:14:57 +00:00
152fbb61db docs: Fix examples for v1.9.0 (#2757)
Fixed up some examples that needed fixing before releasing v1.9.0
2023-09-21 19:24:40 +00:00
477221998a feat(flame): Add helper methods to create frame data on SpriteSheet (#2754)
Add two methods to SpriteSheet to create frame data for SpriteAnimation
2023-09-21 11:34:02 +02:00
7313cd5352 chore: Remove CSpell regex bypasses (part 3) (#2753)
Remove CSpell regex bypasses (part 3) and fix violations accordingly
2023-09-21 06:08:13 +02:00
9c1e1c3098 chore: Remove deprecations for v1.9.0 (#2749)
Removes everything that was marked as deprecated and that should be
removed for v1.9.0.
2023-09-19 16:47:41 +02:00
7c2f400076 feat!: Add CameraComponent to FlameGame (#2740)
This PR adds the `CameraComponent` and a `World` by default to the
FlameGame.
2023-09-18 21:06:37 +02:00
7a3d5126a5 feat!: Move Forge2DGame to use CameraComponent (#2728)
This enables flame_forge2d to work with the CameraComponent and the new event system.
2023-09-16 08:08:29 +00:00
d460b846c2 feat: Add HoverCallbacks (#2706)
This creates HoverCallbacks (and PointerMoveCallbacks) to replicate the Hoverables behaviour in the new camera and event system.
2023-09-10 14:49:52 -04:00
83f5ea45dc feat: SpawnComponent (#2709)
This PR introduces the `SpawnComponent`, which randomly spawns
components within a set area.
2023-09-10 17:55:30 +02:00
10fb65f66c feat: Add TextElementComponent (#2694)
Add TextElementComponent
2023-09-02 19:36:58 +00:00
4b420b7952 refactor!: Rename (Text) Elements, Nodes and Styles for clarity, add docs (#2700)
This occurred to me after a discussion on the [new FCS component
PR](https://github.com/flame-engine/flame/pull/2694#discussion_r1312450113).
As per usual, @spydon has opened my eyes to the ultimate truth:

We should rename loads of files, and it shall affect almost no one.

The idea is to (1) add a "Text" prefix to all text-rendering-related
classes and (2) rename the existing `Text*` to `InlineText*` (which is
what they are).

This PR is a bit big, but the changes should hopefully be simple to
review, and can be broken down into:

* Add a proper base class for the node inheritance chain, call it
TextNode (while working on Flame Markdown I realized the value this will
have to me)
* Rename the old TextNode to InlineTextNode
* Rename DocumentNode to DocumentRoot because it is not a node
* Rename Element to TextElement
* Rename the old TextElement to InlineTextElement
* Rename Style to FlameTextStyle (note: we could consider dropping the
Flame here)
* Rename the old FlameTextStyle to InlineTextStyle
* Update the docs accordingly
* Add some more diagrams and explanations to the docs, following the new
nomenclature
* I also updated our "internal" imports to use the text module to make
life so much easier (this could arguably be done in a separate PR, but I
honestly think it's easier to review together, please lmk if you prefer
me to split).

These are all breaking changes but likely won't actually affect most
users (see below).

While this is breaking, it should hopefully not affect most users,
because these are all infrastructure classes that most people aren't
using directly. If you are using the FCS components, or the renderers
`TextPaint` or `SpriteFontRenderer` directly, this should have zero
effect to you.

If you are using the Nodes, Stlyes or Elements directly, or have a
custom TextRenderer, see below.

Migrating should be a simple matter of renaming your type references:

* from TextNode to InlineTextNode
* from TextElement to InlineTextElement
* from Element to TextElement
* from FlameTextStyle to InlineTextStyle
* from Style to FlameTextStyle

Make sure to do it in the appropriate order not to cause any
double-replace issues.

If you are importing via the module `package:flame/text.dart`, which we
highly encourage, you should not have to change any import statements
whatsoever.
2023-09-02 12:59:59 -04:00
a1cb9a06ad refactor!: Kill TextRenderer, Long Live TextRenderer (#2683)
This will:

    kill the TextRenderer inheritance chain
    incorporate the functionality of the base TextRenderer in the base TextFormatter
    rename TextFormatter to TextRenderer and appropriate references

That is because both essentially do the same job; encompass the style (or "how") information about how to render text, but using two slightly different interfaces. While that could allow for more flexibility, it is a faux choice that needlessly complicates the pipeline. By having a single interface to comply with, we still allow for custom renders while at the same time making all the code downstream simpler to use and understand.
2023-08-27 21:47:01 +02:00
1a64443cca refactor!: Make TextElement more usable on its own (#2679)
This is part of my ongoing effort to simplify the text rendering
pipeline.
My ultimate goal is to:
* get rid of renders
* rename formatters to renderers
* make the interface complies to both
All details are specified here:
https://github.com/flame-engine/flame/pull/2663

As a first step to break down that huge PR, this makes a small change to
TextElements to make them more useful

This PR will:
### rename render -> draw

draw becomes the "internal", underlying impl, raw method, that just
draws the element w/ any custom options

### add a new render method that takes in more options

this does not need to be extended by every impl.
this is for end users and accepts parameters like position and anchor to
be more in line with the renderer interface

This is technically a breaking change but should have no effect for
users, unless you are creating your own custom `TextElement`s. In that
case, to migrate:

* rename your `render` method to `draw`
2023-08-26 12:10:03 -04:00
76405daf48 feat: Component visibility (HasVisibility mixin) (#2681)
This PR introduces a new HasVisibility mixin on Component. It prevents the renderTree method from progressing if the isVisible property is false. It therefore prevents the component and all it's children from rendering.

The purpose of this mixin is to allow showing and hiding a component without removing it from the tree.

An important note is that the component (and all it's children) will still be on the tree. They will continue to receive update events, and all other lifecycle events. If the user has implemented input such as tap events, or collision detection, or any other interactivity, this will continue to operate without affect (unless it relies on the render step - such as per-pixel collision detection).

This is expected behaviour. If it is not desired, the user needs to account for it (by checking isVisible in their code) or someone needs to create another mixin for HasEnabled or HasActive which would prevent these other actions 😁

I am very happy to make changes, take suggestions, etc!
2023-08-26 14:26:22 +02:00
10e4109c81 refactor: Fix lint issues across the codebase - Part 2 (#2677)
Fix a handful of lint issues across the codebase, identified using DCM.
Nothing controversial, I expect; slowly getting these out of the way so
we can focus on discussing bigger things.
2023-08-25 18:15:17 +00:00
9887892493 chore: Update to Flutter 3.13 (#2656)
Updates the pipeline to use Flutter 3.13 and does all the analyze fixes.
2023-08-18 20:13:17 +02:00
e852064e49 fix: Viewport should recieve events before the world (#2630)
The viewport should receive events before the world, otherwise all huds will get the events after the world components, if there are any world components underneath them.
2023-08-07 11:57:21 +00:00
ff3d91075c feat: Adding filterQuality arguments to Parallax load methods (#2596)
The Parallax already supported filter quality, but the loader methods were missing parameters for it to be passed to the loaded instances, making it impossible (unless manually loading) to set a filter quality in a parallax.

By setting a filter quality to none (which on flutter means that the next neighbour algorithm will be user) on pixel art sprites we can keep the crisp look that that style of art demands.
2023-06-30 06:03:00 +02:00
b3efb612cb feat: ComponentKey API (#2566)
Adds a new key api on FCS, which will allow users to get a component from the tree, without needing to iterate over all the children or a parent descendants.
2023-06-20 09:36:15 -03:00
2d45d2be39 chore: Remove 1.8.0 deprecations (#2538)
Removes all the deprecated methods before 1.8.0 release.
2023-05-22 19:01:55 +02:00
b41622db8f fix: Solve warnings from 3.10.0 analyzer (#2532)
Just solves the warnings that the new Flutter version complains about (which makes us lose 10 points on pub).
2023-05-14 16:25:23 +02:00
5d1a6fd167 feat: Spine bridge package (#2530)
This PR introduces a bridge package for Spine.

https://user-images.githubusercontent.com/744771/236058480-75c8212b-98e6-4e3b-834a-c1a9d4de31a8.mp4
2023-05-05 23:17:15 +02:00
472356df31 docs: WeldJoint docs and example (#2525)
WeldJoint docs and example
2023-05-01 20:22:28 +02:00
0991c3bf67 docs: RopeJoint documentation and example (#2520)
RopeJoint documentation and example
2023-04-25 10:37:31 +02:00
1ed2c5a297 feat: Add stepEngine to Game (#2516)
This PR adds a new method to Game which allows advancing the game loop by a certain amount of time while the engine is paused. By default it assumes one frame to be ~16 ms, but it can be controlled while calling stepEngine

The idea is to allow easy frame by frame inspection of the game. It can even be added to FlameStudio as part of the start/pause buttons on the toolbar.

https://user-images.githubusercontent.com/33748002/233453501-b9f90d49-1834-4f0f-9536-77629cfcadbc.mp4
2023-04-23 21:28:37 +02:00
a25b0a03a5 feat: Customise grid of NineTileBox (#2495)
The previous implementation of the NineTileBox calculates identically sized tiles in a 3x3 grid and does not allow the user to customise this. For example, a 60x60 pixel sprite will be cut into 20x20 pixel tiles. This MR allows the user to specify the sizes of the fixed-width and fixed-height rows and columns so that a completely custom grid is possible.

Example with the following sprite and custom grid sizes.
Note that the stretchable row and column are only 1 pixel wide/high in this example.
2023-04-19 08:04:09 +00:00
87b8a067f3 refactor!: Move CameraComponent and events out of experimental (#2505)
This moves the CameraComponent and the new event system out of experimental since this now is the recommended way of handling things.
2023-04-19 09:55:32 +02:00
89926227c5 feat: Accept CollisionType in hitbox constructor (#2509)
With this PR we accept the `CollisionType` directly in the constructor.
2023-04-18 13:57:16 +00:00
dbda37b81a refactor: Add new lint rules (#2477)
This PR adds the following lint rules to our list:

```
always_put_required_named_parameters_first
avoid_multiple_declarations_per_line
avoid_positional_boolean_parameters
avoid_returning_null_for_void
avoid_returning_this
avoid_unnecessary_containers
enable_null_safety
library_private_types_in_public_api
no_leading_underscores_for_library_prefixes
no_leading_underscores_for_local_identifiers
prefer_null_aware_method_calls
tighten_type_of_initializing_formals
unnecessary_late
use_setters_to_change_properties
```

And these rules were considered, and some changes were made according to
them as a clean-up, but in many places they didn't make sense
(`prefer_asserts_with_message` I would have included, but there were too
many places that needed to be changes):

```
collection_methods_unrelated_type
prefer_asserts_with_message
avoid_renaming_method_parameters
```
2023-04-13 19:42:00 +00:00
78b585fe8e docs: Added GearJoint docs and example (#2487)
GearJoint docs and example
2023-04-13 21:09:26 +02:00
47372087f2 feat!: Update AudioPlayers to ^4.0.0 (#2482)
This updates flame_audio to use the recently released audioplayers 4.0.0

Migration instructions:

AudioPool has moved to AudioPlayers, but we still export it from
flame_audio, so the only thing you have to do if you import AudioPool
directly is to change the import to:
import 'package:flame_audio/flame_audio.dart';
2023-04-11 21:51:43 +02:00
bd3e788612 feat: Deprecate Component.changeParent (#2478)
Since we now have a setter directly for parent, changeParent is no longer needed.
2023-04-11 16:55:27 +02:00
e4f741ef23 docs: PrismaticJoint docs and example (#2470)
PrismaticJoint example and documentation
2023-04-07 12:17:05 +00:00
de630a1c3a feat: Add isDragged in DragCallbacks mixin (#2472)
Adding a isDragged state for DragCallbacks mixin. This was available in the Draggable mixin.
2023-04-07 13:39:28 +02:00
b5bdf4ec17 feat!: The HasTappableComponents mixin is no longer needed (#2450)
This PR is the second in a series of refactors that aim to simplify event handling in Flame. The approach is as follows:

    Added the MultiTapDispatcher component, which contains the logic that used to be within the HasTappableComponents mixin. This component is internal; it mounts to a FlameGame directly, and ensures that it is a singleton.
    Whenever any TapCallbacks component is added to a game, it automatically adds the MultiTapDispatcher component (unless there is already one), which in turn registers a tap gesture detector with GestureDetectorBuilder and rebuilds the game widget.

The end result is that now in order to make a component tappable you only need to add the TapCallbacks mixin to that component, everything else will be handled by the framework.

Consequently, the HasTappableComponents mixin is now empty and marked as deprecated.
2023-04-02 16:52:57 +00:00