mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
Implement the core WoW frame system that nearly all addons use:
- CreateFrame(type, name, parent, template) — creates a frame table
with metatable methods, optionally registered as a global by name
- frame:RegisterEvent(event) — register frame for event dispatch
- frame:UnregisterEvent(event) — unregister
- frame:SetScript(type, handler) — set OnEvent/OnUpdate/etc handlers
- frame:GetScript(type) — retrieve handlers
- frame:Show()/Hide()/IsShown()/IsVisible() — visibility state
- frame:GetName() — return frame name
Event dispatch now fires both global RegisterEvent handlers AND
frame OnEvent scripts, matching WoW's dual dispatch model.
Updated HelloWorld to use standard WoW addon pattern:
local f = CreateFrame("Frame", "MyFrame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...) end)
28 lines
1 KiB
Lua
28 lines
1 KiB
Lua
-- HelloWorld addon — demonstrates the WoWee addon system
|
|
|
|
-- Create a frame and register for events (standard WoW addon pattern)
|
|
local f = CreateFrame("Frame", "HelloWorldFrame")
|
|
f:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
f:RegisterEvent("CHAT_MSG_SAY")
|
|
|
|
f:SetScript("OnEvent", function(self, event, ...)
|
|
if event == "PLAYER_ENTERING_WORLD" then
|
|
local name = UnitName("player")
|
|
local level = UnitLevel("player")
|
|
print("|cff00ff00[HelloWorld]|r Welcome, " .. name .. "! (Level " .. level .. ")")
|
|
elseif event == "CHAT_MSG_SAY" then
|
|
local msg, sender = ...
|
|
if msg and sender then
|
|
print("|cff00ff00[HelloWorld]|r " .. sender .. " said: " .. msg)
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Register a custom slash command
|
|
SLASH_HELLOWORLD1 = "/hello"
|
|
SLASH_HELLOWORLD2 = "/hw"
|
|
SlashCmdList["HELLOWORLD"] = function(args)
|
|
print("|cff00ff00[HelloWorld]|r Hello! " .. (args ~= "" and args or "Type /hello <message>"))
|
|
end
|
|
|
|
print("|cff00ff00[HelloWorld]|r Addon loaded. Type /hello to test slash commands.")
|