Skip to content

Commit 382d55c

Browse files
committed
Expose the spriteDirectory attribute in non-return kevins in their Loenn plugin
1 parent d980810 commit 382d55c

2 files changed

Lines changed: 59 additions & 40 deletions

File tree

Loenn/entities/nonReturnKevin.lua

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local drawableNPatch = require("structs.drawable_nine_patch")
22
local drawableRectangle = require("structs.drawable_rectangle")
33
local drawableSprite = require("structs.drawable_sprite")
4+
local utils = require("utils")
45

56
local axisOptions = {
67
Both = "both",
@@ -12,11 +13,14 @@ local nonReturnKevin = {}
1213

1314
nonReturnKevin.name = "CherryHelper/NonReturnKevin"
1415
nonReturnKevin.depth = 0
15-
nonReturnKevin.minimumSize = {24, 24}
16+
nonReturnKevin.minimumSize = { 24, 24 }
1617
nonReturnKevin.fieldInformation = {
1718
axes = {
1819
options = axisOptions,
1920
editable = false
21+
},
22+
fillColor = {
23+
fieldType = "color",
2024
}
2125
}
2226
nonReturnKevin.placements = {}
@@ -47,70 +51,80 @@ for _, axis in pairs(axisOptions) do
4751
})
4852
end
4953

50-
local frameTextures = {
51-
none = "objects/crushblock/block00",
52-
horizontal = "objects/crushblock/block01",
53-
vertical = "objects/crushblock/block02",
54-
both = "objects/crushblock/block03"
55-
}
54+
for _, axis in pairs(axisOptions) do
55+
table.insert(nonReturnKevin.placements, {
56+
name = "reskinnable" .. axis,
57+
data = {
58+
width = 24,
59+
height = 24,
60+
axes = axis,
61+
altTexture = true,
62+
spriteDirectory = "objects/noReturnKevin",
63+
fillColor = "242262",
64+
chillout = false
65+
}
66+
})
67+
end
5668

