Here’s the whole thing:
local gameLib = {}; gameLib.getSaveValue = function(key) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; return gameLib.saveTable[key]; end gameLib.setSaveValue = function(key, value, operateSave) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; gameLib.saveTable[key] = value; if operateSave then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "w+"); local json = require "json"; file:write(json.encode(gameLib.saveTable)); io.close(file); end return gameLib.saveTable[key]; end gameLib.newSimpleButton = function(group, img, width, height) local button = display.newImageRect(group or display.getCurrentStage(), img, width, height); function button:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus(self); self.isFocus = true; if self.touchBegan then self:touchBegan(); end return true; elseif event.phase == "moved" and self.isFocus then local bounds = self.contentBounds; if event.x \> bounds.xMax or event.x \< bounds.xMin or event.y \> bounds.yMax or event.y \< bounds.yMin then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end end return true; elseif event.phase == "ended" and self.isFocus then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end return true; end end button:addEventListener("touch", button); return button; end gameLib.convertRGB = function(r, g, b) return {r/255, g/255, b/255}; end return gameLib;
Everything prior to line 12 is just commented out notes etc.