Skip to content

Commit

Permalink
Fix secret/customizable berry being hidden too late if flag is not ac…
Browse files Browse the repository at this point in the history
…tive
  • Loading branch information
maddie480 committed Dec 6, 2023
1 parent 5dd76e9 commit 47efdf8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Entities/SecretBerry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public SecretBerry(EntityData data, Vector2 offset, EntityID gid) : base(data, o
public override void Added(Scene scene) {
base.Added(scene);

if (!string.IsNullOrEmpty(visibleIfFlag)) {
scene.Add(toggler = new StrawberryToggler(this, visibleIfFlag));
if (!string.IsNullOrEmpty(visibleIfFlag) && scene is Level level) {
scene.Add(toggler = new StrawberryToggler(this, visibleIfFlag, level));
}
}

Expand All @@ -192,14 +192,20 @@ public override void Added(Scene scene) {
private class StrawberryToggler : Entity {
private readonly SecretBerry berry;
private readonly string flag;
private readonly Level level;

public StrawberryToggler(SecretBerry berry, string flag) {
public StrawberryToggler(SecretBerry berry, string flag, Level level) {
this.berry = berry;
this.flag = flag;
this.level = level;

// update right away, to make sure the berry disappears if it needs to
// without waiting for the first update (which is very noticeable during transitions).
Update();
}

public override void Update() {
bool isVisible = SceneAs<Level>().Session.GetFlag(flag);
bool isVisible = level.Session.GetFlag(flag);
berry.Active = berry.Visible = berry.Collidable = isVisible;
berry.Get<BloomPoint>().Visible = isVisible;
}
Expand Down

0 comments on commit 47efdf8

Please sign in to comment.