mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	Fixing game crashes on web
This commit is contained in:
		@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## [next]
 | 
					## [next]
 | 
				
			||||||
 - Adding MemoryCache class
 | 
					 - Adding MemoryCache class
 | 
				
			||||||
 | 
					 - Fixing games crashes on Web
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 0.23.0
 | 
					## 0.23.0
 | 
				
			||||||
 - Add Joystick Component
 | 
					 - Add Joystick Component
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@ class TextBoxConfig {
 | 
				
			|||||||
  final double timePerChar;
 | 
					  final double timePerChar;
 | 
				
			||||||
  final double dismissDelay;
 | 
					  final double dismissDelay;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const TextBoxConfig({
 | 
					  TextBoxConfig({
 | 
				
			||||||
    this.maxWidth = 200.0,
 | 
					    this.maxWidth = 200.0,
 | 
				
			||||||
    this.margin = 8.0,
 | 
					    this.margin = 8.0,
 | 
				
			||||||
    this.timePerChar = 0.0,
 | 
					    this.timePerChar = 0.0,
 | 
				
			||||||
@ -46,11 +46,12 @@ class TextBoxComponent extends PositionComponent with Resizable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  TextBoxConfig get boxConfig => _boxConfig;
 | 
					  TextBoxConfig get boxConfig => _boxConfig;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TextBoxComponent(String text,
 | 
					  TextBoxComponent(String text, {
 | 
				
			||||||
      {TextConfig config = const TextConfig(),
 | 
					    TextConfig config,
 | 
				
			||||||
      TextBoxConfig boxConfig = const TextBoxConfig()}) {
 | 
					    TextBoxConfig boxConfig,
 | 
				
			||||||
    _boxConfig = boxConfig;
 | 
					  }) {
 | 
				
			||||||
    _config = config;
 | 
					    _boxConfig = boxConfig ?? TextBoxConfig();
 | 
				
			||||||
 | 
					    _config = config ?? TextConfig();
 | 
				
			||||||
    _text = text;
 | 
					    _text = text;
 | 
				
			||||||
    _lines = [];
 | 
					    _lines = [];
 | 
				
			||||||
    text.split(' ').forEach((word) {
 | 
					    text.split(' ').forEach((word) {
 | 
				
			||||||
 | 
				
			|||||||
@ -27,8 +27,8 @@ class TextComponent extends PositionComponent {
 | 
				
			|||||||
    _updateBox();
 | 
					    _updateBox();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TextComponent(this._text, {TextConfig config = const TextConfig()}) {
 | 
					  TextComponent(this._text, {TextConfig config }) {
 | 
				
			||||||
    _config = config;
 | 
					    _config = config ?? TextConfig();
 | 
				
			||||||
    _updateBox();
 | 
					    _updateBox();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import 'package:flutter/material.dart' as material;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import 'position.dart';
 | 
					import 'position.dart';
 | 
				
			||||||
import 'anchor.dart';
 | 
					import 'anchor.dart';
 | 
				
			||||||
 | 
					import 'memory_cache.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A Text Config contains all typographical information required to render texts; i.e., font size and color, family, etc.
 | 
					/// A Text Config contains all typographical information required to render texts; i.e., font size and color, family, etc.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
@ -52,10 +53,12 @@ class TextConfig {
 | 
				
			|||||||
  /// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
 | 
					  /// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
 | 
				
			||||||
  final TextDirection textDirection;
 | 
					  final TextDirection textDirection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  final MemoryCache _textPainterCache = MemoryCache<String, material.TextPainter>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Creates a constant [TextConfig] with sensible defaults.
 | 
					  /// Creates a constant [TextConfig] with sensible defaults.
 | 
				
			||||||
  ///
 | 
					  ///
 | 
				
			||||||
  /// Every parameter can be specified.
 | 
					  /// Every parameter can be specified.
 | 
				
			||||||
  const TextConfig({
 | 
					  TextConfig({
 | 
				
			||||||
    this.fontSize = 24.0,
 | 
					    this.fontSize = 24.0,
 | 
				
			||||||
    this.color = const Color(0xFF000000),
 | 
					    this.color = const Color(0xFF000000),
 | 
				
			||||||
    this.fontFamily = 'Arial',
 | 
					    this.fontFamily = 'Arial',
 | 
				
			||||||
@ -93,6 +96,7 @@ class TextConfig {
 | 
				
			|||||||
  /// However, you probably want to use the [render] method witch already renders for you considering the anchor.
 | 
					  /// However, you probably want to use the [render] method witch already renders for you considering the anchor.
 | 
				
			||||||
  /// That way, you don't need to perform the math for yourself.
 | 
					  /// That way, you don't need to perform the math for yourself.
 | 
				
			||||||
  material.TextPainter toTextPainter(String text) {
 | 
					  material.TextPainter toTextPainter(String text) {
 | 
				
			||||||
 | 
					    if (!_textPainterCache.containsKey(text)) {
 | 
				
			||||||
      final material.TextStyle style = material.TextStyle(
 | 
					      final material.TextStyle style = material.TextStyle(
 | 
				
			||||||
          color: color,
 | 
					          color: color,
 | 
				
			||||||
          fontSize: fontSize,
 | 
					          fontSize: fontSize,
 | 
				
			||||||
@ -108,7 +112,10 @@ class TextConfig {
 | 
				
			|||||||
          textDirection: textDirection,
 | 
					          textDirection: textDirection,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      tp.layout();
 | 
					      tp.layout();
 | 
				
			||||||
    return tp;
 | 
					
 | 
				
			||||||
 | 
					      _textPainterCache.setValue(text, tp);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return _textPainterCache.getValue(text);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Creates a new [TextConfig] changing only the [fontSize].
 | 
					  /// Creates a new [TextConfig] changing only the [fontSize].
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user