From e070dbebc143de9bbb21ebfbacb89cc5a2f8d0ff Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 13 Jun 2021 21:28:29 -0400 Subject: [PATCH] Fix undeclared NagView findindex() by moving it to common. --- data/core/commands/dialog.lua | 5 +++-- data/core/common.lua | 7 +++++++ data/core/nagview.lua | 8 +------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/data/core/commands/dialog.lua b/data/core/commands/dialog.lua index f6df69aa..90606abb 100644 --- a/data/core/commands/dialog.lua +++ b/data/core/commands/dialog.lua @@ -1,5 +1,6 @@ local core = require "core" local command = require "core.command" +local common = require "core.common" command.add("core.nagview", { ["dialog:previous-entry"] = function() @@ -15,13 +16,13 @@ command.add("core.nagview", { ["dialog:select-yes"] = function() local v = core.active_view if v ~= core.nag_view then return end - v:change_hovered(findindex(v.options, "default_yes")) + v:change_hovered(common.find_index(v.options, "default_yes")) command.perform "dialog:select" end, ["dialog:select-no"] = function() local v = core.active_view if v ~= core.nag_view then return end - v:change_hovered(findindex(v.options, "default_no")) + v:change_hovered(common.find_index(v.options, "default_no")) command.perform "dialog:select" end, ["dialog:select"] = function() diff --git a/data/core/common.lua b/data/core/common.lua index 155d4ddb..b7dd61db 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -22,6 +22,13 @@ function common.round(n) end +function common.find_index(tbl, prop) + for i, o in ipairs(tbl) do + if o[prop] then return i end + end +end + + function common.lerp(a, b, t) if type(a) ~= "table" then return a + (b - a) * t diff --git a/data/core/nagview.lua b/data/core/nagview.lua index 1f48d8d6..6d6f89f4 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -170,12 +170,6 @@ function NagView:draw() end end -local function findindex(tbl, prop) - for i, o in ipairs(tbl) do - if o[prop] then return i end - end -end - function NagView:get_message_height() local h = 0 for str in string.gmatch(self.message, "(.-)\n") do @@ -196,7 +190,7 @@ function NagView:next() -- self.target_height is the nagview height needed to display the message and -- the buttons, excluding the top and bottom padding space. self.target_height = math.max(message_height, self:get_buttons_height()) - self:change_hovered(findindex(self.options, "default_yes")) + self:change_hovered(common.find_index(self.options, "default_yes")) end self.force_focus = self.message ~= nil core.set_active_view(self.message ~= nil and self or core.last_active_view)