Skip to content

Commit c14d860

Browse files
authored
Merge pull request #188 from EverestAPI/static_puffer
Static Puffer
2 parents 231ba38 + 870c753 commit c14d860

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

Ahorn/entities/staticPuffer.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module SpringCollab2020StaticPuffer
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/StaticPuffer" StaticPuffer(x::Integer, y::Integer, right::Bool=false)
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Static Puffer (Right) (Spring Collab 2020)" => Ahorn.EntityPlacement(
9+
StaticPuffer,
10+
"point",
11+
Dict{String, Any}(
12+
"right" => true
13+
)
14+
),
15+
"Static Puffer (Left) (Spring Collab 2020)" => Ahorn.EntityPlacement(
16+
StaticPuffer,
17+
"point",
18+
Dict{String, Any}(
19+
"right" => false
20+
)
21+
)
22+
)
23+
24+
sprite = "objects/puffer/idle00"
25+
26+
function Ahorn.selection(entity::StaticPuffer)
27+
x, y = Ahorn.position(entity)
28+
scaleX = get(entity, "right", false) ? 1 : -1
29+
30+
return Ahorn.getSpriteRectangle(sprite, x, y, sx=scaleX)
31+
end
32+
33+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::StaticPuffer, room::Maple.Room)
34+
scaleX = get(entity, "right", false) ? 1 : -1
35+
36+
Ahorn.drawSprite(ctx, sprite, 0, 0, sx=scaleX)
37+
end
38+
39+
end

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,6 @@ placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.activa
312312
# Foreground Reflection Tentacles
313313
placements.entities.SpringCollab2020/ForegroundReflectionTentacles.tooltips.slide_until=Changes how far tentacles fall back when Madeline comes into fear distance.
314314
placements.entities.SpringCollab2020/ForegroundReflectionTentacles.tooltips.fear_distance=Determines the distance Madeline has to be at for the tentacles to fall back.
315+
316+
# Static Puffer
317+
placements.entities.SpringCollab2020/StaticPuffer.tooltips.right=The initial direction of the puffer.

Entities/StaticPuffer.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Celeste.Mod.Entities;
2+
using Monocle;
3+
using Microsoft.Xna.Framework;
4+
using MonoMod.Cil;
5+
using System;
6+
using Mono.Cecil.Cil;
7+
using System.Reflection;
8+
9+
namespace Celeste.Mod.SpringCollab2020.Entities {
10+
[CustomEntity("SpringCollab2020/StaticPuffer")]
11+
class StaticPuffer : Puffer {
12+
public static void Load() {
13+
IL.Celeste.Puffer.ctor_Vector2_bool += onPufferConstructor;
14+
}
15+
16+
public static void Unload() {
17+
IL.Celeste.Puffer.ctor_Vector2_bool -= onPufferConstructor;
18+
}
19+
20+
private static void onPufferConstructor(ILContext il) {
21+
ILCursor cursor = new ILCursor(il);
22+
23+
while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchCallvirt<SineWave>("Randomize"))) {
24+
Logger.Log("SpringCollab2020/StaticPuffer", $"Injecting call to unrandomize puffer sine wave at {cursor.Index} in IL for Puffer constructor");
25+
26+
cursor.Emit(OpCodes.Ldarg_0);
27+
cursor.Emit(OpCodes.Ldarg_0);
28+
cursor.Emit(OpCodes.Ldfld, typeof(Puffer).GetField("idleSine", BindingFlags.NonPublic | BindingFlags.Instance));
29+
cursor.EmitDelegate<Action<Puffer, SineWave>>((self, idleSine) => {
30+
if (self is StaticPuffer) {
31+
// unrandomize the initial pufferfish position.
32+
idleSine.Reset();
33+
}
34+
});
35+
}
36+
}
37+
38+
public StaticPuffer(EntityData data, Vector2 offset) : base(data, offset) {
39+
// remove the sine wave component so that it isn't updated.
40+
Get<SineWave>()?.RemoveSelf();
41+
}
42+
}
43+
}

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public override void Load() {
3737
CameraCatchupSpeedTrigger.Load();
3838
ColorGradeFadeTrigger.Load();
3939
SpeedBasedMusicParamTrigger.Load();
40+
StaticPuffer.Load();
4041
Everest.Events.Level.OnLoadBackdrop += onLoadBackdrop;
4142

4243
DecalRegistry.AddPropertyHandler("scale", (decal, attrs) => {
@@ -79,6 +80,7 @@ public override void Unload() {
7980
CameraCatchupSpeedTrigger.Unload();
8081
ColorGradeFadeTrigger.Unload();
8182
SpeedBasedMusicParamTrigger.Unload();
83+
StaticPuffer.Unload();
8284
Everest.Events.Level.OnLoadBackdrop -= onLoadBackdrop;
8385
}
8486

0 commit comments

Comments
 (0)