Skip to content

Commit

Permalink
Merge pull request #336 from Ariemeth/rules_sheet
Browse files Browse the repository at this point in the history
Adding rules sheet to the printed and PDF records
  • Loading branch information
Ariemeth authored Jan 10, 2024
2 parents 94511d9 + 1ffed71 commit 127c49b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/screens/roster/pdf/pdf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import 'dart:typed_data';
import 'package:file_selector/file_selector.dart';
import 'package:gearforce/models/roster/roster.dart';
import 'package:gearforce/screens/roster/pdf/record_sheet/record_sheet.dart';
import 'package:gearforce/screens/roster/pdf/record_sheet/rules_sheet.dart';
import 'package:gearforce/screens/roster/pdf/record_sheet/traits_sheet.dart';
import 'package:gearforce/screens/roster/pdf/unit_cards/unit_cards.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';

const String _defaultRosterFileName = 'hg-roster';
const String _webURL = 'https://gf.metadiversions.com';
const String _webURL = 'https://gearforce.metadiversions.com';

const double _leftRightPageMargins = PdfPageFormat.inch / 8.0;
const double _topPageMargins = PdfPageFormat.inch / 32;
Expand Down Expand Up @@ -84,6 +85,16 @@ Future<Uint8List> buildPdf(PdfPageFormat format, UnitRoster roster,
return _buildFooter(context, version, roster.rulesVersion);
}));

// Add Rules reference page
doc.addPage(pw.MultiPage(
pageTheme: pageTheme,
build: (context) {
return [buildRulesSheet(font, roster)];
},
footer: (pw.Context context) {
return _buildFooter(context, version, roster.rulesVersion);
}));

// Build and return the final Pdf file data
return doc.save();
}
Expand Down
79 changes: 79 additions & 0 deletions lib/screens/roster/pdf/record_sheet/rules_sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:gearforce/models/roster/roster.dart';
import 'package:gearforce/models/rules/faction_rule.dart';
import 'package:pdf/widgets.dart' as pw;

const double _headerTextSize = 12;
const double _standardTextSize = 10;

pw.Widget buildRulesSheet(pw.Font font, UnitRoster roster) {
// Faction rules
final List<(String, String)> factionRules = [];
FactionRule.enabledRules(roster.rulesetNotifer.value.factionRules)
.forEach((fr) {
factionRules.add((fr.name, fr.description));
});

final List<(String, String)> subFactionRules = [];
FactionRule.enabledRules(roster.rulesetNotifer.value.subFactionRules)
.forEach((fr) {
subFactionRules.add((fr.name, fr.description));
});

final sheet = pw.Column(children: [
_buildRuleTable(font, ['Faction Rule', 'Description'], factionRules),
_buildRuleTable(font, ['Sub-Faction Rule', 'Description'], subFactionRules),
]);

return pw.Padding(
padding: pw.EdgeInsets.only(
left: 10.0,
right: 10.0,
top: 10.0,
bottom: 10.0,
),
child: sheet,
);
}

pw.Widget _buildRuleTable(
pw.Font font,
List<String> tableHeaders,
List<(String, String)> rules,
) {
if (rules.isEmpty) {
return pw.Container();
}
var table = pw.TableHelper.fromTextArray(
cellStyle: pw.TextStyle(
font: font,
fontSize: _standardTextSize,
),
columnWidths: {
0: const pw.FixedColumnWidth(200.0),
},
headers: tableHeaders,
headerStyle: pw.TextStyle(
font: font,
fontSize: _headerTextSize,
fontWeight: pw.FontWeight.bold,
),
data: List<List<String>>.generate(
rules.length,
(row) => List<String>.generate(tableHeaders.length, (col) {
switch (col) {
case 0:
return rules[row].$1;
case 1:
return rules[row].$2;
default:
return '';
}
}),
),
);
return pw.Padding(
padding: pw.EdgeInsets.only(
bottom: 10.0,
),
child: table);
}
2 changes: 1 addition & 1 deletion lib/screens/roster/roster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:url_launcher/url_launcher_string.dart';
const double _leftPanelWidth = 670.0;
const double _titleHeight = 40.0;
const double _menuTitleHeight = 50.0;
const String _version = '0.100.1';
const String _version = '0.101.0';
const String _bugEmailAddress = '[email protected]';
const String _dp9URL = 'https://www.dp9.com/';
const String _sourceCodeURL = 'https://github.com/Ariemeth/gearforce-flutter';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.100.1
version: 0.101.0

environment:
sdk: ">=3.0.0"
Expand Down

0 comments on commit 127c49b

Please sign in to comment.