Skip to content

Commit

Permalink
Add 'visible if flag' option to Secret Berry
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Nov 11, 2023
1 parent 26557cf commit b83c294
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Ahorn/entities/maxHelpingHandSecretBerry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ..Ahorn, Maple

@mapdef Entity "MaxHelpingHand/SecretBerry" SecretBerry(x::Integer, y::Integer,
checkpointID::Integer=-1, order::Integer=-1, strawberrySprite::String="strawberry", ghostberrySprite::String="ghostberry",
checkpointID::Integer=-1, order::Integer=-1, visibleIfFlag::String="", strawberrySprite::String="strawberry", ghostberrySprite::String="ghostberry",
strawberryPulseSound::String="event:/game/general/strawberry_pulse", strawberryBlueTouchSound::String="event:/game/general/strawberry_blue_touch",
strawberryTouchSound::String="event:/game/general/strawberry_touch", strawberryGetSound::String="event:/game/general/strawberry_get", countTowardsTotal::Bool=false,
pulseEnabled::Bool=true, particleColor1::String="FF8563", particleColor2::String="FFF4A8", ghostParticleColor1::String="6385FF", ghostParticleColor2::String="72F0FF")
Expand Down
1 change: 1 addition & 0 deletions Ahorn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ placements.entities.MaxHelpingHand/SecretBerry.tooltips.particleColor1=One of th
placements.entities.MaxHelpingHand/SecretBerry.tooltips.particleColor2=One of the colors to use for the particles the strawberry emits when not already collected.
placements.entities.MaxHelpingHand/SecretBerry.tooltips.ghostParticleColor1=One of the colors to use for the particles the strawberry emits when already collected.
placements.entities.MaxHelpingHand/SecretBerry.tooltips.ghostParticleColor2=One of the colors to use for the particles the strawberry emits when already collected.
placements.entities.MaxHelpingHand/SecretBerry.tooltips.visibleIfFlag=If filled out, the strawberry will only be visible (and collectable) when the given flag is set.\nThis will stop having an effect when the berry is grabbed by the player.
placements.entities.MaxHelpingHand/SecretBerry.names.strawberryPulseSound=Pulse Sound
placements.entities.MaxHelpingHand/SecretBerry.names.strawberryBlueTouchSound=Collected Touch Sound
placements.entities.MaxHelpingHand/SecretBerry.names.strawberryTouchSound=Uncollected Touch Sound
Expand Down
39 changes: 39 additions & 0 deletions Entities/SecretBerry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ private static void toggleStrawberryPulse(ILContext il) {
private readonly bool pulseEnabled;
private readonly ParticleType strawberryParticleType;
private readonly ParticleType strawberryGhostParticleType;
private readonly string visibleIfFlag;
private StrawberryToggler toggler;

public SecretBerry(EntityData data, Vector2 offset, EntityID gid) : base(data, offset, gid) {
strawberrySprite = data.Attr("strawberrySprite");
Expand All @@ -165,6 +167,7 @@ public SecretBerry(EntityData data, Vector2 offset, EntityID gid) : base(data, o
strawberryTouchSound = data.Attr("strawberryTouchSound");
strawberryGetSound = data.Attr("strawberryGetSound");
pulseEnabled = data.Bool("pulseEnabled", defaultValue: true);
visibleIfFlag = data.Attr("visibleIfFlag");

strawberryParticleType = new ParticleType(P_Glow) {
Color = Calc.HexToColor(data.Attr("particleColor1")),
Expand All @@ -175,5 +178,41 @@ public SecretBerry(EntityData data, Vector2 offset, EntityID gid) : base(data, o
Color2 = Calc.HexToColor(data.Attr("ghostParticleColor2")),
};
}

public override void Added(Scene scene) {
base.Added(scene);

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

// this is in a separate entity, because it can freeze the berry entirely...
// without freezing the process that unfreezes it when the flag is set.
private class StrawberryToggler : Entity {
private readonly SecretBerry berry;
private readonly string flag;

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

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

public override void Update() {
base.Update();

if (toggler != null && Follower.Leader != null) {
// once the berry has been grabbed, it should not be hidden anymore.
toggler.RemoveSelf();
toggler = null;
}
}
}
}
3 changes: 2 additions & 1 deletion Loenn/entities/secretBerry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ strawberry.placements = {
particleColor1 = "FF8563",
particleColor2 = "FFF4A8",
ghostParticleColor1 = "6385FF",
ghostParticleColor2 = "72F0FF"
ghostParticleColor2 = "72F0FF",
visibleIfFlag = ""
}
}

Expand Down
1 change: 1 addition & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ entities.MaxHelpingHand/SecretBerry.attributes.description.particleColor1=One of
entities.MaxHelpingHand/SecretBerry.attributes.description.particleColor2=One of the colors to use for the particles the strawberry emits when not already collected.
entities.MaxHelpingHand/SecretBerry.attributes.description.ghostParticleColor1=One of the colors to use for the particles the strawberry emits when already collected.
entities.MaxHelpingHand/SecretBerry.attributes.description.ghostParticleColor2=One of the colors to use for the particles the strawberry emits when already collected.
entities.MaxHelpingHand/SecretBerry.attributes.description.visibleIfFlag=If filled out, the strawberry will only be visible (and collectable) when the given flag is set.\nThis will stop having an effect when the berry is grabbed by the player.
entities.MaxHelpingHand/SecretBerry.attributes.name.strawberryPulseSound=Pulse Sound
entities.MaxHelpingHand/SecretBerry.attributes.name.strawberryBlueTouchSound=Collected Touch Sound
entities.MaxHelpingHand/SecretBerry.attributes.name.strawberryTouchSound=Uncollected Touch Sound
Expand Down
2 changes: 1 addition & 1 deletion everest.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The mod used to be known as "max480's Helping Hand", and wasn't renamed for compatibility reasons
- Name: MaxHelpingHand
Version: 1.28.3
Version: 1.28.4
DLL: bin/Release/net452/MaxHelpingHand.dll
Dependencies:
- Name: Everest
Expand Down

0 comments on commit b83c294

Please sign in to comment.