diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 17b84f4..4b85206 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -53,6 +53,8 @@ function Game:new() self.flags = {} self.destroyedGizmo = {} self.variables = {} + self.completion = 0 + self.mapName = "" self.version = "0.0.0" end @@ -88,6 +90,65 @@ function Game:getData() return data end +function Game:getMetadataFile(absolute) + local dir = "" + if absolute then + dir = love.filesystem.getSaveDirectory() .. "/" + if not love.filesystem.exists(dir) then + love.filesystem.createDirectory( "" ) + end + end + + local filepath = dir .. "metadata.save" + + return filepath +end + + +function Game:getMetadata() + local metadata = {} + local filepath = self:getMetadataFile(true) + if love.filesystem.exists("metadata.save") then + metadata = binser.readFile(filepath)[1] + else + metadata = self:newMetadata() + end + return metadata +end + +function Game:newMetadata() + local metadata = {} + for i = 1, self.slotNumber, 1 do + local newMetadata = {} + newMetadata.exist = false + newMetadata.completion = 0 + newMetadata.gametime = 0 + newMetadata.team = {} + newMetadata.rings = 0 + newMetadata.emeralds = 0 + newMetadata.location = "" + table.insert(metadata, newMetadata) + end + return metadata +end + +function Game:writeMetadata(metadata) + local filepath = self:getMetadataFile(true) + binser.writeFile(filepath, metadata) +end + +function Game:addtoMetadata() + local metadata = self:getMetadata() + metadata[self.slot].exist = true + metadata[self.slot].completion = self.completion + metadata[self.slot].gametime = self.gametime + metadata[self.slot].team = self.characters.team + metadata[self.slot].rings = self.loot.rings + metadata[self.slot].emeralds = 0 + metadata[self.slot].location = self.mapName + self:writeMetadata(metadata) +end + function Game:read(save_id) self.slot = save_id if (self.slot > 0) then @@ -96,17 +157,17 @@ function Game:read(save_id) local loadedDatas = binser.readFile(filepath) self:setData(loadedDatas[1]) - end end end -function Game:write(save_id) +function Game:write() if (self.slot > 0) then local data = self:getData() local filepath = self:getSaveFile(self.slot, true) binser.writeFile(filepath, data) + self:addtoMetadata() end end diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index d1f8631..431f797 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -72,6 +72,7 @@ function OverWorld:updateCurrentMap(map) self:playMapMusic(map) self:showMessage(map.name) + game.mapName = map.name end function OverWorld:playMapMusic(map)