Skip to content

Commit d83021f

Browse files
authored
Merge pull request #39 from aonkeeper4/respritable-lillies
Make Lillies respritable and recolorable
2 parents d607611 + 143da1a commit d83021f

3 files changed

Lines changed: 135 additions & 37 deletions

File tree

Code/Entities/Lilly.cs

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public void UpdateArm(float move)
5454
public const float ArmSpeed = 240;
5555
public const float ArmSpeedRetract = 112;
5656

57-
public static readonly Color IdleColor = Calc.HexToColor("0061ff");
58-
public static readonly Color ClimbedOnColor = Calc.HexToColor("ff38f1");
59-
public static readonly Color DashColor = Calc.HexToColor("ff0033");
60-
public static readonly Color RetractColor = Calc.HexToColor("4800ff");
61-
public static readonly Color IdleAltColor = Calc.HexToColor("00d0ff");
62-
public static readonly Color ClimbedOnAltColor = Calc.HexToColor("f432ff");
63-
public static readonly Color HorrifiedColor = Calc.HexToColor("bc51ff");
64-
65-
private Color colorTo = IdleColor, colorFrom = IdleColor;
57+
private readonly Color idleColor = Calc.HexToColor("0061ff");
58+
private readonly Color climbedOnColor = Calc.HexToColor("ff38f1");
59+
private readonly Color dashColor = Calc.HexToColor("ff0033");
60+
private readonly Color retractColor = Calc.HexToColor("4800ff");
61+
private readonly Color idleAltColor = Calc.HexToColor("00d0ff");
62+
private readonly Color climbedOnAltColor = Calc.HexToColor("f432ff");
63+
private readonly Color horrifiedColor = Calc.HexToColor("bc51ff");
64+
65+
private Color colorTo = Calc.HexToColor("0061ff"), colorFrom = Calc.HexToColor("0061ff"); // IdleColor
6666
private float colorLerp = 1f;
6767

6868
public enum FaceState
@@ -108,13 +108,17 @@ public enum FaceState
108108
private readonly List<StaticMover> rightStaticMovers = new();
109109

110110
public Lilly(EntityData data, Vector2 offset)
111-
: this(data.Position + offset, data.Height, data.Int("maxLength")) { }
111+
: this(data.Position + offset, data.Height, data.Int("maxLength"), data.Attr("spriteDir", "").Trim().TrimEnd('/'),
112+
data.HexColor("idleColor", Calc.HexToColor("0061ff")), data.HexColor("climbedOnColor", Calc.HexToColor("ff38f1")), data.HexColor("dashColor", Calc.HexToColor("ff0033")), data.HexColor("retractColor", Calc.HexToColor("4800ff")),
113+
data.HexColor("idleAltColor", Calc.HexToColor("00d0ff")), data.HexColor("climbedOnAltColor", Calc.HexToColor("f432ff")), data.HexColor("horrifiedColor", Calc.HexToColor("bc51ff")))
114+
{ }
112115

113-
public Lilly(Vector2 position, int height, int maxLength)
116+
public Lilly(Vector2 position, int height, int maxLength, string spriteDir,
117+
Color idleColor, Color climbedOnColor, Color dashColor, Color retractColor, Color idleAltColor, Color climbedOnAltColor, Color horrifiedColor)
114118
: base(position, 24, height, true)
115119
{
116120
this.SurfaceSoundIndex = SurfaceIndex.CassetteBlock;
117-
this.arm = GFX.Game.GetAtlasSubtextures("objects/VortexHelper/squareBumperNew/arm");
121+
this.arm = GFX.Game.GetAtlasSubtextures(string.IsNullOrEmpty(spriteDir) ? "objects/VortexHelper/squareBumperNew/arm" : spriteDir + "/arm");
118122

119123
this.maxLength = Math.Abs(maxLength);
120124

@@ -125,11 +129,22 @@ public Lilly(Vector2 position, int height, int maxLength)
125129
Position = middle
126130
});
127131

