Skip to content

Commit

Permalink
Merge pull request flame-engine#411 from flame-engine/develop
Browse files Browse the repository at this point in the history
0.24.0 RC
  • Loading branch information
erickzanardo authored Jul 2, 2020
2 parents 56dd898 + f9602b0 commit fb478f4
Show file tree
Hide file tree
Showing 25 changed files with 115 additions and 281 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 0.24.0
- Outsourcing SVG support to an external package
- Adding MemoryCache class
- Fixing games crashes on Web
- Update tiled dependency to 0.6.0 (objects' properties are now double)

## 0.23.0
- Add Joystick Component
- Adding BaseGame#markToRemove
Expand Down
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Put the pub package as your dependency by dropping the following in your `pubspe

```yaml
dependencies:
flame: ^0.23.0
flame: ^0.24.0
```
And start using it!
Expand Down
11 changes: 0 additions & 11 deletions doc/examples/debug/assets/android.svg

This file was deleted.

Binary file added doc/examples/debug/assets/images/android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions doc/examples/debug/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flame/game.dart';
import 'package:flame/flame.dart';
import 'package:flame/svg.dart';
import 'package:flame/position.dart';
import 'package:flame/components/component.dart' show SvgComponent;
import 'package:flame/components/component.dart';
import 'package:flame/components/mixins/resizable.dart';
import 'package:flame/text_config.dart';

Expand All @@ -16,12 +15,12 @@ void main() async {
myGame.start();
}

class AndroidComponent extends SvgComponent with Resizable {
class AndroidComponent extends SpriteComponent with Resizable {
static const int SPEED = 150;
int xDirection = 1;
int yDirection = 1;

AndroidComponent() : super.fromSvg(100, 100, Svg('android.svg'));
AndroidComponent() : super.square(100, 'android.png');

@override
void update(double dt) {
Expand Down Expand Up @@ -49,7 +48,7 @@ class AndroidComponent extends SvgComponent with Resizable {
}

class MyGame extends BaseGame {
final fpsTextConfig = const TextConfig(color: const Color(0xFFFFFFFF));
final fpsTextConfig = TextConfig(color: const Color(0xFFFFFFFF));

@override
bool debugMode() => true;
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/debug/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ dev_dependencies:

flutter:
assets:
- assets/android.svg
- assets/images/android.png
3 changes: 1 addition & 2 deletions doc/examples/flare/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void main() {
}

class MyGame extends BaseGame with TapDetector {
final TextConfig fpsTextConfig =
const TextConfig(color: const Color(0xFFFFFFFF));
final TextConfig fpsTextConfig = TextConfig(color: const Color(0xFFFFFFFF));

final paint = Paint()..color = const Color(0xFFE5E5E5E5);
final List<String> _animations = ["Stand", "Wave", "Jump", "Dance"];
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/particles/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyGame extends BaseGame {
final Random rnd = Random();
final StepTween steppedTween = StepTween(begin: 0, end: 5);
final trafficLight = TrafficLightComponent();
final TextConfig fpsTextConfig = const TextConfig(
final TextConfig fpsTextConfig = TextConfig(
color: const Color(0xFFFFFFFF),
);

Expand Down
70 changes: 0 additions & 70 deletions doc/examples/svg/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions doc/examples/svg/.metadata

This file was deleted.

3 changes: 0 additions & 3 deletions doc/examples/svg/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions doc/examples/svg/assets/android.svg

This file was deleted.

38 changes: 0 additions & 38 deletions doc/examples/svg/lib/main.dart

This file was deleted.

21 changes: 0 additions & 21 deletions doc/examples/svg/pubspec.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions doc/examples/text/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ TextConfig tiny = regular.withFontSize(12.0);

class MyTextBox extends TextBoxComponent {
MyTextBox(String text)
: super(text,
config: tiny, boxConfig: const TextBoxConfig(timePerChar: 0.05));
: super(text, config: tiny, boxConfig: TextBoxConfig(timePerChar: 0.05));

@override
void drawBackground(Canvas c) {
Expand Down
6 changes: 2 additions & 4 deletions doc/examples/timer/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class GameWidget extends StatelessWidget {
}

class RenderedTimeComponent extends TimerComponent {
final TextConfig textConfig =
const TextConfig(color: const Color(0xFFFFFFFF));
final TextConfig textConfig = TextConfig(color: const Color(0xFFFFFFFF));

RenderedTimeComponent(Timer timer) : super(timer);

Expand All @@ -58,8 +57,7 @@ class MyBaseGame extends BaseGame with TapDetector, DoubleTapDetector {
}

class MyGame extends Game with TapDetector {
final TextConfig textConfig =
const TextConfig(color: const Color(0xFFFFFFFF));
final TextConfig textConfig = TextConfig(color: const Color(0xFFFFFFFF));
Timer countdown;
Timer interval;

Expand Down
4 changes: 3 additions & 1 deletion doc/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ See example [here](/doc/examples/sprite_batch).

Flame provides a simple API to render SVG images in your game.

To use it just import the `Svg` class from `'package:flame/svg.dart'`, and use the following snippet to render it on the canvas:
Svg support is provided by the `flame_svg` external package, be sure to put it on your pubspec to use it

To use it just import the `Svg` class from `'package:flame_svg/flame_svg.dart'`, and use the following snippet to render it on the canvas:

```dart
Svg svgInstance = Svg('android.svg');
Expand Down
21 changes: 0 additions & 21 deletions lib/components/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:ui';
import 'package:flutter/painting.dart';
import 'package:meta/meta.dart';

import '../svg.dart';
import '../sprite.dart';
import '../position.dart';
import '../anchor.dart';
Expand Down Expand Up @@ -205,23 +204,3 @@ class SpriteComponent extends PositionComponent {
return sprite != null && sprite.loaded() && x != null && y != null;
}
}

class SvgComponent extends PositionComponent {
Svg svg;

SvgComponent.fromSvg(double width, double height, this.svg) {
this.width = width;
this.height = height;
}

@override
void render(Canvas canvas) {
prepareCanvas(canvas);
svg.render(canvas, width, height);
}

@override
bool loaded() {
return svg != null && svg.loaded() && x != null && y != null;
}
}
14 changes: 8 additions & 6 deletions lib/components/text_box_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TextBoxConfig {
final double timePerChar;
final double dismissDelay;

const TextBoxConfig({
TextBoxConfig({
this.maxWidth = 200.0,
this.margin = 8.0,
this.timePerChar = 0.0,
Expand Down Expand Up @@ -46,11 +46,13 @@ class TextBoxComponent extends PositionComponent with Resizable {

TextBoxConfig get boxConfig => _boxConfig;

TextBoxComponent(String text,
{TextConfig config = const TextConfig(),
TextBoxConfig boxConfig = const TextBoxConfig()}) {
_boxConfig = boxConfig;
_config = config;
TextBoxComponent(
String text, {
TextConfig config,
TextBoxConfig boxConfig,
}) {
_boxConfig = boxConfig ?? TextBoxConfig();
_config = config ?? TextConfig();
_text = text;
_lines = [];
text.split(' ').forEach((word) {
Expand Down
4 changes: 2 additions & 2 deletions lib/components/text_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class TextComponent extends PositionComponent {
_updateBox();
}

TextComponent(this._text, {TextConfig config = const TextConfig()}) {
_config = config;
TextComponent(this._text, {TextConfig config}) {
_config = config ?? TextConfig();
_updateBox();
}

Expand Down
27 changes: 27 additions & 0 deletions lib/memory_cache.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:collection';

/// Simple class to cache values on the cache
///
class MemoryCache<K, V> {
final LinkedHashMap<K, V> _cache = LinkedHashMap();
final int cacheSize;

MemoryCache({this.cacheSize = 10});

void setValue(K key, V value) {
if (!_cache.containsKey(key)) {
_cache[key] = value;

while (_cache.length > cacheSize) {
final k = _cache.keys.first;
_cache.remove(k);
}
}
}

V getValue(K key) => _cache[key];

bool containsKey(K key) => _cache.containsKey(key);

int get size => _cache.length;
}
Loading

0 comments on commit fb478f4

Please sign in to comment.