Add visual state feedback to squares; Add char table for guesses - 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 67ae73de472448f6080d9fb639fc65df7f541395 (DIR) parent 7263f034e82b39b2c019e5c3280fe3380f5f049b (HTM) Author: Scarlett <social@scarlettmcallister.com> Date: Fri, 17 Dec 2021 11:11:46 -0400 Add visual state feedback to squares; Add char table for guesses Diffstat: M gridsquare.lua | 2 +- M main.lua | 19 ++++++++++++++----- M puzzle.lua | 35 ++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 14 deletions(-) --- (DIR) diff --git a/gridsquare.lua b/gridsquare.lua @@ -29,7 +29,7 @@ function GridSquare:init() self.dimen = Geom:new{w = self.width, h = self.height} -- Set up the right bg color, letter, etc. local bg_color = self.letter_value ~= "." and - Blitbuffer.COLOR_WHITE or + (self.state == "1" and Blitbuffer.COLOR_GRAY or Blitbuffer.COLOR_WHITE) or Blitbuffer.COLOR_BLACK self.letter_font_size = TextBoxWidget:getFontSizeToFitHeight(self.height, 1, 0.3) (DIR) diff --git a/main.lua b/main.lua @@ -18,6 +18,7 @@ local _ = require("gettext") local Solve = require("solve") local GridView = require("gridview") +local GridInput = require("gridinput") local Crossword = WidgetContainer:new{ name = "crossword", @@ -109,7 +110,7 @@ end function Crossword:initGameView() self.active_puzzle = self:loadPuzzle() - self.ActiveGridView = GridView:new{ + self.active_grid_view = GridView:new{ size = { cols = self.active_puzzle.size.cols, rows = self.active_puzzle.size.rows @@ -122,18 +123,26 @@ function Crossword:initGameView() -- Then update the grid (@todo: display touch feedback) and the clue in -- the active grid view. Then refresh this view. local clue = self.active_puzzle:getClueByPos(row_num, col_num, Solve.DOWN) + logger.dbg("main.lua -> on_tap_callback") if not clue then - return false + local keyboard = self.active_grid_view:showKeyboard(false) + self.active_puzzle:resetActiveSquare() + else + local keyboard = self.active_grid_view:showKeyboard(true) + self.active_puzzle:setActiveSquare(row_num, col_num) end - self.ActiveGridView:updateGrid(self.active_puzzle:getGrid(), clue) + self.active_grid_view:updateGrid(self.active_puzzle:getGrid(), clue) self:refreshGameView() + end, + add_chars_callback = function(chars) + self.active_puzzle:setLetterForGuess(chars, self.active_puzzle:getActiveSquare()) end } end function Crossword:refreshGameView() - UIManager:show(self.ActiveGridView) - self.ActiveGridView:render() + self.active_grid_view:render() + UIManager:show(self.active_grid_view) end return Crossword (DIR) diff --git a/puzzle.lua b/puzzle.lua @@ -27,6 +27,8 @@ function Puzzle:init(json_object) self.size = json_object.size -- Initialize the solves. self.solves = {} + -- Initialize the player's inputs. + self.guesses = {} -- Create the down and across solves. self:createSolves(json_object.clues.down, json_object.answers.down, Solve.DOWN, json_object.gridnums) self:createSolves(json_object.clues.across, json_object.answers.across, Solve.ACROSS, json_object.gridnums) @@ -64,6 +66,14 @@ function Puzzle:getGrid() local number = tonumber(grid_index) == tonumber(solve.grid_num) and solve.clue_num or "" + -- Check to see if the grid element should be set to active. + local state = tonumber(grid_index) == + (self.active_square_index and self.active_square_index or -1) and + "1" or + "" + local letter = self.guesses[grid_index] and + self.guesses[grid_index] or + "" -- Check to see if the squares contains an entry for the given -- grid index. Positions in the table are used to indicate the index. -- So, something at squares[4] is the 4th square in the puzzle view, and should @@ -72,19 +82,16 @@ function Puzzle:getGrid() -- Make the initial element and add it to the list. local grid_square = { solve_indices = {solve_index}, - letter = string.sub(solve.word, i, i), -- Get first character of word, - number = number + --letter = string.sub(solve.word, i, i), -- Get first character of word, } grid[grid_index] = grid_square else -- Since the square has been initialized, update the existing element. table.insert(grid[grid_index].solve_indices, solve_index) - -- Set the number if it is not null. This is necessary to account for the - -- fact that the first direction processed will have already initialized - -- all of the squares. - if number ~= "" then - grid[grid_index].number = number - end + -- Update the other attributes. + grid[grid_index].number = number + grid[grid_index].letter = letter + grid[grid_index].state = state end end end @@ -125,6 +132,14 @@ function Puzzle:setActiveSquare(row, col) self.active_square_index = ((row - 1) * self.size.rows) + col end +function Puzzle:getActiveSquare() + return self.active_square_index +end + +function Puzzle:resetActiveSquare() + self.active_square_index = -1 +end + function Puzzle:getSquareAtPos(row, col) local index = ((row - 1) * self.size.rows) + col return self.solves[index] @@ -134,6 +149,10 @@ function Puzzle:getSolveByIndex(index) return self.solves[index] end +function Puzzle:setLetterForGuess(letter, active_square) + self.guesses[active_square] = string.upper(letter) +end + function Puzzle:getClueByPos(row, col, direction) local clue local grid_elm = self.grid[row][col]