swlegion 0.4.0

Database and Data Model for Star Wars: Legion.

Build Status

This package is written and maintained in Dart for maintainability. Future versions will have JSON-formatted build artifacts as well for use within other systems.

Star Wars, Star Wars: Legion and all related properties and text are owned by Fantasy Flight Games, Lucasfilm Ltd., and/or Disney.

Usage #

This package provides 2 libraries: catalog.dart and swlegion.dart. Library catalog is a (best effort) collection of all known cards and other models that may change over time. Common APIs include:

  • catalog.commands and Commands
  • catalog.units and Units
  • catalog.upgrades and Upgrades

Library swlegion.dart is just the data models, with the idea that they are used to create catalog.dart (and exported as catalog.json for use in non-Dart clients).

There is also a utility class Catalog (or the built-in instance, catalog) which adds the ability to do easy aggregations or compuations, for example which Upgrade(s) are valid given a Unit instance or reference, and a utility class Holodeck for running dice simulations and calculating statistics.

0.4.0 #

Large set of breaking changes and new content!

Catalog #

  • Renamed database.dart to catalog.dart. See the top-level field catalog.

Data Model #

  • Added surge_override (AttackSurge) field to Weapon.
  • Significant data model change for Keyword, now split into 3 new classes.
  • Changed the default serializers to always use standard JSON, fixed encoding issues that would cause issues with Firebase or other database formats that expect valid JSON. See lib/catalog.json for example output. Use the exported CustomJsonPlugin instead of StandardJsonPlugin.
  • Added ForceAlignment (instead of just Faction).

Holodeck #

  • Holodeck is now a utility class for executing simulations.
  • The existing database structure and reference lookups were moved to Catalog.

0.3.1 #

Database #

  • Added Chewbacca Operative Expansion.
  • Added Wookie Warriors Expansion.
  • Fixed the ID of Battle Meditation.
  • Added keywords to upgrades that provide them on active or passively.

Holodeck #

  • costOfUnit now treats upgrades as a @required named parameter.
  • Added totalMiniatures(unit, {Iterable<Reference<Upgrade>> upgrades}).

0.3.0 #

Data Model #

  • Corrects Upgrade to only compare based on .id.
  • Indexable.toRef is now optional, as an Indexable is also a Reference.

Database #

  • Normalized all enum IDs as lower-hyphenated-case.
  • Added .from to every enum, to use instead of valueOf.
  • Added .toString() to Reference to aid in debugging.
  • Added missing .isUnique = true for commanders/operatives.
  • Upgrade emergency stims now has a corrected ID of emergency-stims.
  • Created Commands, Units, Upgrades, Weapons classes for convenience:
import 'package:swlegion/database.dart';

void main() {
  print(Units.stormtroopers.points); // 44

Mechanics #

  • Added a new class, Holodeck, for game logic and helper functionality that is not strictly tied to the database nor to the serialized JSON model(s):
import 'package:swlegion/database.dart';
import 'package:swlegion/swlegion.dart';

void main() {
  // Can create a `Holodeck` using the provided data:
  final customDeck = Holodeck(
    commands: commands,
    units: units,
    upgrades: upgrades,

  // Or use the default `Holodeck` directly.

0.2.0 #

Data Model #

  • Moved Army and ArmyUnit out of this package.
  • CommandCard was added.
  • Replaced *Key instances with a single Reference<T> instance.
    • CommandCard, Unit, Upgrade all now implement Indexable<T>.
    • Upgrade's .restrictedToUnit is now a BuiltSet<Reference<Unit>>.

Database #

  • Added 'Emergency Stims' (Gear), which was accidentally omitted.
  • Fixed the cost of 'Estmeed Leader' (Command), which is 5 points not 10.
  • Fixed the ID of 'Esteemed Leader', which was mis-spelled.
  • Added CommandCard(s) for every existing commander and operative.

0.1.0 #

  • Initial stable release.


import 'package:swlegion/catalog.dart';
import 'package:swlegion/holodeck.dart';
import 'package:swlegion/swlegion.dart';

// Prints the name, points, and valid upgrades for a few units.
void main() {
  print('=' * 80);
  print('=' * 80);

void printNamePointsAndUpgrades() {
  final researchUnits = [

  for (final unit in researchUnits) {
    print('${unit.name} (${unit.points}): ');
    for (final upgrade in catalog.upgradesForUnit(unit)) {
      print('  * ${upgrade.name} (${upgrade.points})');

void simulateAttackWithTroopers() {
  final holodeck = Holodeck();
  final timer = Stopwatch()..start();
  var sumWounds = 0;
  for (var i = 0; i < 10000; i++) {
    final z6Attack = holodeck.rollAttacks(
      AttackDice.white * 6 + AttackDice.black * 4,
    final wounds = holodeck.simulateWounds(
      // Rebel Troopers + Z6
        weapons: {
          Weapons.a280BlasterRifle: 4,
          Weapons.z6RotaryBlaster: 1,
      // Stormtroopers
        dice: DefenseDice.red,
    sumWounds += wounds;
  final median = sumWounds / 10000;
    'Wounds (10000 Sample) of Z6 -> Stormtroopers: ${median.toStringAsFixed(1)} in ${timer.elapsedMilliseconds}ms',

Use this package as a library

1. Depend on it

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

  swlegion: ^0.4.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:swlegion/swlegion.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:swlegion/swlegion.dart.

Health suggestions

Fix lib/src/model/faction.g.dart. (-1 points)

Analysis of lib/src/model/faction.g.dart reported 2 hints:

line 75 col 15: 'valueOf' is deprecated and shouldn't be used.

line 102 col 22: 'valueOf' is deprecated and shouldn't be used.

Fix lib/src/model/attack_dice.g.dart. (-0.50 points)

Analysis of lib/src/model/attack_dice.g.dart reported 1 hint:

line 60 col 18: 'valueOf' is deprecated and shouldn't be used.

Fix lib/src/model/attack_surge.g.dart. (-0.50 points)

Analysis of lib/src/model/attack_surge.g.dart reported 1 hint:

line 54 col 19: 'valueOf' is deprecated and shouldn't be used.

Fix additional 4 files with analysis or formatting issues. (-2 points)

Additional issues in the following files:

  • lib/src/model/defense_dice.g.dart (1 hint)
  • lib/src/model/rank.g.dart (1 hint)
  • lib/src/model/unit_type.g.dart (1 hint)
  • lib/src/model/upgrade_slot.g.dart (1 hint)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
args ^1.5.1 1.5.2
built_collection ^4.0.0 4.2.2
built_value ^6.1.6 6.7.1
collection ^1.14.11 1.14.12
meta ^1.1.6 1.1.7
Transitive dependencies
fixnum 0.10.9
matcher 0.12.5
quiver 2.0.5
stack_trace 1.9.3
Dev dependencies
analyzer ^0.34.2
build ^1.0.2
build_runner ^1.1.2
built_value_generator ^6.1.6
glob ^1.1.7
path ^1.6.2 1.6.4
test ^1.5.1
yaml ^2.1.15