57-
local altFrameTextures = {
58-
none = "objects/noReturnKevin/block00",
59-
horizontal = "objects/noReturnKevin/block01",
60-
vertical = "objects/noReturnKevin/block02",
61-
both = "objects/noReturnKevin/block03"
69+
local frameTextures = {
70+
none = "/block00",
71+
horizontal = "/block01",
72+
vertical = "/block02",
73+
both = "/block03"
6274
}
6375

6476
local nPatchOptions = {
6577
mode = "border",
6678
borderMode = "repeat"
6779
}
6880

69-
local kevinColor = {98 / 255, 34 / 255, 43 / 255}
70-
local smallFaceTexture = "objects/crushblock/idle_face"
71-
local giantFaceTexture = "objects/crushblock/giant_block00"
81+
local kevinColor = { 98 / 255, 34 / 255, 43 / 255 }
82+
local altKevinColor = { 36 / 255, 34 / 255, 98 / 255 }
83+
84+
local function isempty(s)
85+
return s == nil or s == ""
86+
end
7287

73-
local altKevinColor = {36 / 255, 34 / 255, 98 / 255}
74-
local altSmallFaceTexture = "objects/noReturnKevin/idle_face"
75-
local altGiantFaceTexture = "objects/noReturnKevin/giant_block00"
88+
local function getBlockStyle(entity)
89+
local entitySpriteDir = entity.altTexture
90+
and (isempty(entity.spriteDirectory) and "objects/noReturnKevin" or entity.spriteDirectory)
91+
or "objects/crushblock"
92+
local frameTexture = entitySpriteDir .. frameTextures[entity.axes or "both"]
93+
local smallFaceTexture = entitySpriteDir .. "/idle_face"
94+
local giantFaceTexture = entitySpriteDir .. "/giant_block00"
95+
local fillColor = entity.altTexture
96+
and (isempty(entity.fillColor) and altKevinColor or utils.getColor(entity.fillColor))
97+
or kevinColor
98+
99+
return {
100+
spriteDir = entitySpriteDir,
101+
frameTexture = frameTexture,
102+
smallFaceTexture = smallFaceTexture,
103+
giantFaceTexture = giantFaceTexture,
104+
fillColor = fillColor
105+
}
106+
end
76107

77108
function nonReturnKevin.sprite(room, entity)
78-
local altTexture = entity.altTexture or false
109+
local blockStyle = getBlockStyle(entity)
79110

80111
local x, y = entity.x or 0, entity.y or 0
81112
local width, height = entity.width or 24, entity.height or 24
82113

83-
local axes = entity.axes or "both"
84114
local chillout = entity.chillout
85-
86115
local giant = height >= 48 and width >= 48 and chillout
87116

88-
local faceTexture = giant and giantFaceTexture or smallFaceTexture
89-
if altTexture then
90-
faceTexture = giant and altGiantFaceTexture or altSmallFaceTexture
91-
end
92-
93-
local frameTexture = frameTextures[axes] or frameTextures["both"]
94-
if altTexture then
95-
frameTexture = altFrameTextures[axes] or altFrameTextures["both"]
96-
end
97-
98-
local ninePatch = drawableNPatch.fromTexture(frameTexture, nPatchOptions, x, y, width, height)
99-
100-
local rectangle = drawableRectangle.fromRectangle("fill", x + 2, y + 2, width - 4, height - 4, kevinColor)
101-
if altTexture then
102-
rectangle = drawableRectangle.fromRectangle("fill", x + 2, y + 2, width - 4, height - 4, altKevinColor)
103-
end
117+
local ninePatch = drawableNPatch.fromTexture(blockStyle.frameTexture, nPatchOptions, x, y, width, height)
118+
local rectangle = drawableRectangle.fromRectangle("fill", x + 2, y + 2, width - 4, height - 4, blockStyle.fillColor)
104119

120+
local faceTexture = giant and blockStyle.giantFaceTexture or blockStyle.smallFaceTexture
105121
local faceSprite = drawableSprite.fromTexture(faceTexture, entity)
106122
faceSprite:addPosition(math.floor(width / 2), math.floor(height / 2))
107123

108124
local sprites = ninePatch:getDrawableSprite()
109-
110125
table.insert(sprites, 1, rectangle:getDrawableSprite())
111126
table.insert(sprites, 2, faceSprite)
112-
113127
return sprites
114128
end
115129

116-
return nonReturnKevin
130+
return nonReturnKevin

Loenn/lang/en_gb.lang

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ entities.CherryHelper/NonReturnKevin.placements.name.horizontal=Non Return Kevin
1212
entities.CherryHelper/NonReturnKevin.placements.name.altboth=Non Return Kevin (Alt Texture) (Both)
1313
entities.CherryHelper/NonReturnKevin.placements.name.altvertical=Non Return Kevin (Alt Texture) (Vertical)
1414
entities.CherryHelper/NonReturnKevin.placements.name.althorizontal=Non Return Kevin (Alt Texture) (Horizontal)
15+
entities.CherryHelper/NonReturnKevin.placements.name.reskinnableboth=Non Return Kevin (Reskinnable) (Both)
16+
entities.CherryHelper/NonReturnKevin.placements.name.reskinnablevertical=Non Return Kevin (Reskinnable) (Vertical)
17+
entities.CherryHelper/NonReturnKevin.placements.name.reskinnablehorizontal=Non Return Kevin (Reskinnable) (Horizontal)
18+
entities.CherryHelper/NonReturnKevin.attributes.description.spriteDirectory=Directory custom sprites will be taken from. Custom sprites must be formatted in the same way as vanilla kevins. This option does nothing if the "Alt Texture" field is unchecked.
19+
entities.CherryHelper/NonReturnKevin.attributes.description.fillColor=Fill color of the kevin. This option does nothing if the "Alt Texture" field is unchecked.
1520

1621
entities.CherryHelper/UI_NRCB.placements.name.both=Uninterruptible Non Return Kevin (Both)
1722
entities.CherryHelper/UI_NRCB.placements.name.vertical=Uninterruptible Non Return Kevin (Vertical)

0 commit comments

Comments
 (0)