ecs_dart 0.1.0

  • Readme
  • Changelog
  • Installing
  • 54

Dart realisation of ECS pattern

License: MIT

Usage #

A simple usage example:

import 'package:ecs_dart/ecs_dart.dart';

void main() {
  final ecs = EcsDart();

  final entity = ecs.addEntity('1', components: [NumberComponent()..number=0]);
  final numberStreamController = StreamController<int>.broadcast(sync: true);

  ecs.registerSystem(IncrementSystem());
  ecs.registerSystem(HandleNumberStreamSystem(numberStreamController.stream));

  numberStreamController.add(10);
  ecs.update(); // this can be used in requestAnimationFrame or another loop with fixed update time

  //entity.getComponent<NumberComponent>().number == 11

}
// Execute systems are simple and executes on every update call;
class IncrementSystem extends ExecuteSystem {
  @override
  void execute(double deltaTime) {
    entities.select(all: [NumberComponent]).forEach((entity) {
      final intData = entity.getComponent<NumberComponent>();
      intData.number++;
    });
  }
}

// Event handler system does not guarantee order of execution it may cause problems, but im working on it.
class HandleNumberStreamSystem extends EventHandlerSystem<int> {
  HandleIntStreamSystem(Stream<int> stream) : super(stream);

  @override
  void handle(int event) {
    entities.select(all: [NumberComponent]).forEach((entity){
      final intData = entity.getComponent<NumberComponent>();
      intData.number = event;
    });
  }
}

// Components can be mutable...
class NumberComponent implements Component {
  int number;
}

//.. or not. For update use entity.setComponent(new ImmutableNumberComponent(1))

class ImmutableNumberComponent implements Component {
  final int number;

  ImmutableNumberComponent(this.number);
}

0.1.0 #

  • Initial version, created by Raphael Kamaltinov

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ecs_dart: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ecs_dart/ecs_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Health suggestions

Format lib/src/ecs_dart_base.dart.

Run dartfmt to format lib/src/ecs_dart_base.dart.

Format lib/src/managers/entity_manager.dart.

Run dartfmt to format lib/src/managers/entity_manager.dart.

Format lib/src/managers/system_manager.dart.

Run dartfmt to format lib/src/managers/system_manager.dart.

Format lib/src/systems/system.dart.

Run dartfmt to format lib/src/systems/system.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and ecs_dart.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
meta ^1.1.8 1.2.2 1.3.0-nullsafety
path ^1.6.0 1.7.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0