Skip to content

Conversation

@grimmier378
Copy link
Contributor

Convert version 7 of ButtonMaster.lua settings to SQL DB.

Still saves to the ButtonMaster.lua file for backup purposes but will load from the DB if present

@grimmier378
Copy link
Contributor Author

forgot i was also playing with the zep editor, commented that all out and re-enabled the multiline editor.


if renderButton[key] ~= nil then
local tColors = ButtonUtils.split(renderButton[key], ",")
for i, v in ipairs(tColors) do btnColor[i] = tonumber(v / 255) end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just do
(tonumber(v) or 0) / 255 ?

self.Open, self.Draw = ImGui.Begin('Icon Picker', self.Open, ImGuiWindowFlags.None)
if self.Draw then
self.Page = ImGui.InputInt("Page", self.Page, 1)
self.Page = ImGui.SliderInt("Page", self.Page,1, 26)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a tab list - i really don't like the input int or the slider its really non-obvious that you can move to different pages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea

flags = bit32.bor(flags, ImGuiWindowFlags.NoScrollbar)
if BMHotbars ~= nil then
for hotbarId, bmHotbar in ipairs(BMHotbars) do
if BMSettings:GetCharacterWindow(hotbarId) ~= nil then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should reduce this to a single lookup

local charWindowSettings = BMSettings:GetCharacterWindow(hotbarId)

etc...

end

CopyLocalSet(key)
-- CopyLocalSet(key)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.


-- Save and update the settings in the database
BMSettings:SaveSettings(true)
BMSettings:updateCharacterDB(BMSettings.CharConfig, BMSettings:GetCharConfig())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convert this to CamelCase to match the rest of the code?

end
end

-- function CopyLocalSet(key)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.

BMSettings:GetCharacterWindow(self.id).HideTitleBar = not BMSettings:GetCharacterWindow(self.id)
.HideTitleBar
BMSettings:SaveSettings(true)
BMSettings:updateCharacterDB(BMSettings.CharConfig, BMSettings:GetCharConfig())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesnt SaveSettings do updateCharacterDB?

for _, value in ipairs(charList) do
if ImGui.MenuItem(value.displayName) then
CopyLocalSet(value.key)
-- CopyLocalSet(value.key)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.

Also is there a reason this was moved to the other coroutine? I am not against it but just curious why this was done.

ImGui.PushFont(ImGui.ConsoleFont)
renderButton.Cmd, textChanged = ImGui.InputTextMultiline("##_Cmd_Edit", renderButton.Cmd or "",
ImVec2(ImGui.GetWindowWidth() * 0.98, editHeight), ImGuiInputTextFlags.AllowTabInput)
-- self.textEditor:Render(ImVec2(ImGui.GetWindowWidth() * 0.98, editHeight))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.

-- color pickers
colorChanged = btnUtils.RenderColorPicker(string.format("##ButtonColorPicker1_%s", renderButton.Label), 'Button',
renderButton,
colorChanged = btnUtils.RenderColorPicker(string.format("##ButtonColorPicker1_%s", renderButton.Label), 'Button', renderButton,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem like non-changes polluting the PR. Can you get rid of them please?


function BMButtonEditor:CloseEditPopup()
picker:SetClosed()
-- self.textEditor:Clear()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.

BMSettings:GetSettings().Buttons[ButtonKey].Unassigned = nil -- clear the unassigned flag

BMSettings:SaveSettings(true)
BMSettings:updateButtonDB(btnUtils.shallowcopy(self.tmpButton), ButtonKey)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant all the DB updates be handle from SaveSettings? How do you know when to call updatebutton/updateset/etc? That should ideally be abstracted away as much as possible.

BMButtonEditor.selectedTimerType = 1
BMButtonEditor.selectedUpdateRate = 1

-- ---@diagnostic disable-next-line:undefined-field
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add comments back into the branch.

local iconId = Button.Icon
local iconType = Button.IconType
local iconId = Button.Icon or -1
local iconType = Button.IconType or ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change existing behavior (nil iconType means something) so please make sure this doesn't break existing stuff.

local renderIconAnim = animItems
if iconType == nil or iconType == "Spell" then

if iconType == "Spell" then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely broken as nil is a valid case. which will now be either nil or '' with your changes...

animSpellIcons:SetTextureCell(tonumber(iconId) or 0)
renderIconAnim = animSpellIcons
else
elseif iconType == "Item" then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do if iconType == "Item" else ... assume spell

local settings_path = settings_base .. '.lua '
local mq = require('mq')
local btnUtils = require('lib.buttonUtils')
local PackageMan = require('mq.PackageMan')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break only init.lua can invoke packageman - you can use it here but you ALSO need to add it to init.lua

Copy link

@brainiac brainiac Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grimmier378 the only reason why this doesn't fail for you is because you already have the package.

This only works here if it is a no-op. So there is no reason to use package man here. Just do a normal require and put the package man code in init.lua as derple said.

local showLabel = icon == 0 and true or buttonData.ShowLabel ~= nil and buttonData.ShowLabel or true
self:saveToDB(db, [[
INSERT OR REPLACE INTO buttons (
button_number, button_label, button_render, button_text_color, button_button_color,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these insert or replace statements will work because they will only replace if the key collides but the only key you provide to the table is the id auto increment which is not specified here. See:
SQLite Insert or Replace
SQLite’s INSERT OR REPLACE statement is an alias for the INSERT statement with the OR clause, which specifies the action to take when a row with the same primary key already exists. When a conflict occurs, the statement deletes the existing row and inserts a new one.


function BMSettings:deleteButtonFromDB(id)
local db = self:InitializeDB()
self:saveToDB(db, "DELETE FROM buttons WHERE button_number = ?", id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing operations with WHERE clauses that are not keys still will result in a very slow full table scan.


function BMSettings:deleteSetFromDB(setName)
local db = self:InitializeDB()
self:saveToDB(db, "DELETE FROM sets WHERE set_name = ?", setName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing operations with WHERE clauses that are not keys still will result in a very slow full table scan.


function BMSettings:deleteButtonFromSetDB(setName, buttonNumber)
local db = self:InitializeDB()
self:saveToDB(db, "DELETE FROM sets WHERE set_name = ? AND button_number = ?", setName, buttonNumber)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing operations with WHERE clauses that are not keys still will result in a very slow full table scan.


function BMSettings:deleteSetFromCharacterDB(charName, SetName)
local db = self:InitializeDB()
self:saveToDB(db, "DELETE FROM windows WHERE character = ? AND window_set_name = ?", charName, SetName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing operations with WHERE clauses that are not keys still will result in a very slow full table scan.


-- Save Global Settings
if table_name == "all" or table_name == "global" then
self:saveToDB(db, "INSERT OR REPLACE INTO settings (server, character, settings_version, settings_last_backup) VALUES (?, ?, ?, ?)",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this likely will result in duplicates for characters as it does not specify the PK

for _, button in ipairs(buttonsData) do
self.settings.Buttons[button.button_number] = {
Label = button.button_label,
highestRenderTime = button.button_render,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space these ='s out nicely please

}
end

local charactersData = self:loadFromDB(db, "SELECT character, character_locked, character_hide_title FROM characters")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid pre-loading every characters data now that we have moved to a db?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that we can do. i would still pull the char names for local copy functionality but yeah no reason to have all char data loaded on one character

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants