-
Notifications
You must be signed in to change notification settings - Fork 7
SQL conversion #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
SQL conversion #18
Conversation
|
forgot i was also playing with the zep editor, commented that all out and re-enabled the multiline editor. |
doesn't crash when reloading the new copy.
|
|
||
| if renderButton[key] ~= nil then | ||
| local tColors = ButtonUtils.split(renderButton[key], ",") | ||
| for i, v in ipairs(tColors) do btnColor[i] = tonumber(v / 255) end |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 '' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 (?, ?, ?, ?)", |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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