128-
this.face = VortexHelperModule.LillySpriteBank.Create("lillyFace");
132+
this.idleColor = idleColor;
133+
this.climbedOnColor = climbedOnColor;
134+
this.dashColor = dashColor;
135+
this.retractColor = retractColor;
136+
this.idleAltColor = idleAltColor;
137+
this.climbedOnAltColor = climbedOnAltColor;
138+
this.horrifiedColor = horrifiedColor;
139+
this.colorFrom = this.colorTo = this.idleColor;
140+
141+
this.face = string.IsNullOrEmpty(spriteDir) ? VortexHelperModule.LillySpriteBank.Create("lillyFace") : BuildCustomFaceSprite(spriteDir);
129142
this.face.Position = middle + Vector2.UnitY;
130-
this.face.Color = IdleColor;
143+
this.face.Color = this.idleColor;
131144
Add(this.face);
132145

146+
if (!string.IsNullOrEmpty(spriteDir)) InitializeTextures(spriteDir);
147+
133148
this.OnDashCollide = OnDashed;
134149

135150
Add(this.bloom = new BloomPoint(.65f, 16f)
@@ -139,6 +154,40 @@ public Lilly(Vector2 position, int height, int maxLength)
139154
});
140155
}
141156

157+
private static Sprite BuildCustomFaceSprite(string path)
158+
{
159+
Sprite faceSprite = new Sprite(GFX.Game, path + "/");
160+
161+
// <Loop id="idle" path="face" frames="0"/>
162+
faceSprite.AddLoop("idle", "face", 0f, 0);
163+
// <Anim id="idle_climb" path="face" frames="1-3" delay="0.08"/>
164+
faceSprite.Add("idle_climb", "face", 0.08f, 1, 2, 3);
165+
// <Anim id="climb_idle" path="face" frames="2,1,0" delay="0.08" goto="idle"/>
166+
faceSprite.Add("climb_idle", "face", 0.08f, "idle", 2, 1, 0);
167+
168+
// <Anim id="dashed" path="face" frames="4" delay="0.5" goto="dash"/>
169+
faceSprite.Add("dashed", "face", 0.5f, "dash", 4);
170+
// <Loop id="dash" path="face" frames="5,6" delay="0.08"/>
171+
faceSprite.AddLoop("dash", "face", 0.08f, 5, 6);
172+
173+
// <Anim id="retract" path="face" frames="7-9" delay="0.08"/>
174+
faceSprite.Add("retract", "face", 0.08f, 7, 8, 9);
175+
// <Anim id="end_retract" path="face" frames="10-12" delay="0.08" goto="idle_alt"/>
176+
faceSprite.Add("end_retract", "face", 0.08f, "idle_alt", 10, 11, 12);
177+
178+
// <Loop id="idle_alt" path="face" frames="12" delay="0.08"/>
179+
faceSprite.AddLoop("idle_alt", "face", 0.08f, 12);
180+
// <Loop id="climb_alt" path="face" frames="13" delay="0.08"/>
181+
faceSprite.AddLoop("climb_alt", "face", 0.08f, 13);
182+
183+
// <Anim id="horrified" path="face" frames="14,15,16,15,16,15,16,15,16,15,16,15,16,17,18,0" delay="0.06"/>
184+
faceSprite.Add("horrified", "face", 0.06f, 14, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 17, 18, 0);
185+
186+
faceSprite.JustifyOrigin(0.5f, 0.5f);
187+
faceSprite.Play("idle");
188+
return faceSprite;
189+
}
190+
142191
private DashCollisionResults OnDashed(Player player, Vector2 dir)
143192
{
144193
if (this.Activated)
@@ -154,7 +203,7 @@ private IEnumerator DashedSequence()
154203
// Dashed in, shaking.
155204
this.faceState = FaceState.Dash;
156205
this.face.Play("dashed", true);
157-
ChangeColor(DashColor);
206+
ChangeColor(dashColor);
158207
StartShaking(0.375f);
159208
Audio.Play(CustomSFX.game_lilly_dashed, this.Center);
160209
yield return 0.5f;
@@ -236,7 +285,7 @@ private IEnumerator DashedSequence()
236285
this.faceState = FaceState.Retract;
237286
this.face.Play("retract");
238287
this.sfx.Play(CustomSFX.game_lilly_conveyor, "end", 0f);
239-
ChangeColor(RetractColor);
288+
ChangeColor(retractColor);
240289

241290
float retractFactor = 0f;
242291
while (rightArmExtended || leftArmExtended)
@@ -293,7 +342,7 @@ private IEnumerator DashedSequence()
293342
this.sfx.Param("end", 1f);
294343
this.faceState = FaceState.IdleAlt;
295344
this.face.Play("end_retract");
296-
ChangeColor(IdleAltColor);
345+
ChangeColor(idleAltColor);
297346

298347
this.armsExtended = false;
299348
RemoveArms(rightArmEnd, rightArm);
@@ -333,7 +382,7 @@ private void UpdateFace()
333382
{
334383
this.faceState = FaceState.Horrified;
335384
this.face.Play("horrified");
336-
ChangeColor(HorrifiedColor);
385+
ChangeColor(horrifiedColor);
337386
}
338387

339388
if (this.Activated || this.faceState == FaceState.Horrified)
@@ -344,25 +393,25 @@ private void UpdateFace()
344393
{
345394
this.faceState = FaceState.ClimbedOn;
346395
this.face.Play("idle_climb");
347-
ChangeColor(ClimbedOnColor);
396+
ChangeColor(climbedOnColor);
348397
}
349398
else if (!ridden && this.faceState == FaceState.ClimbedOn)
350399
{
351400
this.faceState = FaceState.Idle;
352401
this.face.Play("climb_idle");
353-
ChangeColor(IdleColor);
402+
ChangeColor(idleColor);
354403
}
355404
else if (ridden && this.faceState == FaceState.IdleAlt)
356405
{
357406
this.faceState = FaceState.ClimbedOnAlt;
358407
this.face.Play("climb_alt");
359-
ChangeColor(ClimbedOnAltColor);
408+
ChangeColor(climbedOnAltColor);
360409
}
361410
else if (!ridden && this.faceState == FaceState.ClimbedOnAlt)
362411
{
363412
this.faceState = FaceState.IdleAlt;
364413
this.face.Play("idle_alt");
365-
ChangeColor(IdleAltColor);
414+
ChangeColor(idleAltColor);
366415
}
367416
}
368417

