Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseGameInitialKnownItemList backwards compatibility hotfix #23

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion about.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ accepted = [
"CC0-1.0",
"MPL-2.0",
"BSD-3-Clause",
"ISC"
"ISC",
"Unicode-3.0"
]

[unreal_asset.clarify]
Expand Down
48 changes: 33 additions & 15 deletions astro_mod_integrator/src/handlers/item_list_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,45 @@ pub(crate) fn handle_item_list_entries(
.as_object()
.ok_or_else(|| io::Error::new(ErrorKind::Other, "Invalid item_list_entries"))?;

// we duplicate /Game/Items/ItemTypes/MasterItemList entries into /Game/Items/ItemTypes/BaseGameInitialKnownItemList, if the latter list is not specified
// this provides backwards compatibility for older mods
// this can just be suppressed by specifying an entry for /Game/Items/ItemTypes/BaseGameInitialKnownItemList in metadata
let exists_bgikil = item_list_entries_map.contains_key("/Game/Items/ItemTypes/BaseGameInitialKnownItemList");

for (name, item_list_entries) in item_list_entries_map {
let item_list_entries = item_list_entries
.as_object()
.ok_or_else(|| io::Error::new(ErrorKind::Other, "Invalid item_list_entries"))?;
let new_items_entry = new_items.entry(name.clone()).or_insert_with(HashMap::new);

for (item_name, entries) in item_list_entries {
let entries = entries
.as_array()
.ok_or_else(|| io::Error::new(ErrorKind::Other, "Invalid item_list_entries"))?;

let new_items_entry_map = new_items_entry
.entry(item_name.clone())
.or_insert_with(Vec::new);
for entry in entries {
let entry = entry.as_str().ok_or_else(|| {
io::Error::new(ErrorKind::Other, "Invalid item_list_entries")
})?;
new_items_entry_map.push(String::from(entry));

{
let new_items_entry = new_items.entry(name.clone()).or_insert_with(HashMap::new);

for (item_name, entries) in item_list_entries {
let entries = entries
.as_array()
.ok_or_else(|| io::Error::new(ErrorKind::Other, "Invalid item_list_entries"))?;

let new_items_entry_map = new_items_entry
.entry(item_name.clone())
.or_insert_with(Vec::new);
for entry in entries {
let entry = entry.as_str().ok_or_else(|| {
io::Error::new(ErrorKind::Other, "Invalid item_list_entries")
})?;
new_items_entry_map.push(String::from(entry));
}
}
}

// duplicate to BaseGameInitialKnownItemList appropriately, if applicable
if name == "/Game/Items/ItemTypes/MasterItemList" && !exists_bgikil {
let orig_entry = new_items.entry(name.clone()).or_insert_with(HashMap::new).clone();

new_items
.entry(String::from("/Game/Items/ItemTypes/BaseGameInitialKnownItemList"))
.or_insert_with(HashMap::new)
.extend(orig_entry);
}
}
}

Expand Down
Loading