diff --git a/Ahorn/entities/shroomBookInteraction.jl b/Ahorn/entities/shroomBookInteraction.jl index bc33f4c..41cb004 100644 --- a/Ahorn/entities/shroomBookInteraction.jl +++ b/Ahorn/entities/shroomBookInteraction.jl @@ -7,7 +7,9 @@ using ..Ahorn, Maple y::Integer, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight, - assetKey::String="shroompage" + assetKey::String="shroompage", + enableFlag::String="", + readFlag::String="" ) const placements = Ahorn.PlacementDict( diff --git a/Ahorn/lang/en_gb.lang b/Ahorn/lang/en_gb.lang index d5181c6..bf04e99 100644 --- a/Ahorn/lang/en_gb.lang +++ b/Ahorn/lang/en_gb.lang @@ -19,6 +19,8 @@ placements.entities.ShroomHelper/RealityDistortionField.tooltips.rippleAreaMulti # Shroom Book Interaction placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.assetKey=The image to display relative to Graphics/Atlases/Gui (do not include .png). +placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.enableFlag=If specified, the entity will only load when the flag is True. Use ! prefix to invert. +placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.readFlag=A flag to set when the player finishes reading. Use ! prefix to clear. # Shroom Dash Switch placements.entities.ShroomHelper/ShroomDashSwitch.tooltips.side=The direction the switch is facing. diff --git a/Code/Entities/ShroomBook.cs b/Code/Entities/ShroomBook.cs index c4d51b7..ffca806 100644 --- a/Code/Entities/ShroomBook.cs +++ b/Code/Entities/ShroomBook.cs @@ -7,11 +7,15 @@ namespace Celeste.Mod.ShroomHelper.Entities { public class ShroomBook : CutsceneEntity { private readonly Player player; private readonly string bookTextKey; + private readonly string readFlag; + private readonly bool readFlagInverted; private PoemPage poem; - public ShroomBook(Player player, string bookTextKey) { + public ShroomBook(Player player, string bookTextKey, string readFlag = "", bool readFlagInverted = false) { this.player = player; this.bookTextKey = bookTextKey; + this.readFlag = readFlag; + this.readFlagInverted = readFlagInverted; } public override void OnBegin(Level level) { @@ -21,8 +25,9 @@ public override void OnBegin(Level level) { public override void OnEnd(Level level) { player.StateMachine.Locked = false; player.StateMachine.State = Player.StNormal; - if (poem != null) { - poem.RemoveSelf(); + poem?.RemoveSelf(); + if (!string.IsNullOrWhiteSpace(readFlag)) { + level.Session.SetFlag(readFlag, !readFlagInverted); } } @@ -134,4 +139,4 @@ public IEnumerator EaseOut() { } } } -} \ No newline at end of file +} diff --git a/Code/Entities/ShroomBookInteraction.cs b/Code/Entities/ShroomBookInteraction.cs index cbe7734..5eb9644 100644 --- a/Code/Entities/ShroomBookInteraction.cs +++ b/Code/Entities/ShroomBookInteraction.cs @@ -5,9 +5,12 @@ namespace Celeste.Mod.ShroomHelper.Entities { [CustomEntity("ShroomHelper/ShroomBookInteraction")] public class ShroomBookInteraction : Entity { - public const string FlagPrefix = "it_"; public TalkComponent Talker; public string assetKey; + public string enableFlag; + public string readFlag; + public bool enableFlagInverted = false; + public bool readFlagInverted = false; public ShroomBookInteraction(EntityData data, Vector2 offset) : base(data.Position + offset) { @@ -15,6 +18,19 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Collider = new Hitbox(data.Width, data.Height); assetKey = data.Attr("assetKey", "shroompage"); + enableFlag = data.Attr("enableFlag", ""); + if (!string.IsNullOrWhiteSpace(enableFlag) && enableFlag[0] == '!') { + enableFlagInverted = true; + enableFlag = enableFlag.Substring(1); + } + + readFlag = data.Attr("readFlag", ""); + if (!string.IsNullOrWhiteSpace(readFlag) && readFlag[0] == '!') { + readFlagInverted = true; + readFlag = readFlag.Substring(1); + } + + Vector2 drawAt = new(data.Width / 2, 0f); if (data.Nodes.Length != 0) { drawAt = data.Nodes[0] - data.Position; @@ -24,8 +40,16 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Talker.PlayerMustBeFacing = false; } + public override void Awake(Scene scene) { + if (string.IsNullOrWhiteSpace(enableFlag) || SceneAs().Session.GetFlag(enableFlag) != enableFlagInverted) { + base.Awake(scene); + } else { + RemoveSelf(); + } + } + public void OnTalk(Player player) { - Scene.Add(new ShroomBook(player, assetKey)); + Scene.Add(new ShroomBook(player, assetKey, readFlag, readFlagInverted)); } } } diff --git a/Loenn/entities/shroom_book_interaction.lua b/Loenn/entities/shroom_book_interaction.lua index 91190f7..e7ff11f 100644 --- a/Loenn/entities/shroom_book_interaction.lua +++ b/Loenn/entities/shroom_book_interaction.lua @@ -9,8 +9,10 @@ shroom_book_interaction.placements = { data = { width = 8, height = 8, - assetKey = "shroompage" + assetKey = "shroompage", + enableFlag = "", + readFlag = "" } } -return shroom_book_interaction \ No newline at end of file +return shroom_book_interaction diff --git a/Loenn/lang/en_gb.lang b/Loenn/lang/en_gb.lang index 0d456f5..a4f189b 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -46,6 +46,8 @@ entities.ShroomHelper/ShroomDashSwitch.attributes.description.windPatternOnColli # Shroom Book Interaction entities.ShroomHelper/ShroomBookInteraction.placements.name.shroom_book_interaction=Shroom Book Interaction entities.ShroomHelper/ShroomBookInteraction.attributes.description.assetKey=The image to display relative to Graphics/Atlases/Gui (do not include .png). +entities.ShroomHelper/ShroomBookInteraction.attributes.description.enableFlag=If specified, the entity will only load when the flag is True. Use ! prefix to invert. +entities.ShroomHelper/ShroomBookInteraction.attributes.description.readFlag=A flag to set when the player finishes reading. Use ! prefix to clear. # Double Refill Booster entities.ShroomHelper/DoubleRefillBooster.placements.name.double_refill_booster=Double Refill Booster