swlegion 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 59

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.
  print(holodeck.validUpgradesForUnit(Units.stormtroopers));
}

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.

example/main.dart

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);
  printNamePointsAndUpgrades();
  print('=' * 80);
  simulateAttackWithTroopers();
}

void printNamePointsAndUpgrades() {
  final researchUnits = [
    Units.emperorPalpatine,
    Units.imperialRoyalGuards,
    Units.scoutTroopersStrikeTeam,
  ];

  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,
      AttackSurge.hit,
    );
    final wounds = holodeck.simulateWounds(
      z6Attack,
      // Rebel Troopers + Z6
      holodeck.formAttackPool(
        Units.rebelTroopers,
        weapons: {
          Weapons.a280BlasterRifle: 4,
          Weapons.z6RotaryBlaster: 1,
        },
      ),
      // Stormtroopers
      DefensePool.of(
        dice: DefenseDice.red,
      ),
    );
    sumWounds += wounds;
  }
  final median = sumWounds / 10000;
  print(
    '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:


dependencies:
  swlegion: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.4.0 Feb 8, 2019 Go to the documentation of swlegion 0.4.0 Download swlegion 0.4.0 archive
0.3.0 Dec 31, 2018 Go to the documentation of swlegion 0.3.0 Download swlegion 0.3.0 archive
0.2.0 Dec 24, 2018 Go to the documentation of swlegion 0.2.0 Download swlegion 0.2.0 archive
0.1.0 Dec 21, 2018 Go to the documentation of swlegion 0.1.0 Download swlegion 0.1.0 archive
0.1.0-alpha+4 Dec 7, 2018 Go to the documentation of swlegion 0.1.0-alpha+4 Download swlegion 0.1.0-alpha+4 archive
0.1.0-alpha+3 Dec 7, 2018 Go to the documentation of swlegion 0.1.0-alpha+3 Download swlegion 0.1.0-alpha+3 archive
0.1.0-alpha+2 Dec 7, 2018 Go to the documentation of swlegion 0.1.0-alpha+2 Download swlegion 0.1.0-alpha+2 archive
0.1.0-alpha+1 Dec 6, 2018 Go to the documentation of swlegion 0.1.0-alpha+1 Download swlegion 0.1.0-alpha+1 archive
0.1.0-alpha Nov 23, 2018 Go to the documentation of swlegion 0.1.0-alpha Download swlegion 0.1.0-alpha archive
Popularity:
Describes how popular the package is relative to other packages. [more]
20
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13+1

Platforms

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)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
args ^1.5.1 1.5.1
built_collection ^4.0.0 4.1.0
built_value ^6.1.6 6.3.0
collection ^1.14.11 1.14.11
meta ^1.1.6 1.1.7
Transitive dependencies
fixnum 0.10.9
matcher 0.12.4
quiver 2.0.1
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.2
test ^1.5.1
yaml ^2.1.15