46 Commits

Author SHA1 Message Date
978ad31b42 refactor: Fix lint issues from latest flutter release (#3390)
Updates to use the new color method `withValues`.

---------

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
2024-12-13 22:40:54 +01:00
06f5a4b4a8 chore: Update cicd.yml file on flame_3d to match main, rollback color changes (#3378)
Update cicd.yml file on flame_3d to match main.

Since we finally updated main, we should require no difference
whatsoever on this file anymore.

This will require downgrading all the color changes, which is fine. This
should never have been a part of flame_3d to begin with.

Files were "untouched" by checking out the exact version as they are in
main right now (will need to rebase flame_3d to main later). I had to
add a couple more files because the files on main had dependencies on
changes that are not yet rebased on flame_3d. These extra diffs should
disappear when I do the final rebase.
2024-12-11 14:26:29 -05:00
27e4dcb65a chore: Update usages of Dart UI Color to not use deprecated fields and methods [flame_3d] (#3297)
Update usages of Dart UI Color to not use deprecated fields and methods.
On latest main of Flutter these will cause lint errors, [as can be seen
here](https://github.com/flame-engine/flame/actions/runs/10814047130/job/29999530293?pr=3282).

Note: I will update the `flame_3d`-specific violations on a followup.
2024-12-11 14:26:29 -05:00
fabbf928d0 chore: Enable DCM rule double-literal-format (#3248)
Enable DCM rule double-literal-format.

More details
[here](https://dcm.dev/docs/rules/common/double-literal-format/). This
both forbids trailing zeroes and mandates leading zeroes.

If we would prefer a different style (e.g. prefer no leading zero
instead), just lmk :)
2024-07-30 11:17:27 -04:00
67e069c00d feat: Support inline code blocks on markdown rich text (#3186)
Support inline code blocks on markdown rich text.
2024-06-06 08:57:55 -04:00
194d553656 feat: Support text align on new text rendering pipeline (#3147)
Support text align on new text rendering pipeline.

![image](https://github.com/flame-engine/flame/assets/882703/62f91c8e-f38f-48b0-8c59-06efb10acdf3)

![image](https://github.com/flame-engine/flame/assets/882703/b00afb90-6051-4a2c-aac6-ac36ea1bcba2)
2024-05-06 08:13:10 -04:00
9a7bdc7439 fix!: Update IsometricTileMapComponent to have better defined position and size (#3142)
Update IsometricTileMapComponent to have better defined position and
size.

Before, the isometric component "zero" would be the center of the 0,0
block.
However, that does not play nicely with our component system if you want
to know the size (i.e. bounding box) of a component.

This changes so that the 0,0 of the component is the 0,0 of the AABB
around the isometric tiles. Then, it also computes the size of the
component accordingly.

This also changes the example to allow toggling between half and full
size more easily.

In our example, this is what it looks like:


![image](https://github.com/flame-engine/flame/assets/882703/6e3d6bb5-ff66-4923-9c66-2f0794fd3eab)

The example still shows how to compute the previous origin (the purple
dot) if you want to.

With full size blocks:


![image](https://github.com/flame-engine/flame/assets/882703/485dbffc-51a8-46f5-a125-6f12cce5b35e)


This is a minor breaking change as you might need to "reposition" your
tile components, essentially remove the "compensation" for its location
that you probably did yourself. If you were centering the tile component
based on the available methods such as `map.getBlockCenterPosition`,
then just make sure you are adding the `map.position` to that and it
should work as before.
2024-04-29 11:24:05 -04:00
b946ba70cb feat: Add copyWith method on the TextBoxConfig (#3099)
Simplifies the creation of the `TextBoxConfig` in the
`ScrollTextBoxComponent` by adding a `copyWith` method to it and making
it `const`.
2024-03-26 22:21:26 +00: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
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
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
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
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
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
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
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
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
51a896b2c8 feat: clampLength for Vector2 extension (#2190)
With this method you can clamp the length of a vector, instead fitting it in a box like clamp and clampScalar does.
2022-11-25 14:36:18 +00:00
cbfa789e75 chore: Fix some spelling mistakes (#2148)
Fix all* typos reported by CSpell, and add some more words into the dictionaries.

(Except for two in the flame_isolate/example package).
2022-11-06 14:06:44 +00:00
4bf9563013 chore: Fix some spelling errors (#2146) 2022-11-05 12:17:48 +01:00
6fe517a0c2 ci: Added Spell checker in CI (#2006)
Added spell check in Github CI
2022-10-22 16:51:00 +02:00
b5780d4212 feat: Add support for styles propagating through the text node tree (#1915)
This PR continues the work for enabling rich text support within Flame.
Here I add support for different text fragments having different TextStyles, and allow those styles to be inheritable within the text node tree.
2022-10-08 11:08:18 +00:00
bfdc3a291b feat: Structured text and text styles (#1830)
This PR introduces the notions of structured text, and text styles, to support rendering of rich text bodies.

Specifically, we recognize that sometimes in games one needs to render pieces of text that are larger than a single word or even a single paragraph. These pieces may include: books, quest descriptions, mission objectives, tutorials, in-game help system, dialogues, etc. Rendering such a piece of text is non-trivial, however. In order to tackle this problem, I break into the following parts:

Text structure, represented as a tree of Nodes. The nodes describe the logical structure of the text, for example the document may contain a header, and then several paragraphs, and a list, where the list contains some list items, some of which having possibly several paragraphs, etc. This structure is similar to how in HTML the text is marked up with HTML tags.

Text styles are struct-like classes that contain properties describing how the text is to be styled: font size, font renderer, borders, backgrounds, margins, padding, etc. This representation is also tree-like, so that for example text inside paragraphs can have different style than text within headers, and paragraphs within lists can have different margins. A text style is similar to a stylesheet in HTML.

Text elements are the result of applying the document style to a document node: they are the "prepared" and laid out pieces, ready to be rendered. Elements are a bit like mini-components, or perhaps text "particles" in a particle system.
2022-08-10 08:13:27 +00:00
2a41d0d683 feat: Move to Flutter 3.0.0 and Dart 2.17.0 (#1713)
This upgrades all packages to Flutter 3.0.0 and fixes all analyze issues that came from that.
2022-06-08 06:04:40 +00:00
c64aedaeb3 feat: Aligned text in the TextBoxComponent (#1620)
- Added option align in the TextBoxComponent which controls the alignment of text.
 - Added option for the TextBoxComponent to have a fixed size (before the only mode was for the textbox to automatically expand/shrink to fit the text).
2022-06-03 23:21:40 +02:00
843ddc3624 refactor: Move to package imports (#1625)
* refactor: Move to package imports

* Fix local imports

* Removed unused imports
2022-05-15 15:04:35 +00:00
4c68c2b0a2 feat: Add FpsComponent and FpsTextComponent (#1595) 2022-05-11 19:49:14 +02:00
6891eaaa24 feat: adding ParticleSystemComponent (#1489) 2022-03-26 12:20:31 -03:00
05f7a4c3d6 refactor: Remove Loadable, optional onLoads (#1333) 2022-01-24 23:23:12 +01:00
d77e5efee5 refactor: Use canvas.drawImageNine in NineTileBox (#1314)
`canvas.drawImageNine` is built-in now a lot of logic was removed from NineTileBox.
2022-01-17 00:22:51 +01:00
5c47d7f6d7 chore: analyze issues introduced from new dart version (#1196)
* Added Component.childrenFactory

* fix some of the lint warnings

* more lint warnings

* remove changelog entry

* more analyzer warnings

* one more warning

* one more warning

* remove more unused imports

* fix more warnings

* another warning

* one more warning

* a lot more warnings

* some more warnings

* fix warnings in flame_svg

* fix warnings in flame_bloc

* Remove OrderedSet override feature

* Remove testRandom change

* Remove unnecessary type checks

* Re-remove deprecated argument in random_test

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2021-12-09 15:40:43 +01:00
dec04f3335 Work around Flutter bug for ColorEffect and fix broken links (#1178)
* Fix `ColorEffect` Flutter bug and example links

* Remove accidental code

* Fix `ColorEffect` test
2021-12-08 13:19:00 +01:00
fe162c6d90 Introduce updateTree (#1158)
* Introduce updateTree

* Update tests

* Fix update for game-in-game situations

* Add dartdoc to updateTree
2021-12-03 14:01:46 +01:00
8b132d7c0b Unify examples structure (#1118)
* Animations, CameraAndViewport, CollisionDetection and Components unified

* Added descriptions to effects

* Rename input games

* Unify input stories

* Add info to parallax section

* Added descriptions to the rendering examples

* Add descriptions to the sprites directory

* Fix utils and rendering section

* Add descriptions to the widgets section

* Delete directory that rebase brought back

* Unify game names

* Added some styleguide docs for examples

* Fix analyze issues

* All files should have _example as suffix

* Made the FollowComponentExample a bit easier to understand

* Change priority of ember
2021-11-19 14:28:04 +01:00
12fd07e5ae Possibility to initialize all PositionComponents from onLoad (#1113)
* Fix ParallaxComponent constructor

* Fix sizing bug parallax_component

* Unify TextComponent and TextBoxComponent

* Fix tests

* Update PositionComponent docs

* Add changelog entry

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Fix analyze issue

* Apply suggestions from code review

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Fix line length in components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Luan Nico <luanpotter27@gmail.com>
2021-11-18 11:42:12 +01:00
3cb23ef530 TextPaint to use TextStyle instead of TextPaintConfig (#1086)
* `TextPaint` to use `TextStyle` instead of `TextPaintConfig`

* Update packages/flame/lib/src/text.dart

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Removed BaseTextConfig and TextPaintConfig

* Update text docs

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Remove generics

* Update TextBoxExample

* Update text examples variable names

* Fix TextPaint in collision_detection example

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
2021-11-13 16:38:06 +01:00
a1b6ffa04a Game as a Component (#906)
* Game as a component

* Fix component stories

* Effects are now components

* Update effects docs

* Handle swap of parent

* Fix reAddChildren

* Wait for children to be added

* BaseComponent and PositionComponent to be non-abstract

* Simplify HasGameRef

* Revert so that onLoad can be null

* Fix example description

* Effects as components

* Remove gameRef from addChildren

* Fix hasGameRef

* Start migrating effects

* Updated comments of effect fields

* Fix comments

* Continue to fix sequence and combined effects

* Upgrade ordered_set

* Fix position_component_test

* BaseComponent -> Component

* Fix combined and sequence effects

* Await components to be added in tests

* Remove unnecessary game.update in tests

* Fix some tests related to composition

* BaseGame should be used in examples

* Fix CombinedEffect test

* Keyboard code to be based on Component

* Fix keyboard tests

* Fix analyze problems

* Fix sequence_effect

* Fix combined_effect_test

* Store peak state instead of end state

* Fix sequence_effect tests

* Update tutorial

* Fix tutorial 1

* Remove SimplePositionComponentEffect

* Remove unused test variable

* Update docs

* Removed onMount

* Remove onMount

* Add missing dartdoc

* Fix dart docs

* Add super.update where needed

* Move reAddChildren to component

* Reorganize method order in game widget

* preOffset -> initialDelay, postOffset -> peakDelay

* Introduce component.onParentChange

* Remove tests in wrong file

* Fix composed component test

* Add game lifecycle test

* Use BaseGame for mouse cursor test

* Oxygen should (?) not call super.update

* Use BaseGame in keyboard_test

* Fix onLoad to be properly cached

* Re-add unintentionally removed override

* Fix info for collision detection tests

* Add test for correct lifecycle on parent change

* Fix particles example

* Add component lifecycle diagram to the docs

* Add docs for the game lifecycle

* onRemove should be called when a game is removed from the widget

* Fix analyze errors

* prepare should be called from the component itself, not its parent

* Fix dartdoc

* onParentChange -> onMount

* onMount should have void as return type

* Simplify the loaderFuture in GameWidget

* Fix mock_canvas

* Fix rebase problem

* Remove asComponent

* Less complex _loaderFuture

* Add super.update to no_fcs parallax example

* Fix async tests

* Revert _loaderFuture

* Fix analyze issues

* await gameWithCollidables

* Keep epsilon small where it can be

* tappable methods should return bool

* Game lifecycle is now the same as for Component

* Remove mustCallSuper from component.update

* Make onLoadCache protected

* @internal on onLoadCache

* Cache/Memoize debugPaint and debugTextPaint

* Fix imports

* Fix comments

* Always call super.onLoad so that mixins can override it

* Add forgotten super.onLoad

* Bump coverage percentage

* HasCollidables should override update

* Fix Game comments

* Fix some dartdoc

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Game + Loadable as mixins

* Update packages/flame/lib/src/game/game_widget/game_widget.dart

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Update loadable docs

* Fix comments

* Move fps_counter

* Fix keyboard example

* Fix dartdoc

* Remove tutorials temporarily

* Fix game lowlevel graph

* Fix resize issue

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Luan Nico <luanpotter27@gmail.com>
2021-09-15 00:17:49 +02:00
9ec00d4ad7 Use Transform2D in PositionComponent (#904) 2021-08-21 19:32:32 -03:00
af014ac798 Fix the resolution of TextBoxComponent (#878)
* Fix the resolution of TextBoxComponent

* scale canvas

* Scale down

* Scale down on rendering

* Don't affect the debug rendering
2021-07-27 19:56:51 +02:00
d9e0acd3ff Abstracting text API to enable custom renderers (#772)
* Abstracting text API to enable custom renderers

* Addressing comments

* Lint

* Update doc/text.md

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>

* Adding dartdoc about TextRenderer

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2021-04-29 09:24:17 -03:00
23a72f5f39 Follow a Vector2 in Camera and add onPositionUpdate (#716)
* No setter for position and size

* Use setter for position and size

* Add onPositionUpdate and snapTo to Camera

* Fix formatting

* Fix size in test

* Update packages/flame/CHANGELOG.md

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>

* Update packages/flame/CHANGELOG.md

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>

* Better naming for internal position state

* Anchor and angle defaults on effect test utils

* No setter for position and size

* Fix scale effect

* Fix formatting

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
2021-03-31 20:48:44 +02:00
640bfea941 Migrate examples to null-safety (#707) 2021-03-24 19:04:33 -04:00
769bb711c3 Migrate examples back, change to monorepo (#701) 2021-03-12 09:24:50 -05:00