From 6c6fd765f058857c888d861df6299a4bc55309dd Mon Sep 17 00:00:00 2001 From: wlaub Date: Sun, 15 Sep 2024 17:18:20 -0600 Subject: [PATCH 1/5] add enable flag and read flag to shroom book interaction --- Code/Entities/ShroomBook.cs | 11 ++++++-- Code/Entities/ShroomBookInteraction.cs | 32 +++++++++++++++++++++- Loenn/entities/shroom_book_interaction.lua | 6 ++-- Loenn/lang/en_gb.lang | 4 +++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Code/Entities/ShroomBook.cs b/Code/Entities/ShroomBook.cs index c4d51b7..3199656 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) { this.player = player; this.bookTextKey = bookTextKey; + this.readFlag = readFlag; + this.readFlagInverted = readFlagInverted; } public override void OnBegin(Level level) { @@ -24,6 +28,9 @@ public override void OnEnd(Level level) { if (poem != null) { poem.RemoveSelf(); } + if(readFlag != "") { + level.Session.SetFlag(readFlag, !readFlagInverted); + } } private IEnumerator Routine() { @@ -134,4 +141,4 @@ public IEnumerator EaseOut() { } } } -} \ No newline at end of file +} diff --git a/Code/Entities/ShroomBookInteraction.cs b/Code/Entities/ShroomBookInteraction.cs index cbe7734..c6bf200 100644 --- a/Code/Entities/ShroomBookInteraction.cs +++ b/Code/Entities/ShroomBookInteraction.cs @@ -8,6 +8,10 @@ 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 +19,21 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Collider = new Hitbox(data.Width, data.Height); assetKey = data.Attr("assetKey", "shroompage"); + enableFlag = data.Attr("enableFlag"); + if(enableFlag[0] == '!') + { + enableFlagInverted = true; + enableFlag = enableFlag[1..]; + } + + readFlag = data.Attr("readFlag"); + if(readFlag[0] == '!') + { + readFlagInverted = true; + readFlag = readFlag[1..]; + } + + Vector2 drawAt = new(data.Width / 2, 0f); if (data.Nodes.Length != 0) { drawAt = data.Nodes[0] - data.Position; @@ -24,8 +43,19 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Talker.PlayerMustBeFacing = false; } + public override void Awake(Scene scene) + { + + if(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..270a573 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -46,6 +46,10 @@ 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 From 3b79ea35a180767764e9ffcf7d9142a149ca3748 Mon Sep 17 00:00:00 2001 From: wlaub Date: Mon, 16 Sep 2024 11:09:42 -0600 Subject: [PATCH 2/5] missed a couple places for code style consistency --- Code/Entities/ShroomBookInteraction.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Code/Entities/ShroomBookInteraction.cs b/Code/Entities/ShroomBookInteraction.cs index c6bf200..7ed26f8 100644 --- a/Code/Entities/ShroomBookInteraction.cs +++ b/Code/Entities/ShroomBookInteraction.cs @@ -20,15 +20,13 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) assetKey = data.Attr("assetKey", "shroompage"); enableFlag = data.Attr("enableFlag"); - if(enableFlag[0] == '!') - { + if(enableFlag[0] == '!') { enableFlagInverted = true; enableFlag = enableFlag[1..]; } readFlag = data.Attr("readFlag"); - if(readFlag[0] == '!') - { + if(readFlag[0] == '!') { readFlagInverted = true; readFlag = readFlag[1..]; } @@ -43,8 +41,7 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Talker.PlayerMustBeFacing = false; } - public override void Awake(Scene scene) - { + public override void Awake(Scene scene) { if(enableFlag == "" || SceneAs().Session.GetFlag(enableFlag) != enableFlagInverted) { base.Awake(scene); From 34b562f67273840613ac480cf04d50f9012131a9 Mon Sep 17 00:00:00 2001 From: wlaub Date: Thu, 14 Nov 2024 17:42:39 -0700 Subject: [PATCH 3/5] add default values for flags and handle them more better --- Code/Entities/ShroomBookInteraction.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Entities/ShroomBookInteraction.cs b/Code/Entities/ShroomBookInteraction.cs index 7ed26f8..4e73205 100644 --- a/Code/Entities/ShroomBookInteraction.cs +++ b/Code/Entities/ShroomBookInteraction.cs @@ -19,14 +19,14 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) Collider = new Hitbox(data.Width, data.Height); assetKey = data.Attr("assetKey", "shroompage"); - enableFlag = data.Attr("enableFlag"); - if(enableFlag[0] == '!') { + enableFlag = data.Attr("enableFlag", ""); + if(enableFlag.Length > 1 && enableFlag[0] == '!') { enableFlagInverted = true; enableFlag = enableFlag[1..]; } - readFlag = data.Attr("readFlag"); - if(readFlag[0] == '!') { + readFlag = data.Attr("readFlag", ""); + if(readFlag.Length > 1 && readFlag[0] == '!') { readFlagInverted = true; readFlag = readFlag[1..]; } From a9fd559ea3ef1069dbeaf84ff09bbf7f8cd7fe8c Mon Sep 17 00:00:00 2001 From: bigkahuna443 <13278973+bigkahuna443@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:26:02 -0500 Subject: [PATCH 4/5] Added Ahorn plugin changes Not sure if we really need to do this anymore, but if we have both sets of plugins then might as well --- Ahorn/entities/shroomBookInteraction.jl | 4 +++- Ahorn/lang/en_gb.lang | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) 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. From a3180e5c11a01eaa709a4003883017cc81c9cf3d Mon Sep 17 00:00:00 2001 From: bigkahuna443 <13278973+bigkahuna443@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:26:53 -0500 Subject: [PATCH 5/5] Clean-up Whitespace cleanup + remove unused field + check for empty flags more robustly. Also add some defaults to parameters so we don't break our Open function --- Code/Entities/ShroomBook.cs | 8 +++----- Code/Entities/ShroomBookInteraction.cs | 15 ++++++--------- Loenn/lang/en_gb.lang | 2 -- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Code/Entities/ShroomBook.cs b/Code/Entities/ShroomBook.cs index 3199656..ffca806 100644 --- a/Code/Entities/ShroomBook.cs +++ b/Code/Entities/ShroomBook.cs @@ -11,7 +11,7 @@ public class ShroomBook : CutsceneEntity { private readonly bool readFlagInverted; private PoemPage poem; - public ShroomBook(Player player, string bookTextKey, string readFlag, bool readFlagInverted) { + public ShroomBook(Player player, string bookTextKey, string readFlag = "", bool readFlagInverted = false) { this.player = player; this.bookTextKey = bookTextKey; this.readFlag = readFlag; @@ -25,10 +25,8 @@ 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(); - } - if(readFlag != "") { + poem?.RemoveSelf(); + if (!string.IsNullOrWhiteSpace(readFlag)) { level.Session.SetFlag(readFlag, !readFlagInverted); } } diff --git a/Code/Entities/ShroomBookInteraction.cs b/Code/Entities/ShroomBookInteraction.cs index 4e73205..5eb9644 100644 --- a/Code/Entities/ShroomBookInteraction.cs +++ b/Code/Entities/ShroomBookInteraction.cs @@ -5,7 +5,6 @@ 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; @@ -20,15 +19,15 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) assetKey = data.Attr("assetKey", "shroompage"); enableFlag = data.Attr("enableFlag", ""); - if(enableFlag.Length > 1 && enableFlag[0] == '!') { + if (!string.IsNullOrWhiteSpace(enableFlag) && enableFlag[0] == '!') { enableFlagInverted = true; - enableFlag = enableFlag[1..]; + enableFlag = enableFlag.Substring(1); } readFlag = data.Attr("readFlag", ""); - if(readFlag.Length > 1 && readFlag[0] == '!') { + if (!string.IsNullOrWhiteSpace(readFlag) && readFlag[0] == '!') { readFlagInverted = true; - readFlag = readFlag[1..]; + readFlag = readFlag.Substring(1); } @@ -42,11 +41,9 @@ public ShroomBookInteraction(EntityData data, Vector2 offset) } public override void Awake(Scene scene) { - - if(enableFlag == "" || SceneAs().Session.GetFlag(enableFlag) != enableFlagInverted) { + if (string.IsNullOrWhiteSpace(enableFlag) || SceneAs().Session.GetFlag(enableFlag) != enableFlagInverted) { base.Awake(scene); - } - else { + } else { RemoveSelf(); } } diff --git a/Loenn/lang/en_gb.lang b/Loenn/lang/en_gb.lang index 270a573..a4f189b 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -49,8 +49,6 @@ entities.ShroomHelper/ShroomBookInteraction.attributes.description.assetKey=The 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