Add state class, make Puzzle extend it - crossword.koplugin - Unnamed repository; edit this file 'description' to name the repository. (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules (DIR) README (DIR) LICENSE --- (DIR) commit 94971da672822b590acef09fd83c09d315e1bcc1 (DIR) parent 4a6e9447b35f096c688fbbbc0420cef8ccae2d46 (HTM) Author: Scarlett <social@scarlettmcallister.com> Date: Sun, 23 Jan 2022 17:12:58 -0400 Add state class, make Puzzle extend it Diffstat: M puzzle.lua | 4 ++-- A state.lua | 34 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) --- (DIR) diff --git a/puzzle.lua b/puzzle.lua @@ -1,8 +1,8 @@ local logger = require("logger") local Solve = require("solve") +local State = require("state") -local Puzzle = { - json_object = nil, +local Puzzle = State:new{ size = { cols = nil, rows = nil, (DIR) diff --git a/state.lua b/state.lua @@ -0,0 +1,34 @@ +local DataStorage = require("datastorage") +local LuaSettings = require("frontend/luasettings") +local logger = require("logger") + +local State = { + state_file = "crossword_states.lua", + lua_settings = nil, +} + +function State:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + o:init() + return o +end + +function State:init() + self.lua_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), self.state_file)) +end + +function State:load() + local state = self.lua_settings:child("puzzle_id") + for key, value in pairs(state.data) do + self[key] = value + end +end + +function State:save() + self.lua_settings:saveSetting("puzzle_id", self) + self.lua_settings:flush() +end + +return State