Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lisyce committed Apr 12, 2024
1 parent b654389 commit c7afd1a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 51 deletions.
4 changes: 3 additions & 1 deletion AssetPatches/PatchObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static void AddAllergen(AssetRequestedEventArgs e, string allergen)
objectData.ContextTags ??= new List<string>();
objectData.ContextTags.Add(GetAllergenContextTag(allergen));
}
});
},
AssetEditPriority.Late
);
}
}

Expand Down
39 changes: 23 additions & 16 deletions ContentPackFramework/LoadContentPacks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BZP_Allergies.Apis;
using BZP_Allergies.Config;
using BZP_Allergies.Config;
using StardewModdingAPI;

namespace BZP_Allergies.ContentPackFramework
Expand All @@ -18,6 +17,12 @@ public static void LoadPacks(IEnumerable<IContentPack> packs, ModConfig config)
}
}

private static string SanitizeAllergenId(string id)
{
// remove "," "_" and lowercase
return id.Replace(",", "").Replace("_", "").ToLower();
}

private static bool ProcessPack(IContentPack pack, ModConfig config)
{
ContentModel? content = pack.ReadJsonFile<ContentModel>("content.json");
Expand All @@ -44,57 +49,59 @@ private static bool ProcessPack(IContentPack pack, ModConfig config)
foreach (var pair in content.CustomAllergens)
{
CustomAllergen allergen = pair.Value;
string allergenId = SanitizeAllergenId(pair.Key);

if (allergen.Name == null)
{
Monitor.Log("No Name was specified for allergen with Id " + pair.Key, LogLevel.Error);
Monitor.Log("No Name was specified for allergen with Id " + allergenId, LogLevel.Error);
return false;
}

if (!AllergenManager.ALLERGEN_OBJECTS.ContainsKey(pair.Key))
if (!AllergenManager.ALLERGEN_OBJECTS.ContainsKey(allergenId))
{
AllergenManager.ALLERGEN_OBJECTS.Add(pair.Key, new HashSet<string>());
AllergenManager.ALLERGEN_OBJECTS.Add(allergenId, new HashSet<string>());
}

if (!AllergenManager.ALLERGEN_CONTEXT_TAGS.ContainsKey(pair.Key))
if (!AllergenManager.ALLERGEN_CONTEXT_TAGS.ContainsKey(allergenId))
{
AllergenManager.ALLERGEN_CONTEXT_TAGS.Add(pair.Key, new HashSet<string>());
AllergenManager.ALLERGEN_CONTEXT_TAGS.Add(allergenId, new HashSet<string>());
}

if (!AllergenManager.ALLERGEN_TO_DISPLAY_NAME.ContainsKey(pair.Key))
if (!AllergenManager.ALLERGEN_TO_DISPLAY_NAME.ContainsKey(allergenId))
{
AllergenManager.ALLERGEN_TO_DISPLAY_NAME.Add(pair.Key, allergen.Name);
AllergenManager.ALLERGEN_TO_DISPLAY_NAME.Add(allergenId, allergen.Name);
}

AllergenManager.ALLERGEN_CONTENT_PACK[pack.Manifest.UniqueID].Add(pair.Key);
AllergenManager.ALLERGEN_CONTENT_PACK[pack.Manifest.UniqueID].Add(allergenId);

if (!config.Farmer.Allergies.ContainsKey(pair.Key))
if (!config.Farmer.Allergies.ContainsKey(allergenId))
{
config.Farmer.Allergies.Add(pair.Key, false);
config.Farmer.Allergies.Add(allergenId, false);
}
}

// allergen assignments
foreach (var pair in content.AllergenAssignments)
{
AllergenAssignments allergenAssign = pair.Value;
string allergenId = SanitizeAllergenId(pair.Key);

if (pair.Key == null)
if (allergenId == null)
{
Monitor.Log("No AllergenId was specified for allergen assignment with Id " + pair.Key, LogLevel.Error);
Monitor.Log("No AllergenId was specified for allergen assignment with Id " + allergenId, LogLevel.Error);
return false;
}

// object Ids
foreach (string id in allergenAssign.ObjectIds)
{
AllergenManager.ALLERGEN_OBJECTS[pair.Key].Add(id);
AllergenManager.ALLERGEN_OBJECTS[allergenId].Add(id);
}

// context tags
foreach (string tag in allergenAssign.ContextTags)
{
AllergenManager.ALLERGEN_CONTEXT_TAGS[pair.Key].Add(tag);
AllergenManager.ALLERGEN_CONTEXT_TAGS[allergenId].Add(tag);
}
}

Expand Down
30 changes: 15 additions & 15 deletions ContentPacks/[BZPA] Cornucopia Allergies/content.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"Format": "1.0.0",
"CustomAllergens": {
"BarleyZP.cornucopia_peanut": {
"BarleyZP.CornucopiaPeanut": {
"Name": "Peanuts"
},
"BarleyZP.cornucopia_almond": {
"BarleyZP.CornucopiaAlmond": {
"Name": "Almonds"
},
"BarleyZP.cornucopia_cashew": {
"BarleyZP.CornucopiaCashew": {
"Name": "Cashews"
},
"BarleyZP.cornucopia_pecan": {
"BarleyZP.CornucopiaPecan": {
"Name": "Pecans"
},
"BarleyZP.cornucopia_pistachio": {
"BarleyZP.CornucopiaPistachio": {
"Name": "Pistachios"
},
"BarleyZP.cornucopia_walnut": {
"BarleyZP.CornucopiaWalnut": {
"Name": "Walnuts"
},
"BarleyZP.cornucopia_soy": {
"BarleyZP.CornucopiaSoy": {
"Name": "Soy"
}
},
Expand All @@ -31,7 +31,7 @@
"Cornucopia_DarkAle"
]
},
"treenut": {
"treenuts": {
"ObjectIds": [
"Cornucopia_Almond",
"Cornucopia_Cashew",
Expand All @@ -40,37 +40,37 @@
"Cornucopia_Walnut"
]
},
"BarleyZP.cornucopia_peanut": {
"BarleyZP.CornucopiaPeanut": {
"ObjectIds": [
"Cornucopia_Peanut"
]
},
"BarleyZP.cornucopia_almond": {
"BarleyZP.CornucopiaAlmond": {
"ObjectIds": [
"Cornucopia_Almond"
]
},
"BarleyZP.cornucopia_cashew": {
"BarleyZP.CornucopiaCashew": {
"ObjectIds": [
"Cornucopia_Cashew"
]
},
"BarleyZP.cornucopia_pecan": {
"BarleyZP.CornucopiaPecan": {
"ObjectIds": [
"Cornucopia_Pecan"
]
},
"BarleyZP.cornucopia_pistachio": {
"BarleyZP.CornucopiaPistachio": {
"ObjectIds": [
"Cornucopia_Pistachio"
]
},
"BarleyZP.cornucopia_walnut": {
"BarleyZP.CornucopiaWalnut": {
"ObjectIds": [
"Cornucopia_Walnut"
]
},
"BarleyZP.cornucopia_soy": {
"BarleyZP.CornucopiaSoy": {
"ObjectIds": [
"Cornucopia_Soybeans",
"Cornucopia_Tofu"
Expand Down
36 changes: 20 additions & 16 deletions ContentPacks/[BZPA] Cornucopia Allergies/manifest.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"Name": "[BZPA] Conrucopia Allergies",
"Author": "BarleyZP",
"Version": "1.0.0",
"Description": "Brings BarleyZP's Allergies to Cornucopia",
"UniqueID": "BarleyZP.BzpAllergiesCornucopia.BZPA",
"MinimumApiVersion": "3.8.0",
"UpdateKeys": [],
"ContentPackFor": {
"UniqueID": "BarleyZP.BzpAllergies"
"Name": "[BZPA] Cornucopia Allergies",
"Author": "BarleyZP",
"Version": "1.0.0",
"Description": "Brings BarleyZP's Allergies to Cornucopia",
"UniqueID": "BarleyZP.BzpAllergiesCornucopia.BZPA",
"MinimumApiVersion": "3.8.0",
"UpdateKeys": [],
"ContentPackFor": {
"UniqueID": "BarleyZP.BzpAllergies"
},
"Dependencies": [
{
"UniqueID": "BarleyZP.BzpAllergies",
"IsRequired": true
},
"Dependencies": [
{
"UniqueID": "BarleyZP.BzpAllergies",
"IsRequired": true
}
]
}
{
"UniqueID": "Cornucopia.MoreCrops",
"IsRequired": true
}
]
}
2 changes: 1 addition & 1 deletion [CP] BzpAllergies/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "BarleyZP Allergies [CP]",
"Author": "BarleyZP",
"Version": "1.2.0",
"Version": "1.2.1",
"Description": "BarleyZP's Allergy Mod Content Patcher Component",
"UniqueID": "BarleyZP.BzpAllergies.CP",
"MinimumApiVersion": "3.8.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/content_packs.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The `"Format"` field describes the version of this content pack framework that w

Here, you may define custom allergens outside of the six provided by the base mod. It is NOT recommended to edit the base six allergens, which have Ids `"egg"`, `"wheat"`, `"fish"`, `"shellfish"`, `"treenuts"`, and `"dairy"`.

Custom allergens are defined by a unique Id key, which is customarily in all lowercase and must be unique among ALL allergens in the game, including from other content packs. This unique Id may not contain commas. Custom allergens also have a `"Name"`, which is their name displayed to the player.
Custom allergens are defined by a unique Id key, which is customarily in all lowercase and must be unique among ALL allergens in the game, including from other content packs. This unique Id may not contain commas or underscores. Custom allergens also have a `"Name"`, which is their name displayed to the player.

### AllergenAssignments

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "BarleyZP's Allergies",
"Author": "BarleyZP",
"Version": "1.2.0",
"Version": "1.2.1",
"Description": "Adds food allergies to the game, with support for custom allergens.",
"UniqueID": "BarleyZP.BzpAllergies",
"EntryDll": "BzpAllergies.dll",
Expand Down

0 comments on commit c7afd1a

Please sign in to comment.