annotate AfterDark.lua @ 13:3a5816741bcb tip

Added tag v1.0Release for changeset 2761550de087
author wobin
date Sun, 20 Dec 2009 22:29:05 +1100
parents f601b8507480
children
rev   line source
wobin@1 1 AddonName, AfterDark = ...
wobin@1 2 LibStub("AceTimer-3.0"):Embed(AfterDark)
wobin@1 3 LibStub("AceEvent-3.0"):Embed(AfterDark)
wobin@1 4
wobin@1 5 AfterDark.L = LibStub("AceLocale-3.0"):GetLocale("AfterDark", true)
wobin@1 6 local L = AfterDark.L
wobin@1 7
wobin@1 8 local RIDE = "Interface\\AddOns\\AfterDark\\Images\\rotv.mp3"
wobin@1 9 local ANTHEM = "Interface\\AddOns\\AfterDark\\Images\\fta.mp3"
wobin@1 10
wobin@1 11 local SCREEN_HEIGHT = GetScreenHeight()
wobin@1 12 local SCREEN_WIDTH = GetScreenWidth()
wobin@1 13
wobin@1 14 local ScreenSaving = false
wobin@1 15
wobin@1 16 burntoutToasters, shinyToasters, toasterRack, pendingFlight = {}, {}, {}, {}
wobin@1 17
wobin@1 18 function OnFinished(self)
wobin@1 19 if ScreenSaving then
wobin@1 20 table.insert(pendingFlight, AfterDark:ScheduleTimer("SpawnMonkey", 0 ))
wobin@1 21 if #shinyToasters < AfterDark.db.profile.Busy then
wobin@1 22 table.insert(pendingFlight, AfterDark:ScheduleTimer("SpawnMonkey", math.random(0, AfterDark.db.profile.Speed)))
wobin@1 23 end
wobin@1 24 end
wobin@1 25 AfterDark:CleanCrumbTray(self.parent)
wobin@1 26 end
wobin@1 27
wobin@1 28 function AfterDark:BringMeTheHeadOfAlfredoGarcia()
wobin@1 29 local frame = table.remove(burntoutToasters)
wobin@1 30 if not frame then
wobin@1 31 frame = CreateFrame("Frame", nil, UIParent)
wobin@1 32 frame:SetFrameStrata("BACKGROUND")
wobin@1 33 frame:SetFrameLevel(math.random(1,60))
wobin@1 34 frame:SetHeight(64)
wobin@1 35 frame:SetWidth(64)
wobin@1 36
wobin@1 37 frame.mover = frame:CreateAnimationGroup()
wobin@1 38 frame.mover.parent = frame
wobin@1 39 frame.mover:SetLooping("NONE")
wobin@1 40 frame.mover:SetScript("OnFinished", OnFinished)
wobin@1 41
wobin@1 42 frame.transporter = frame.mover:CreateAnimation("Translation")
wobin@1 43 frame.zoomer = frame.mover:CreateAnimation("Scale")
wobin@1 44
wobin@1 45 if math.random(0,100) < 85 then
wobin@1 46 AfterDark:ConstructToaster(frame)
wobin@1 47 else
wobin@1 48 AfterDark:SliceBread(frame)
wobin@1 49 end
wobin@1 50 end
wobin@1 51
wobin@1 52
wobin@1 53 table.insert(shinyToasters, frame)
wobin@1 54 if not toasterRack[frame] then
wobin@1 55 toasterRack[frame] = true
wobin@1 56 end
wobin@1 57 return frame
wobin@1 58 end
wobin@1 59
wobin@1 60 function AfterDark:SpawnMonkey()
wobin@1 61 local halfHeight = SCREEN_HEIGHT/2
wobin@1 62 local yOffset = math.random(-halfHeight, halfHeight)
wobin@1 63
wobin@1 64 local scale = math.random(0.75, 1.5)
wobin@1 65
wobin@1 66 if #shinyToasters >= AfterDark.db.profile.Busy then return end
wobin@1 67 local head = self:BringMeTheHeadOfAlfredoGarcia()
wobin@1 68
wobin@1 69 head:ClearAllPoints()
wobin@1 70 head:SetPoint("RIGHT", UIParent, "RIGHT", 64, yOffset)
wobin@1 71
wobin@1 72 local yLanding = math.random(-halfHeight, halfHeight)
wobin@1 73
wobin@1 74 if head.IsToast then head.shade:SetAlpha(1 - AfterDark.db.profile.Darkness) end -- Retoast the bread
wobin@1 75 head:Respeed()
wobin@1 76
wobin@1 77 head.transporter:SetOffset(-SCREEN_WIDTH - 64 * scale, yLanding)
wobin@1 78 head.transporter:SetDuration(AfterDark.db.profile.Speed)
wobin@1 79 head.zoomer:SetScale(scale, scale)
wobin@1 80 head.zoomer:SetDuration(AfterDark.db.profile.Speed)
wobin@1 81 head:Start()
wobin@1 82 end
wobin@1 83
wobin@1 84 function AfterDark:PlayThatFunkyMusic()
wobin@1 85 if AfterDark.db.profile.Music == "zRandom" then
wobin@1 86 if math.random(1,2) == 1 then
wobin@1 87 PlayMusic(RIDE)
wobin@1 88 else
wobin@1 89 PlayMusic(ANTHEM)
wobin@1 90 end
wobin@1 91 return
wobin@1 92 else
wobin@1 93 if AfterDark.db.profile.Music == "Ride" then
wobin@1 94 PlayMusic(RIDE)
wobin@1 95 else
wobin@1 96 PlayMusic(ANTHEM)
wobin@1 97 end
wobin@1 98 end
wobin@1 99 end
wobin@1 100
wobin@1 101 function AfterDark:ScheduleFlight()
wobin@1 102 StopMusic()
wobin@1 103 table.insert(pendingFlight, self:ScheduleTimer("PlayThatFunkyMusic", 1))
wobin@1 104 table.insert(pendingFlight, self:ScheduleTimer("BeFreeMyPretties", 4))
wobin@1 105 end
wobin@1 106
wobin@1 107 function AfterDark:BeFreeMyPretties()
wobin@1 108 for i=1,AfterDark.db.profile.Busy do
wobin@1 109 table.insert(pendingFlight, AfterDark:ScheduleTimer("SpawnMonkey", math.random(0, AfterDark.db.profile.Speed)))
wobin@1 110 end
wobin@1 111
wobin@1 112 end
wobin@1 113
wobin@1 114 function AfterDark:QuickItsTheFuzz()
wobin@1 115 for i,v in ipairs(pendingFlight) do
wobin@1 116 AfterDark:CancelTimer(v, true)
wobin@1 117 end
wobin@1 118 for v,_ in pairs(toasterRack) do
wobin@1 119 v:Finish()
wobin@1 120 self:CleanCrumbTray(v)
wobin@1 121 end
wobin@1 122 pendingFlight = {}
wobin@1 123 StopMusic()
wobin@1 124 end
wobin@1 125
wobin@1 126 function AfterDark:CleanCrumbTray(frame)
wobin@1 127 for i = #shinyToasters, 1, -1 do
wobin@1 128 if frame == shinyToasters[i] then
wobin@1 129 table.insert(burntoutToasters, table.remove(shinyToasters, i))
wobin@1 130 return
wobin@1 131 end
wobin@1 132 end
wobin@1 133 end
wobin@1 134
wobin@1 135 function AfterDark:LightsAreOnButNobodysHome(eventName, target)
wobin@1 136 if target ~= "player" then return end
wobin@1 137 if UnitIsAFK("player") then
wobin@1 138 ScreenSaving = true
wobin@1 139 self:ScheduleFlight()
wobin@1 140 else
wobin@1 141 ScreenSaving = false
wobin@1 142 self:QuickItsTheFuzz()
wobin@1 143 end
wobin@1 144 end
wobin@1 145
wobin@1 146 function AfterDark:SetMeUp(event, addon)
wobin@1 147 if addon ~= "AfterDark" then return end
wobin@1 148 self:RegisterEvent("PLAYER_FLAGS_CHANGED", "LightsAreOnButNobodysHome")
wobin@1 149 self.db = LibStub("AceDB-3.0"):New("AfterDarkDB", {profile = { Busy = 30, Music = "zRandom", Darkness = 0.5, Speed = 10 } })
wobin@1 150 AfterDark:SetupOptions()
wobin@1 151 end
wobin@1 152
wobin@1 153 AfterDark:RegisterEvent("ADDON_LOADED", "SetMeUp")
wobin@1 154