Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Fix Powerups not saving for spheres
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamblesSM committed Feb 18, 2023
1 parent b594c68 commit 3fc1dd6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Sphere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ function Sphere:new(sphereGroup, deserializationTable, color, shootOrigin, shoot
self.prevSphere = nil
self.nextSphere = nil
self.offset = 0
-- Temporary value.
-- In the future this should be customizable per-level, and in case of ZBR
-- this shall be linked to a Power/Food.
self.powerupTimeout = 20

if deserializationTable then
Expand Down Expand Up @@ -200,14 +197,17 @@ end

---Adds a powerup to the current Sphere.
---@param powerup string
function Sphere:addPowerup(powerup)
---@param noSound boolean?
function Sphere:addPowerup(powerup, noSound)
if not powerup then
_Log:printt("Sphere", "No powerup defined when calling Sphere:addPowerup()")
return
end
if not (self:isGhost() or self:isOffscreen()) then
self.powerup = powerup
_Game:playSound("sound_events/spawn_powerup_"..self.powerup..".json")
if not noSound then
_Game:playSound("sound_events/spawn_powerup_"..self.powerup..".json")
end
self.entity:setPowerup(powerup)
end
end
Expand Down Expand Up @@ -668,7 +668,9 @@ end
---@return table
function Sphere:serialize()
local t = {
color = self.color,
color = self.color,
powerup = self.powerup,
powerupTimeout = self.powerupTimeout,
--animationFrame = self.animationFrame, -- who cares about that, you can uncomment this if you do
shootOrigin = self.shootOrigin and {x = self.shootOrigin.x, y = self.shootOrigin.y} or nil,
shootTime = self.shootTime,
Expand Down Expand Up @@ -715,7 +717,8 @@ function Sphere:deserialize(t)
self.shootOrigin = t.shootOrigin and Vec2(t.shootOrigin.x, t.shootOrigin.y) or nil
self.shootTime = t.shootTime
self.ghostTime = t.ghostTime
self.powerup = t.currentPowerup
self.powerup = t.powerup
self.powerupTimeout = t.powerupTimeout

self.effects = {}
if t.effects then
Expand Down
1 change: 1 addition & 0 deletions src/SphereEntity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ end


---Sets the current powerup to be displayed on this Sphere Entity.
---DO NOT CALL THIS OUTSIDE `Sphere.lua` - call `Sphere:addPowerup()` instead.
---@param powerup? string The powerup to be displayed, or `nil` if none.
function SphereEntity:setPowerup(powerup)
self.powerup = powerup
Expand Down
9 changes: 8 additions & 1 deletion src/SphereGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,21 @@ function SphereGroup:deserialize(t)
self.spheres = {}
local offset = 0
for i, sphere in ipairs(t.spheres) do
---@type Sphere
local s = Sphere(self, sphere)
s.offset = offset
-- links are mandatory!!!
if i > 1 then
s.prevSphere = self.spheres[i - 1]
self.spheres[i - 1].nextSphere = s
end
table.insert(self.spheres, s)
table.insert(self.spheres, s)
if sphere.powerup then
s:addPowerup(sphere.powerup, true)
-- idk why it's nil by default when it's always defined as 20
-- until a powerup is given
s.powerupTimeout = sphere.powerupTimeout or 0
end
offset = offset + 29 * s.size
end
self.matchCheck = t.matchCheck
Expand Down

0 comments on commit 3fc1dd6

Please sign in to comment.