Mercurial > wow > squawk
comparison Squawk.lua @ 2:75a76882c343
more work on the controller
author | wobin |
---|---|
date | Thu, 16 Apr 2009 22:05:24 +1000 |
parents | 188273d0efad |
children | 1cc6e4710e2e |
comparison
equal
deleted
inserted
replaced
1:188273d0efad | 2:75a76882c343 |
---|---|
76 | 76 |
77 function Squawk:Sort(Squawks) | 77 function Squawk:Sort(Squawks) |
78 return table.sort(Squawks, function(a,b) return a.Time < b.Time end) | 78 return table.sort(Squawks, function(a,b) return a.Time < b.Time end) |
79 end | 79 end |
80 | 80 |
81 function Squawk:GetOwn(Squawks) | |
82 local mine = {} | |
83 for _, squawk in ipairs(Squawks) do | |
84 if squawk.Owner == UnitName("player") then | |
85 table.insert(mine, squawk) | |
86 end | |
87 end | |
88 return self:Sort(mine) | |
89 end | |
90 | |
81 function Settings:IsPrivate() | 91 function Settings:IsPrivate() |
82 return Settings.Private | 92 return Settings.Private |
83 end | 93 end |
84 | 94 |
85 function Settings:AddFollower(Name) | 95 function Settings:AddFollower(Name) |
86 table.insert(Settings.Follower, Name) | 96 Settings.Follower[Name] = 1 |
87 end | 97 end |
88 | 98 |
89 function Settings:AddFollowing(Name) | 99 function Settings:AddFollowing(Name) |
90 table.insert(Settings.Following, Name) | 100 Settings.Following[Name] = 1 |
91 end | 101 end |
92 | 102 |
93 function Settings:AddBlock(Name) | 103 function Settings:AddBlock(Name) |
94 table.insert(Settings.Blocked, Name) | 104 Settings.Blocked[Name] = 1 |
95 end | 105 end |
96 | 106 |
97 function Settings:RemoveFollower(Name) | 107 function Settings:RemoveFollower(Name) |
98 for i,v in ipairs(Settings.Follower) do | 108 if Settings.Follower[Name] then |
99 if v == Name then | 109 Settings.Follower[Name] = nil |
100 table.remove(Settings.Follower, i) | |
101 return | |
102 end | |
103 end | 110 end |
104 end | 111 end |
105 | 112 |
106 function Settings:RemoveFollowing(Name) | 113 function Settings:RemoveFollowing(Name) |
107 for i,v in ipairs(Settings.Following) do | 114 if Settings.Following[Name] then |
108 if v == Name then | 115 Settings.Following[Name] = nil |
109 table.remove(Settings.Following, i) | |
110 return | |
111 end | |
112 end | 116 end |
113 end | 117 end |
114 | 118 |
115 function Settings:RemoveBlock(Name) | 119 function Settings:RemoveBlock(Name) |
116 for i,v in ipairs(Settings.Blocked) do | 120 if Settings.Blocked[Name] then |
117 if v == Name then | 121 Settings.Blocked[Name] = nil |
118 table.remove(Settings.Blocked, i) | |
119 return | |
120 end | |
121 end | 122 end |
122 end | 123 end |
123 | 124 |
124 --Controller-- | 125 --Controller-- |
125 | 126 |
133 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) | 134 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) |
134 end | 135 end |
135 end | 136 end |
136 | 137 |
137 function Controller:IWantToFollowThem(Name) | 138 function Controller:IWantToFollowThem(Name) |
138 | 139 self:SendMessageToTarget(Name, "#Request|"..UnitName("player")) |
139 end | 140 end |
140 | 141 |
141 function Controller:IAmNowFollowingThem(Name) | 142 function Controller:IAmNowFollowingThem(Name) |
142 Settings:AddFollowing(Name) | 143 Settings:AddFollowing(Name) |
143 View:NotifyOfNewFollowing(Name) | 144 View:NotifyOfNewFollowing(Name) |
144 end | 145 end |
145 | 146 |
146 function Controller:AddANewSquawk(Name, Message) | 147 function Controller:AddANewSquawk(Name, Message) |
147 table.insert(Model.db.Squawks, Squawk:new(Message, Name)) | 148 table.insert(Model.db.Squawks, Squawk:new(Message, Name)) |
148 View:UpdateSquawkList() | 149 View:UpdateSquawkList() |
150 end | |
151 | |
152 function Controller:SendNewSquawk(Message) | |
153 if not Model:IsPrivate() then | |
154 self:SendMessageToGuild("#Squawk|"..UnitName("player").."|"..Message) | |
155 end | |
156 | |
157 self:AddANewSquawk(UnitName("player"), Message) | |
158 | |
159 for name, _ in pairs(Model.Following) do | |
160 self:SendMessageToTarget(name, "#Squawk|"..UnitName("player").."|"..Message) | |
161 end | |
149 end | 162 end |
150 | 163 |
151 function Controller:ImPending(Name) | 164 function Controller:ImPending(Name) |
152 View:NotifyOfPending(Name) | 165 View:NotifyOfPending(Name) |
153 end | 166 end |
161 end | 174 end |
162 | 175 |
163 local Parse = { | 176 local Parse = { |
164 ["#Pending"] = Controller.ImPending, | 177 ["#Pending"] = Controller.ImPending, |
165 ["#Follow"] = Controller.IAmNowFollowingThem, | 178 ["#Follow"] = Controller.IAmNowFollowingThem, |
166 ["#Squawk"] = Controller.AddANewSquawk | 179 ["#Squawk"] = Controller.AddANewSquawk, |
180 ["#Request"] = Controller.TheyWantToFollowMe, | |
167 } | 181 } |
168 | 182 |
169 function Controller:ReceiveMessage(Prefix, Message, Distribution, Sender) | 183 function Controller:ReceiveMessage(Prefix, Message, Distribution, Sender) |
170 local command, name, info = strsplit("|",Message) | 184 local command, name, info = strsplit("|",Message) |
171 Parse[command](self, name, info) | 185 Parse[command](self, name, info) |