Skip to content

Commit

Permalink
(try to) fix existing double spawns
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed May 1, 2024
1 parent 617a44a commit e8eb71f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 3 deletions.
34 changes: 34 additions & 0 deletions SCHIZO/Items/Components/DestroyOnStoryGoal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SCHIZO.Helpers;
using Story;

namespace SCHIZO.Items.Components;
partial class DestroyOnStoryGoal : IStoryGoalListener
{
private string storyGoal;
public void Start()
{
storyGoal = RetargetHelpers.Pick(storyGoalSN, storyGoalBZ);
StoryGoalManager.main.AddListener(this);
UpdateActive();
}

private void OnDestroy()
{
StoryGoalManager.main.RemoveListener(this);
}

public void NotifyGoalComplete(string key) => UpdateActive(key);

public void NotifyGoalReset(string key) => UpdateActive(key);

public void NotifyGoalsDeserialized() => UpdateActive();

private void UpdateActive(string key = null)
{
if (key is { } && !StoryGoalHelpers.Matches(key, storyGoal))
return;

if (StoryGoalHelpers.IsCompleted(storyGoal))
Destroy(GetComponentInParent<PrefabIdentifier>().gameObject);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SCHIZO.Helpers;
using Story;

namespace SCHIZO.Creatures.Components;
namespace SCHIZO.Items.Components;
partial class DisableUntilStoryGoal : IStoryGoalListener
{
private string storyGoal;
Expand Down
7 changes: 7 additions & 0 deletions SCHIZO/Items/PDAJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Nautilus.Assets.Gadgets;
using Nautilus.Assets.PrefabTemplates;
using SCHIZO.Helpers;
using SCHIZO.Items.Components;

namespace SCHIZO.Items;

Expand Down Expand Up @@ -52,6 +53,12 @@ private PDAJournalPrefab(PDAJournal journal)
if (!string.IsNullOrEmpty(journal.pdaHandTargetSubtext))
handTarget.secondaryTooltip = journal.pdaHandTargetSubtext;
handTarget.goal.key = journal.key;

DestroyOnStoryGoal preventDupes = prefab.EnsureComponent<DestroyOnStoryGoal>();
preventDupes.storyGoalSN = preventDupes.storyGoalBZ = journal.key;

DestroyInCreativeMode storyOnly = prefab.EnsureComponent<DestroyInCreativeMode>();

prefab.SetActive(false);
}
});
Expand Down
13 changes: 13 additions & 0 deletions Unity/Assets/Scripts/SCHIZO/Items/Components/DestroyOnStoryGoal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using TriInspector;
using UnityEngine;

namespace SCHIZO.Items.Components
{
public sealed partial class DestroyOnStoryGoal : MonoBehaviour
{
[LabelText("Story Goal (SN)")]
public string storyGoalSN;
[LabelText("Story Goal (BZ)")]
public string storyGoalBZ;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using TriInspector;
using UnityEngine;

namespace SCHIZO.Creatures.Components
namespace SCHIZO.Items.Components
{
public sealed partial class DisableUntilStoryGoal : MonoBehaviour
{
Expand All @@ -10,4 +10,4 @@ public sealed partial class DisableUntilStoryGoal : MonoBehaviour
[LabelText("Story Goal (BZ)")]
public string storyGoalBZ;
}
}
}
9 changes: 9 additions & 0 deletions Unity/Assets/Scripts/Subnautica/DestroyDuplicates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SCHIZO.TriInspector.Attributes;
using TriInspector;
using UnityEngine;

[DeclareComponentReferencesGroup]
public class DestroyDuplicates : MonoBehaviour
{
[ComponentReferencesGroup, Required] public PrefabIdentifier identifier;
}
11 changes: 11 additions & 0 deletions Unity/Assets/Scripts/Subnautica/DestroyDuplicates.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8eb71f

Please sign in to comment.