@@ -465,13 +514,13 @@ public override void Render()
465514
this.Position = pos;
466515
}
467516

468-
public static void InitializeTextures()
517+
public static void InitializeTextures(string path = "objects/VortexHelper/squareBumperNew")
469518
{
470-
MTexture block00 = GFX.Game["objects/VortexHelper/squareBumperNew/block00"];
471-
MTexture block01 = GFX.Game["objects/VortexHelper/squareBumperNew/block01"];
472-
MTexture active_block00 = GFX.Game["objects/VortexHelper/squareBumperNew/active_block00"];
473-
MTexture active_block01 = GFX.Game["objects/VortexHelper/squareBumperNew/active_block01"];
474-
MTexture armend = GFX.Game["objects/VortexHelper/squareBumperNew/armend"];
519+
MTexture block00 = GFX.Game[path + "/block00"];
520+
MTexture block01 = GFX.Game[path + "/block01"];
521+
MTexture active_block00 = GFX.Game[path + "/active_block00"];
522+
MTexture active_block01 = GFX.Game[path + "/active_block01"];
523+
MTexture armend = GFX.Game[path + "/armend"];
475524

476525
for (int j = 0; j < 4; j++)
477526
{

Loenn/entities/lilly.lua

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,42 @@ local drawableSprite = require "structs.drawable_sprite"
33
local lilly = {}
44

55
lilly.name = "VortexHelper/Lilly"
6-
lilly.minimumSize = {24, 24}
7-
lilly.canResize = {false, true}
6+
lilly.minimumSize = { 24, 24 }
7+
lilly.canResize = { false, true }
88

99
lilly.fieldInformation = {
1010
maxLength = {
1111
fieldType = "integer",
1212
minimumValue = 0
13-
}
13+
},
14+
idleColor = {
15+
fieldType = "color"
16+
},
17+
climbedOnColor = {
18+
fieldType = "color"
19+
},
20+
dashColor = {
21+
fieldType = "color"
22+
},
23+
retractColor = {
24+
fieldType = "color"
25+
},
26+
idleAltColor = {
27+
fieldType = "color"
28+
},
29+
climbedOnAltColor = {
30+
fieldType = "color"
31+
},
32+
horrifiedColor = {
33+
fieldType = "color"
34+
},
35+
}
36+
37+
lilly.fieldOrder = {
38+
"x", "y", "width", "height",
39+
"maxLength", "spritesDir",
40+
"idleColor", "climbedOnColor", "dashColor", "retractColor",
41+
"idleAltColor", "climbedOnAltColor", "horrifiedColor"
1442
}
1543

1644
lilly.placements = {
@@ -19,16 +47,34 @@ lilly.placements = {
1947
data = {
2048
width = 24,
2149
height = 24,
22-
maxLength = 64
50+
maxLength = 64,
51+
spriteDir = "",
52+
idleColor = "0061ff",
53+
climbedOnColor = "ff38f1",
54+
dashColor = "ff0033",
55+
retractColor = "4800ff",
56+
idleAltColor = "00d0ff",
57+
climbedOnAltColor = "f432ff",
58+
horrifiedColor = "bc51ff",
2359
}
2460
}
2561
}
2662

27-
local block = "objects/VortexHelper/squareBumperNew/block00"
28-
local face = "objects/VortexHelper/squareBumperNew/face12"
29-
local armend = "objects/VortexHelper/squareBumperNew/armend"
30-
local arm = "objects/VortexHelper/squareBumperNew/arm00"
31-
local color = {0.0, 208 / 255, 1.0, 1.0}
63+
local defaultSpriteDir = "objects/VortexHelper/squareBumperNew"
64+
65+
local block, face, armend, arm
66+
local color
67+
68+
local function reloadSprites(entity)
69+
local spriteDir = (entity.spriteDir ~= "" and entity.spriteDir) and entity.spriteDir or defaultSpriteDir
70+
71+
block = spriteDir .. "/block00"
72+
face = spriteDir .. "/face12"
73+
armend = spriteDir .. "/armend"
74+
arm = spriteDir .. "/arm00"
75+
76+
color = entity.idleColor or { 0.0, 208 / 255, 1.0, 1.0 }
77+
end
3278

3379
local function addBlockSprites(sprites, entity, h, armLength)
3480
for i = 0, h - 1 do
@@ -75,6 +121,7 @@ function lilly.sprite(room, entity)
75121
local tileHeight = math.floor(height / 8)
76122
local armLength = entity.maxLength or 64
77123

124+
reloadSprites(entity)
78125
local sprites = {}
79126

80127
x = 16 + armLength

Loenn/lang/en_gb.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ entities.VortexHelper/FloorBooster.attributes.description.notAttached=If ticked,
6262
# Lilly
6363
entities.VortexHelper/Lilly.placements.name.lilly=Lilly
6464
entities.VortexHelper/Lilly.attributes.description.maxLength=The maximum distance at which this Lilly's arms can extend.
65+
entities.VortexHelper/Lilly.attributes.description.spriteDir=Custom sprite path for this Lilly that leads to custom frames.\nThe frame count and image names must match the ones from the original skin.\nFor instance: face00.png, face01.png, face02.png, ..., arm00.png, arm01.png, etc.\nThe sprites must be located somewhere in the Gameplay atlas (somewhere in Graphics/Atlases/Gameplay/).\n\nExample: objects/myMap/myCustomLilly\n..should be valid if there exists files whose paths are Graphics/Atlases/Gameplay/objects/myMap/myCustomLilly/face00.png, etc.
66+
6567

6668
# Puffer Barrier
6769
entities.VortexHelper/PufferBarrier.placements.name.puffer_barrier=Puffer Barrier

0 commit comments

Comments
 (0)