Skip to content
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

Non-randomize option #27

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Copy-Addon.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}



58 changes: 49 additions & 9 deletions Gratwurst.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -154,33 +175,52 @@ 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
canGrats = true
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)
Expand Down
2 changes: 1 addition & 1 deletion Gratwurst.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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

34 changes: 0 additions & 34 deletions backupAndCopyAddon.ps1

This file was deleted.