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

Better fix for #390 - Use AddGadget, but only when needed #404

Merged
merged 4 commits into from
Jun 19, 2023

Conversation

vlyon
Copy link
Contributor

@vlyon vlyon commented Jun 11, 2023

This fixes the duplicate gadget exception by only using AddGadget when needed. (More efficient)

@LeeTwentyThree
Copy link
Member

Personally I preferred it the old way since it had less duplication of the "functional" code and property setting, but it's really personal preference. We can ask other contributors what they prefer.

@vlyon
Copy link
Contributor Author

vlyon commented Jun 16, 2023

This way actually has less duplication and less redundant code. It makes use of the return value of TryGetGadget instead of ignoring it and then trying to add the gadget again. This way it also avoids setting properties when the newly created gadgets have just been initialised with those properties.

@LeeTwentyThree
Copy link
Member

I already asked ECM and I think she didn't mind either way. I'll ask one other "maintainer" and see what they think.

@JKohlman
Copy link
Contributor

Ask and you shall receive an even harder decision, A THIRD OPTION!

public static CraftingGadget SetRecipe(this ICustomPrefab customPrefab, RecipeData recipeData)
{
    if (!customPrefab.TryGetGadget(out CraftingGadget craftingGadget))
        return customPrefab.AddGadget(new CraftingGadget(customPrefab, recipeData));
    craftingGadget.RecipeData = recipeData;
    return craftingGadget;
}

@LeeTwentyThree
Copy link
Member

Ask and you shall receive an even harder decision, A THIRD OPTION!

public static CraftingGadget SetRecipe(this ICustomPrefab customPrefab, RecipeData recipeData)
{
    if (!customPrefab.TryGetGadget(out CraftingGadget craftingGadget))
        return customPrefab.AddGadget(new CraftingGadget(customPrefab, recipeData));
    craftingGadget.RecipeData = recipeData;
    return craftingGadget;
}

I prefer this

Copy link
Member

@LeeTwentyThree LeeTwentyThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that the code should be reformatted to fit this suggestion.

@LeeTwentyThree LeeTwentyThree merged commit 1a5adf0 into SubnauticaModding:master Jun 19, 2023
LeeTwentyThree added a commit to vlyon/Nautilus that referenced this pull request Jun 19, 2023
LeeTwentyThree added a commit that referenced this pull request Jun 19, 2023
* Improve PDA item sorting capabilities

* Prevented a breaking change.
Applied suggestions to improve docs.

* Added Enum for clarity of the insert position (sorting)

* Carry over changes introduced in PR #404

---------

Co-authored-by: LeeTwentyThree <[email protected]>
@vlyon vlyon deleted the better-fix-for-390 branch June 19, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants