diff --git a/Copy-Addon.ps1 b/Copy-Addon.ps1 new file mode 100644 index 0000000..7fc73b0 --- /dev/null +++ b/Copy-Addon.ps1 @@ -0,0 +1,62 @@ +$options = $args[0] + +$addonTestName = "Gratwurst" +$dateTimeNow = Get-Date -Format yyyy-MM-ddTHH-mm-ss-ff +$version = "_retail_" +$wowRetailPath = "C:\Program Files (x86)\World of Warcraft\$version\Interface\AddOns" +$addonTempPath = Join-Path -Path $env:APPDATA -ChildPath $addonTestName +$addonPath = Join-Path -Path $wowRetailPath -ChildPath $addonTestName +$backupAddonPath = Join-Path -Path $addonTempPath -ChildPath "Backup" + +$addonPathExists = Test-Path -Path $addonPath +$tempPathExists = Test-Path -Path $addonTempPath + +function Clear-Folders { + if($addonPathExists){ + Remove-Item -Path $addonPath -Recurse -Force + Write-Host "AddonFolderRemoved" + } + + if($tempPathExists){ + Remove-Item -Path $addonTempPath -Recurse -Force + Write-Host "TempFolderRemoved" + } +} + +function Copy-Addon { + if(-not $tempPathExists){ + New-Item -Path $env:APPDATA -Name $addonTestName -ItemType "directory" + } + + if(-not $addonPathExists){ + New-Item -Path $addonPath -Name $addonTestName -ItemType "directory" + } + + $allWowAddonFiles = $addonPath + "\*" + + $backupAddonPathDateTime = Join-Path -Path $backupAddonPath -ChildPath $dateTimeNow + + New-Item -Path $backupAddonPath -Name $dateTimeNow -ItemType "directory" + + # Back up last session + Copy-Item -Path $allWowAddonFiles -Destination $backupAddonPathDateTime -Recurse + + Copy-Item -Path "src\*" -Destination $addonPath -Recurse -Force + + Write-Host $addonPath -ForegroundColor Blue +} + +# switch on args +switch ($options) { + "clean" { + Write-Host "Cleaning up addon" + Clear-Folders + } + default { + Write-Host "Copying addon" + Copy-Addon + } +} + + + diff --git a/Gratwurst.lua b/Gratwurst.lua index 60700bf..adf7cd8 100644 --- a/Gratwurst.lua +++ b/Gratwurst.lua @@ -1,5 +1,6 @@ ---@diagnostic disable: param-type-mismatch, missing-parameter, undefined-field -- create global variables +ConfigTitle = "Gratwurst 1.7 Config" PaddingLeft = 20 function InitializeAddon(self) @@ -15,6 +16,7 @@ function InitializeSavedVariables(self) GratwurstEnabled = GratwurstEnabled or true GratwurstVariancePercentage = GratwurstVariancePercentage or 50 GratwurstIsGratzing = GratwurstIsGratzing or false + GratwurstShouldRandomize = GratwurstShouldRandomize or true end function SetConfigurationWindow() @@ -34,13 +36,32 @@ function SetConfigurationWindow() titleString:SetTextColor(1, 0.8196079, 0) titleString:SetShadowOffset(1, -1) titleString:SetShadowColor(0, 0, 0) - titleString:SetText("Gratwurst 1.6 Config") + titleString:SetText(ConfigTitle) Gratwurst = {}; Gratwurst.ui = {}; Gratwurst.ui.panel = luaFrame Gratwurst.ui.panel.name = "Gratwurst"; + -- Make a checkbox to disable randomizing the message + local checkbox = CreateFrame("CheckButton", "GratwurstCheckbox", Gratwurst.ui.panel, "ChatConfigCheckButtonTemplate") + checkbox:SetPoint("TOPLEFT", PaddingLeft, -30) + checkbox:SetChecked(GratwurstShouldRandomize) + checkbox:SetScript("OnClick", function(self,event,arg1) + GratwurstShouldRandomize = self:GetChecked() + end) + + -- Make a label for the checkbox + local checkboxLabel = checkbox:CreateFontString("GratwurstCheckboxLabel") + checkboxLabel:SetPoint("BOTTOM", checkbox, "TOP", 0, 0) + checkboxLabel:SetFont("Fonts\\FRIZQT__.TTF", 12) + checkboxLabel:SetWidth(250) + checkboxLabel:SetHeight(20) + checkboxLabel:SetTextColor(1, 0.8196079, 0) + checkboxLabel:SetShadowOffset(1, -1) + checkboxLabel:SetShadowColor(0, 0, 0) + checkboxLabel:SetText("Randomize Message") + -- Create the max delay slide from 1 to 9 local maxDelaySlider = CreateFrame("Slider", "MaxDelaySlider", Gratwurst.ui.panel, "OptionsSliderTemplate") maxDelaySlider:SetPoint("TOPLEFT", PaddingLeft, -70) @@ -154,14 +175,12 @@ function OnEventReceived(self, event, msg, author, ...) end function GuildAchievementMessageEventReceived(isDebug, author) - -- if GratwurstIsGratzing is true, then we're already gratzing and we should stop the event if GratwurstIsGratzing then return end GratwurstIsGratzing = true - local gratsStop = true local canGrats = false local random = math.random(1, 100) if random <= GratwurstVariancePercentage then @@ -169,18 +188,39 @@ function GuildAchievementMessageEventReceived(isDebug, author) end GratwurstDelayInSeconds = math.random(1,GratwurstRandomDelayMax) C_Timer.After(GratwurstDelayInSeconds,function() - if gratsStop and canGrats and GratwurstEnabled and GratwurstMessage ~= "" then - gratsStop=false - if isDebug then - print("GetRandomMessageFromList(author): " .. GetRandomMessageFromList(author)) + if canGrats and GratwurstEnabled and GratwurstMessage ~= "" then + if GratwurstShouldRandomize then + if isDebug then + print("GetTopMessageFromList(author): " .. GetTopMessageFromList(author)) + else + SendChatMessage(GetTopMessageFromList(author), "GUILD") + end else - SendChatMessage(GetRandomMessageFromList(author), "GUILD") + if isDebug then + print("GetRandomMessageFromList(author): " .. GetRandomMessageFromList(author)) + else + SendChatMessage(GetRandomMessageFromList(author), "GUILD") + end end - end + end GratwurstIsGratzing = false end) end +function GetTopMessageFromList(author) + local table = lines(GratwurstMessage) + local message = table[1] + + if author ~= nil then + message = FindAndReplacePlayerNameToken(message, author) + else + -- we're debugging because author is nil since the event isn't fired + message = FindAndReplacePlayerNameToken(message, "Taco-RealmOfNightmares") + end + + return message +end + function GetRandomMessageFromList(author) local table = lines(GratwurstMessage) local index = GetTableSize(table) diff --git a/Gratwurst.toc b/Gratwurst.toc index f4390ed..c170ab9 100644 --- a/Gratwurst.toc +++ b/Gratwurst.toc @@ -4,7 +4,7 @@ ## Title: Gratwurst ## Version: 1.6.0 ## DefaultState: Enabled -## SavedVariablesPerCharacter: GratwurstMessage, GratwurstDelayInSeconds, GratwurstEnabled, GratwurstUnitName, GratwurstRandomDelayEnabled, GratwurstRandomDelayMax, GratwurstShouldVary, GratwurstVariancePercentage, GratwurstIsGratzing +## SavedVariablesPerCharacter: GratwurstMessage, GratwurstDelayInSeconds, GratwurstEnabled, GratwurstUnitName, GratwurstRandomDelayEnabled, GratwurstRandomDelayMax, GratwurstShouldVary, GratwurstVariancePercentage, GratwurstIsGratzing, GratwurstShouldRandomize Gratwurst.xml Gratwurst.lua diff --git a/backupAndCopyAddon.ps1 b/backupAndCopyAddon.ps1 deleted file mode 100644 index b9452c0..0000000 --- a/backupAndCopyAddon.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -$addonTestName = "Gratwurst" -$dateTimeNow = Get-Date -Format yyyy-MM-ddTHH-mm-ss-ff -$version = "_retail_" -$wowRetailPath = "C:\Program Files (x86)\World of Warcraft\$version\Interface\AddOns" -$addonTempPath = Join-Path -Path $env:APPDATA -ChildPath $addonTestName -$addonPath = Join-Path -Path $wowRetailPath -ChildPath $addonTestName -$backupAddonPath = Join-Path -Path $addonTempPath -ChildPath "Backup" - -$addonPathExists = Test-Path -Path $addonPath -$tempPathExists = Test-Path -Path $addonTempPath - -if(-not $tempPathExists){ - New-Item -Path $env:APPDATA -Name $addonTestName -ItemType "directory" - Write-Host "TempFolderCreated" -} - -if(-not $addonPathExists){ - New-Item -Path $addonPath -Name $addonTestName -ItemType "directory" - Write-Host "AddonFolderCreated" -} - -$allWowAddonFiles = $addonPath + "\*" - -$backupAddonPathDateTime = Join-Path -Path $backupAddonPath -ChildPath $dateTimeNow - -New-Item -Path $backupAddonPath -Name $dateTimeNow -ItemType "directory" - -# Back up last session -Copy-Item -Path $allWowAddonFiles -Destination $backupAddonPathDateTime -Recurse - -# Copy over source -Copy-Item -Path "$addonTestName.*" -Destination $addonPath | Where-Object { ! $_.PSIsContainer } - -# Start-Process -FilePath "C:\Program Files (x86)\World of Warcraft\_retail_\Wow.exe" \ No newline at end of file