-
-
Notifications
You must be signed in to change notification settings - Fork 899
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: Add network assets package. #2314
Merged
Merged
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
00c582a
feat: adding flame network image package
erickzanardo 6309175
feat: adding implementation
erickzanardo 153054e
adding example
erickzanardo 4d43652
removing widget test
erickzanardo 70b449d
improving tests
erickzanardo 1d4737c
test and docs
erickzanardo 84c8bf7
Merge branch 'main' into erick.flame-network-image
erickzanardo ce5a39d
some fixes
erickzanardo aacba5c
Merge branch 'main' into erick.flame-network-image
erickzanardo 9fabebb
feat: package repurpose to be able to load any kind of assets
erickzanardo e29a41d
fix md lint
erickzanardo 42b218d
fix md lint
erickzanardo 94e2194
fix dev dep
erickzanardo 8e6880c
updting LICENSE
erickzanardo fedce82
pr suggestions
erickzanardo 15b7775
removing example folder
erickzanardo 5feaa43
md fix
erickzanardo 5228961
Merge branch 'main' into erick.flame-network-image
erickzanardo 18323db
fix spell
erickzanardo 420dec7
Update packages/flame_network_assets/CHANGELOG.md
erickzanardo d114c20
pr suggestions
erickzanardo 97540df
Apply suggestions from code review
erickzanardo 7c69cd9
Update packages/flame_network_assets/README.md
erickzanardo c2d4cee
pr
erickzanardo aa2030f
Merge branch 'main' into erick.flame-network-image
erickzanardo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ yarnspinner | |
рушниці | ||
рушниць | ||
рушниця | ||
unawaited | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,45 @@ class MyGame extends Game { | |
} | ||
``` | ||
|
||
## Loading images from the network | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section should be further down in the document? Feels like Sprite for example is of higher priority? |
||
|
||
Flame core package doesn't offer a built in method to loading images from the network. | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The reason for that is that Flutter/Dart does not have a built in http client, which required | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
a package to be used and since there are a couple of packages available out there, we refrain | ||
from forcing, on even pushing the user in a specific package. | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
With that said, it is quite simple to load images from the network once a http client package | ||
is chosen by the user. The following snippet shows how an `Image` can be fetched from the web | ||
using the [http](https://pub.dev/packages/http) package. | ||
|
||
```dart | ||
import 'package:http/http.dart' as http; | ||
import 'package:flutter/painting.dart'; | ||
|
||
final response = await http.get('https://url.com/image.png'); | ||
final image = await decodeImageFromList(response.bytes); | ||
``` | ||
|
||
## FlameNetworkImages | ||
|
||
The snippet above can be enough for simple games, or simple features of some games, but | ||
more than often, developers will want to cache the images that were fetched from the web. | ||
|
||
To help in that regards, Flame provides a package that makes is easy to fetch images from the | ||
network, with automatic memory and file system cache. | ||
|
||
To use it, just add the `flame_network_image` package to your project and use the following | ||
code to fetch images: | ||
|
||
```dart | ||
final networkImages = FlameNetworkImages(); | ||
final charSprite = await networkImages.load('https://url.com/image.png'); | ||
``` | ||
|
||
By default, that package relies on the `http` package to make http requests, and `path_provider` | ||
to get the place to store the local cache, to use a different approach for those, check the | ||
optional arguments in `FlameNetworkImages` constructor in order to customize that. | ||
|
||
## Sprite | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
channel: stable | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# flame_network_image | ||
|
||
<!-- markdownlint-disable MD013 --> | ||
<p align="center"> | ||
<a href="https://flame-engine.org"> | ||
<img alt="flame" width="200px" src="https://user-images.githubusercontent.com/6718144/101553774-3bc7b000-39ad-11eb-8a6a-de2daa31bd64.png"> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
Adds network images support to <a href="https://github.com/flame-engine/flame">Flame</a>. | ||
</p> | ||
|
||
<p align="center"> | ||
<img src="https://github.com/flame-engine/flame_network_image/workflows/Lint/badge.svg?branch=master&event=push" alt="Test" /> | ||
<a title="Discord" href="https://discord.gg/pxrBmy4" ><img src="https://img.shields.io/discord/509714518008528896.svg" /></a> | ||
</p> | ||
<!-- markdownlint-enable MD013 --> | ||
|
||
--- | ||
|
||
This package makes it easy to use and cache images from the network inside a Flame game. | ||
|
||
For instructions on how to use this package, check Flame docs: | ||
|
||
https://docs.flame-engine.org/1.6.0/flame/rendering/images.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include: package:flame_lint/analysis_options.yaml | ||
|
||
linter: | ||
rules: | ||
- public_member_api_docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release | ||
|
||
android | ||
ios | ||
web | ||
linux | ||
macos | ||
windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled. | ||
|
||
version: | ||
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
channel: stable | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: android | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: ios | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: linux | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: macos | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: web | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
- platform: windows | ||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# example | ||
|
||
`flame_network_images` example app. |
29 changes: 29 additions & 0 deletions
29
packages/flame_network_image/example/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file configures the analyzer, which statically analyzes Dart code to | ||
# check for errors, warnings, and lints. | ||
# | ||
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled | ||
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be | ||
# invoked from the command line by running `flutter analyze`. | ||
|
||
# The following line activates a set of recommended lints for Flutter apps, | ||
# packages, and plugins designed to encourage good coding practices. | ||
include: package:flutter_lints/flutter.yaml | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
linter: | ||
# The lint rules applied to this project can be customized in the | ||
# section below to disable rules from the `package:flutter_lints/flutter.yaml` | ||
# included above or to enable additional rules. A list of all available lints | ||
# and their documentation is published at | ||
# https://dart-lang.github.io/linter/lints/index.html. | ||
# | ||
# Instead of disabling a lint rule for the entire project in the | ||
# section below, it can also be suppressed for a single line of code | ||
# or a specific dart file by using the `// ignore: name_of_lint` and | ||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file | ||
# producing the lint. | ||
rules: | ||
# avoid_print: false # Uncomment to disable the `avoid_print` rule | ||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flame/extensions.dart'; | ||
import 'package:flame/game.dart'; | ||
import 'package:flame/input.dart'; | ||
import 'package:flame_network_image/flame_network_image.dart'; | ||
import 'package:flutter/material.dart' hide Image; | ||
|
||
void main() { | ||
runApp(GameWidget.controlled(gameFactory: MyGame.new)); | ||
} | ||
|
||
class MyGame extends FlameGame with TapDetector { | ||
final networkImages = FlameNetworkImages(); | ||
late Image charSprite; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
charSprite = await networkImages.load( | ||
'https://examples.flame-engine.org/assets/assets/images/bomb_ptero.png', | ||
); | ||
} | ||
|
||
@override | ||
bool onTapUp(TapUpInfo info) { | ||
add( | ||
SpriteAnimationComponent.fromFrameData( | ||
charSprite, | ||
SpriteAnimationData.sequenced( | ||
textureSize: Vector2(48, 32), | ||
amount: 4, | ||
stepTime: .2, | ||
), | ||
size: Vector2(100, 50), | ||
anchor: Anchor.center, | ||
position: info.eventPosition.game, | ||
), | ||
); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: example | ||
description: A flame network images example. | ||
publish_to: 'none' | ||
|
||
version: 1.0.0+1 | ||
|
||
environment: | ||
sdk: '>=2.18.0 <3.0.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flame: ^1.6.0 | ||
flame_network_image: | ||
path: ../ | ||
cupertino_icons: ^1.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
library flame_network_image; | ||
|
||
export 'src/flame_network_image.dart'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess this should go in the
gamedev_dictionary.txt
?