Skip to content

Commit 785fc74

Browse files
authored
Merge pull request #5 from wlaub/feature/shroom_book_flags
add enable flag and read flag to shroom book interaction
2 parents d93dc9c + a3180e5 commit 785fc74

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

Ahorn/entities/shroomBookInteraction.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ using ..Ahorn, Maple
77
y::Integer,
88
width::Integer=Maple.defaultBlockWidth,
99
height::Integer=Maple.defaultBlockHeight,
10-
assetKey::String="shroompage"
10+
assetKey::String="shroompage",
11+
enableFlag::String="",
12+
readFlag::String=""
1113
)
1214

1315
const placements = Ahorn.PlacementDict(

Ahorn/lang/en_gb.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ placements.entities.ShroomHelper/RealityDistortionField.tooltips.rippleAreaMulti
1919

2020
# Shroom Book Interaction
2121
placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.assetKey=The image to display relative to Graphics/Atlases/Gui (do not include .png).
22+
placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.enableFlag=If specified, the entity will only load when the flag is True. Use ! prefix to invert.
23+
placements.entities.ShroomHelper/ShroomBookInteraction.tooltips.readFlag=A flag to set when the player finishes reading. Use ! prefix to clear.
2224

2325
# Shroom Dash Switch
2426
placements.entities.ShroomHelper/ShroomDashSwitch.tooltips.side=The direction the switch is facing.

Code/Entities/ShroomBook.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ namespace Celeste.Mod.ShroomHelper.Entities {
77
public class ShroomBook : CutsceneEntity {
88
private readonly Player player;
99
private readonly string bookTextKey;
10+
private readonly string readFlag;
11+
private readonly bool readFlagInverted;
1012
private PoemPage poem;
1113

12-
public ShroomBook(Player player, string bookTextKey) {
14+
public ShroomBook(Player player, string bookTextKey, string readFlag = "", bool readFlagInverted = false) {
1315
this.player = player;
1416
this.bookTextKey = bookTextKey;
17+
this.readFlag = readFlag;
18+
this.readFlagInverted = readFlagInverted;
1519
}
1620

1721
// Used to activate a ShroomBook externally (e.g. for Lua Cutscenes)
@@ -30,8 +34,9 @@ public override void OnBegin(Level level) {
3034
public override void OnEnd(Level level) {
3135
player.StateMachine.Locked = false;
3236
player.StateMachine.State = Player.StNormal;
33-
if (poem != null) {
34-
poem.RemoveSelf();
37+
poem?.RemoveSelf();
38+
if (!string.IsNullOrWhiteSpace(readFlag)) {
39+
level.Session.SetFlag(readFlag, !readFlagInverted);
3540
}
3641
}
3742

@@ -143,4 +148,4 @@ public IEnumerator EaseOut() {
143148
}
144149
}
145150
}
146-
}
151+
}

Code/Entities/ShroomBookInteraction.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,32 @@
55
namespace Celeste.Mod.ShroomHelper.Entities {
66
[CustomEntity("ShroomHelper/ShroomBookInteraction")]
77
public class ShroomBookInteraction : Entity {
8-
public const string FlagPrefix = "it_";
98
public TalkComponent Talker;
109
public string assetKey;
10+
public string enableFlag;
11+
public string readFlag;
12+
public bool enableFlagInverted = false;
13+
public bool readFlagInverted = false;
1114

1215
public ShroomBookInteraction(EntityData data, Vector2 offset)
1316
: base(data.Position + offset) {
1417

1518
Collider = new Hitbox(data.Width, data.Height);
1619
assetKey = data.Attr("assetKey", "shroompage");
1720

21+
enableFlag = data.Attr("enableFlag", "");
22+
if (!string.IsNullOrWhiteSpace(enableFlag) && enableFlag[0] == '!') {
23+
enableFlagInverted = true;
24+
enableFlag = enableFlag.Substring(1);
25+
}
26+
27+
readFlag = data.Attr("readFlag", "");
28+
if (!string.IsNullOrWhiteSpace(readFlag) && readFlag[0] == '!') {
29+
readFlagInverted = true;
30+
readFlag = readFlag.Substring(1);
31+
}
32+
33+
1834
Vector2 drawAt = new(data.Width / 2, 0f);
1935
if (data.Nodes.Length != 0) {
2036
drawAt = data.Nodes[0] - data.Position;
@@ -24,8 +40,16 @@ public ShroomBookInteraction(EntityData data, Vector2 offset)
2440
Talker.PlayerMustBeFacing = false;
2541
}
2642

43+
public override void Awake(Scene scene) {
44+
if (string.IsNullOrWhiteSpace(enableFlag) || SceneAs<Level>().Session.GetFlag(enableFlag) != enableFlagInverted) {
45+
base.Awake(scene);
46+
} else {
47+
RemoveSelf();
48+
}
49+
}
50+
2751
public void OnTalk(Player player) {
28-
Scene.Add(new ShroomBook(player, assetKey));
52+
Scene.Add(new ShroomBook(player, assetKey, readFlag, readFlagInverted));
2953
}
3054
}
3155
}

Loenn/entities/shroom_book_interaction.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ shroom_book_interaction.placements = {
99
data = {
1010
width = 8,
1111
height = 8,
12-
assetKey = "shroompage"
12+
assetKey = "shroompage",
13+
enableFlag = "",
14+
readFlag = ""
1315
}
1416
}
1517

16-
return shroom_book_interaction
18+
return shroom_book_interaction

Loenn/lang/en_gb.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ entities.ShroomHelper/ShroomDashSwitch.attributes.description.windPatternOnColli
4646
# Shroom Book Interaction
4747
entities.ShroomHelper/ShroomBookInteraction.placements.name.shroom_book_interaction=Shroom Book Interaction
4848
entities.ShroomHelper/ShroomBookInteraction.attributes.description.assetKey=The image to display relative to Graphics/Atlases/Gui (do not include .png).
49+
entities.ShroomHelper/ShroomBookInteraction.attributes.description.enableFlag=If specified, the entity will only load when the flag is True. Use ! prefix to invert.
50+
entities.ShroomHelper/ShroomBookInteraction.attributes.description.readFlag=A flag to set when the player finishes reading. Use ! prefix to clear.
4951

5052
# Double Refill Booster
5153
entities.ShroomHelper/DoubleRefillBooster.placements.name.double_refill_booster=Double Refill Booster

0 commit comments

Comments
 (0)