Skip to content

Commit

Permalink
Merge pull request #23 from atenfyr/bgikil-fix
Browse files Browse the repository at this point in the history
BaseGameInitialKnownItemList backwards compatibility hotfix
  • Loading branch information
konsti219 authored Dec 6, 2024
2 parents 87145c9 + 832aa77 commit 7a00fc7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
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

0 comments on commit 7a00fc7

Please sign in to comment.