Skip to content

Commit

Permalink
Fix YASB expansion names that are possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony Saba committed Jun 14, 2024
1 parent bfa095f commit a58df86
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# X-Wing: The Miniature Game 2.0/2.5 Inventory Management Tools

This repository generates an Microsoft® Excel® for Microsoft 365 MSO for keeping
track of an X-Wing: The Miniature Game 2.0/2.5 colletion.
track of an X-Wing: The Miniature Game 2.0/2.5 collection.

As a command line interface (CLI), it gives you the ability to take your raw
[yasb collection](https://login.yasb.app/collection) and dump it to a `json`
Expand Down Expand Up @@ -76,6 +76,15 @@ Why rust?
> [System.Console]::OutputEncoding=[System.Text.Encoding]::UTF8
```

## Known Issues

* YASB Collection Quirks
* If you used YASP pre-2.0, your 1.0 expansions are still there, but of
won't be in YASB, except for the core sets and the ships that came with
obstacles, so they will print out as warning.
* "First Edition VT-49 Decimator": Records appear to have been removed when the VT-49 was
reprinted, so can't be imported like the other 1.0 obstacle sets.

## Contributing to the this repo

Have a look at the issues.
Expand All @@ -85,7 +94,7 @@ some tests for anything you are going to add.

### Adding new expansions

1. Update the `xwing-data2` submodule to a version that includes the expsnsion
1. Update the `xwing-data2` submodule to a version that includes the expansion
contents.
1. Add expansion to [src/expansions/expansions.json](src/expansions/expansions.json).
1. TODO
Expand Down
6 changes: 3 additions & 3 deletions src/expansions/expansions.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"xws": "coreasteroid5"
}
],
"name": "First Edition Core Set",
"name": "Core",
"sku": "swx01",
"wave": 0
},
Expand All @@ -69,7 +69,7 @@
"xws": "yt2400debris2"
}
],
"name": "First Edition YT-2400 Freighter Expansion Pack",
"name": "YT-2400 Freighter Expansion Pack",
"sku": "swx23",
"wave": 0
},
Expand Down Expand Up @@ -143,7 +143,7 @@
"xws": "core2asteroid5"
}
],
"name": "First Edition Force Awakens Core Set",
"name": "The Force Awakens Core Set",
"sku": "swx36",
"wave": 0
},
Expand Down
28 changes: 17 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ pub mod expansions;
pub mod xwingdata2;
pub mod yasb2;

use expansions::{Catalog, Expansion, ItemCount, ItemType, SKU};
use expansions::{Catalog, ItemCount, ItemType, SKU};
use serde::{Deserialize, Serialize};
use xwingdata2::Data;

use rust_xlsxwriter::utility::row_col_to_cell;
use rust_xlsxwriter::{Table, TableColumn, TableFunction, TableStyle, Workbook, XlsxError};

use std::cmp::Ordering;
use std::collections::BTreeMap;

#[derive(Debug)]
Expand Down Expand Up @@ -310,10 +311,11 @@ pub fn generate_xls(
data: &Data,
collection: &Collection,
inventory: &Inventory,
only_owned: bool,
) -> Result<(), XlsxError> {
let mut workbook = Workbook::new();

add_expansion_sheet(&mut workbook, catalog, collection)?;
add_expansion_sheet(&mut workbook, catalog, collection, only_owned)?;
// This must be done seperately because of the way borrows work on the
// workbook make it hard to work with more than 1 sheet at once.
add_ships_sheet(&mut workbook, catalog, data, collection, inventory)?;
Expand All @@ -331,21 +333,25 @@ fn add_expansion_sheet(
workbook: &mut Workbook,
catalog: &Catalog,
collection: &Collection,
only_owned: bool,
) -> Result<(), XlsxError> {
let worksheet = workbook.add_worksheet().set_name("Expansions")?;
for (i, col) in EXPANSION_COLS.iter().enumerate() {
worksheet.write(0, i as u16, *col)?;
}
let unknown = Expansion {
sku: "error".to_string(),
name: "notfound".to_string(),
wave: 0,
contents: vec![],
};
let mut row = 1;
for (e, c) in &collection.skus {
let exp = catalog.expansions.get(e).unwrap_or(&unknown);
worksheet.write(row, 0, *c)?;
let mut sorted_expansions = catalog.expansions.values().collect::<Vec<_>>();
sorted_expansions.sort_by(|a, b| match (a.wave.cmp(&b.wave), a.sku.cmp(&b.sku)) {
(Ordering::Less, _) => Ordering::Less,
(Ordering::Greater, _) => Ordering::Greater,
(_, x) => x,
});
for exp in sorted_expansions {
let c = *collection.skus.get(&exp.sku).unwrap_or(&0);
if c == 0 && only_owned {
continue;
}
worksheet.write(row, 0, c)?;
worksheet.write(row, 1, &exp.name)?;
worksheet.write(row, 2, exp.wave)?;
worksheet.write(row, 3, &exp.sku)?;
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FLAGS:
-h, --help Prints help information
-f, --format json or xlsx (default: xlsx)
-c, --collection A YASB collection in YASB's json format
-o, --only-owned Includes all known expansions and contents
-o, --only-owned Don't include unowned expansions and contents
";

#[derive(PartialEq, EnumString)]
Expand Down Expand Up @@ -169,7 +169,13 @@ fn main() {
}
}
Format::Xlsx => {
match xwingtmg2_inventory_rs::generate_xls(&catalog, &data, &collection, &inventory) {
match xwingtmg2_inventory_rs::generate_xls(
&catalog,
&data,
&collection,
&inventory,
args.only_owned,
) {
Ok(_) => println!("xlsx written"),
Err(err) => println!("xlsx error: {}", err),
}
Expand Down

0 comments on commit a58df86

Please sign in to comment.