style: rustfmt squad host + adapter files

Formatting-only. Runs the project formatter over the files authored/edited
this session (host lib+tests, adapter item/squad_ext/squad_projection/mod +
projection test). The intentionally-preserved dirty catalog.rs and
pre-existing /club-era host drift beyond these files are out of scope.
This commit is contained in:
funman300
2026-08-12 03:59:15 +00:00
parent afc909fd3b
commit c2e2e0d8f2
7 changed files with 744 additions and 177 deletions
@@ -109,7 +109,10 @@ impl std::fmt::Display for SquadProjectError {
write!(f, "projection input missing owned item {id}")
}
SquadProjectError::NoFifaIdentity(id) => {
write!(f, "owned item {id} has no real FIFA asset identity (cannot render)")
write!(
f,
"owned item {id} has no real FIFA asset identity (cannot render)"
)
}
}
}
@@ -139,10 +142,9 @@ pub fn project_squad<I: ItemIdentityResolver + ?Sized>(
for index in 0..FIFA17_SQUAD_SLOTS {
match by_index.get(&index) {
Some(slot) => {
let item = input
.owned
.get(&slot.owned_card_id)
.ok_or_else(|| SquadProjectError::MissingOwnedItem(slot.owned_card_id.clone()))?;
let item = input.owned.get(&slot.owned_card_id).ok_or_else(|| {
SquadProjectError::MissingOwnedItem(slot.owned_card_id.clone())
})?;
let id = ident
.resolve(item)
.ok_or_else(|| SquadProjectError::NoFifaIdentity(slot.owned_card_id.clone()))?;
@@ -150,7 +152,11 @@ pub fn project_squad<I: ItemIdentityResolver + ?Sized>(
captain_wire = id.item_id as i64;
}
// kit follows the player: look it up by owned id, never by index.
let kit = ext.kit_numbers.get(&slot.owned_card_id).copied().unwrap_or(0);
let kit = ext
.kit_numbers
.get(&slot.owned_card_id)
.copied()
.unwrap_or(0);
players.push(json!({
"index": index,
"itemData": shape_item(item, id, ent),
@@ -278,14 +284,24 @@ mod tests {
owned.insert("oc1".to_string(), owned_item("oc1", "card_x"));
let ident = TableIdentity(HashMap::from([(
"oc1".to_string(),
Fifa17Identity { item_id: 100000042, asset_id: 20801 },
Fifa17Identity {
item_id: 100000042,
asset_id: 20801,
},
)]));
let input = one_slot_input(&owned, SquadExtInput::Fresh(fresh_ext()));
let SquadProjection::Projected(v) = project_squad(&input, &ident, &ent()).unwrap() else {
panic!("expected Projected");
};
assert_eq!(v["players"].as_array().unwrap().len(), 23, "fixed 23-slot array");
assert_eq!(v["players"][0]["itemData"]["id"], 100000042, "wire id, not resourceId");
assert_eq!(
v["players"].as_array().unwrap().len(),
23,
"fixed 23-slot array"
);
assert_eq!(
v["players"][0]["itemData"]["id"], 100000042,
"wire id, not resourceId"
);
assert_eq!(v["players"][0]["itemData"]["resourceId"], 20801);
assert_eq!(v["players"][0]["kitNumber"], 9, "kit from ext by owned id");
assert_eq!(v["players"][1]["itemData"]["id"], 0, "empty slot");
@@ -301,7 +317,10 @@ mod tests {
// A stale extension IS carried (host may log it) but must not be applied.
let input = one_slot_input(&owned, SquadExtInput::Stale(fresh_ext()));
let ident = TableIdentity(HashMap::new());
assert_eq!(project_squad(&input, &ident, &ent()).unwrap(), SquadProjection::Stale);
assert_eq!(
project_squad(&input, &ident, &ent()).unwrap(),
SquadProjection::Stale
);
}
#[test]
@@ -309,7 +328,10 @@ mod tests {
let owned = HashMap::new();
let input = one_slot_input(&owned, SquadExtInput::Missing);
let ident = TableIdentity(HashMap::new());
assert_eq!(project_squad(&input, &ident, &ent()).unwrap(), SquadProjection::Missing);
assert_eq!(
project_squad(&input, &ident, &ent()).unwrap(),
SquadProjection::Missing
);
}
#[test]
@@ -332,21 +354,46 @@ mod tests {
owned.insert("oc-a".to_string(), owned_item("oc-a", "fifa17_101490"));
owned.insert("oc-b".to_string(), owned_item("oc-b", "fifa17_101490"));
let ident = TableIdentity(HashMap::from([
("oc-a".to_string(), Fifa17Identity { item_id: 100000030, asset_id: 101490 }),
("oc-b".to_string(), Fifa17Identity { item_id: 100000031, asset_id: 101490 }),
(
"oc-a".to_string(),
Fifa17Identity {
item_id: 100000030,
asset_id: 101490,
},
),
(
"oc-b".to_string(),
Fifa17Identity {
item_id: 100000031,
asset_id: 101490,
},
),
]));
let mut kit = std::collections::BTreeMap::new();
kit.insert("oc-a".to_string(), 7);
kit.insert("oc-b".to_string(), 19);
let ext = Fifa17SquadExtensionV1 { kit_numbers: kit, ..fresh_ext() };
let ext = Fifa17SquadExtensionV1 {
kit_numbers: kit,
..fresh_ext()
};
let owned_ref = &owned;
let input = SquadProjectionInput {
fifa_squad_id: 0,
name: "OpenFUT".into(),
formation: "f442".into(),
slots: vec![
ProjectionSlot { owned_card_id: "oc-a".into(), index: 0, is_captain: false, is_on_bench: false },
ProjectionSlot { owned_card_id: "oc-b".into(), index: 1, is_captain: false, is_on_bench: false },
ProjectionSlot {
owned_card_id: "oc-a".into(),
index: 0,
is_captain: false,
is_on_bench: false,
},
ProjectionSlot {
owned_card_id: "oc-b".into(),
index: 1,
is_captain: false,
is_on_bench: false,
},
],
ext: SquadExtInput::Fresh(ext),
owned: owned_ref,
@@ -356,9 +403,18 @@ mod tests {
};
let a = &v["players"][0]["itemData"];
let b = &v["players"][1]["itemData"];
assert_eq!(a["resourceId"], b["resourceId"], "same definition => same asset");
assert_ne!(a["id"], b["id"], "distinct owned copies keep distinct wire ids");
assert_eq!(
a["resourceId"], b["resourceId"],
"same definition => same asset"
);
assert_ne!(
a["id"], b["id"],
"distinct owned copies keep distinct wire ids"
);
assert_eq!(v["players"][0]["kitNumber"], 7);
assert_eq!(v["players"][1]["kitNumber"], 19, "kit stays with the instance");
assert_eq!(
v["players"][1]["kitNumber"], 19,
"kit stays with the instance"
);
}
}