Skip to content

Commit

Permalink
Fixed saving shot spheres
Browse files Browse the repository at this point in the history
Actually implemented, because this was only a placeholder.
  • Loading branch information
jakubg1 committed Aug 17, 2021
1 parent f0fe816 commit a9804c6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/Map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function Map:update(dt)
for i, path in ipairs(self.paths.objects) do path:update(dt) end
end

function Map:getPathID(path)
for i, pathT in ipairs(self.paths.objects) do if pathT == path then return i end end
end



function Map:draw()
Expand Down
51 changes: 40 additions & 11 deletions src/ShotSphere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,36 @@ function ShotSphere:moveStep()
end
end

function ShotSphere:getHitSphereIDs()
if not self.hitSphere then
return nil
end

local s = self.hitSphere
local g = s.sphereGroup
local c = g.sphereChain
local p = c.path
local m = p.map

local sphereID = s.sphereID
local groupID = c:getSphereGroupID(g)
local chainID = p:getSphereChainID(c)
local pathID = m:getPathID(p)

return {
sphereID = sphereID,
groupID = groupID,
chainID = chainID,
pathID = pathID
}
end

function ShotSphere:destroy()
if self.delQueue then return end
self._list:destroy(self)
self.sphereEntity:destroy(false)
if self.sphereEntity then
self.sphereEntity:destroy(false)
end
self.delQueue = true
self.shooter:activate()
end
Expand Down Expand Up @@ -130,12 +156,7 @@ function ShotSphere:serialize()
color = self.color,
speed = self.speed,
steps = self.steps,
hitSphere = {
pathID = 1,
chainID = 2,
groupID = 1,
sphereID = 8
}, -- TODO: add an indexation function in Sphere.lua to resolve this problem
hitSphere = self:getHitSphereIDs(),
hitTime = self.hitTime
}
end
Expand All @@ -148,12 +169,20 @@ function ShotSphere:deserialize(t)

self.shooter = game.session.level.shooter

self.hitSphere = nil -- blah blah blah, see above
self.hitTime = t.hitTime

self.hitSphere = nil
self.sphereEntity = nil

if t.hitSphere then
self.hitSphere = {
sphereID = t.hitSphere.sphereID,
sphereGroup = game.session.level.map.paths.objects[t.hitSphere.pathID].sphereChains[t.hitSphere.chainID].sphereGroups[t.hitSphere.groupID]
}
else
self.sphereEntity = SphereEntity(self.pos, self.color)
self.sphereEntity.frame = Vec2(1)
end

self.sphereEntity = SphereEntity(self.pos, self.color)
self.hitTime = t.hitTime
end

return ShotSphere
4 changes: 3 additions & 1 deletion src/SphereGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,17 @@ function SphereGroup:deserialize(t)
self.offset = t.offset
self.speed = t.speed
self.spheres = {}
local offset = 0
for i, sphere in ipairs(t.spheres) do
local s = Sphere(self, sphere)
s.offset = (i - 1) * 32
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)
offset = offset + 32 * s.size
end
self.matchCheck = t.matchCheck
end
Expand Down

0 comments on commit a9804c6

Please sign in to comment.