37 lines
906 B
Lua
37 lines
906 B
Lua
|
local MessageQueue = Object:extend()
|
||
|
local Message = require "game.modules.messagequeue.message"
|
||
|
local MAX = 3
|
||
|
|
||
|
function MessageQueue:new(scene)
|
||
|
self.messages = {}
|
||
|
self.permaMessage = nil
|
||
|
self.scene = scene
|
||
|
end
|
||
|
|
||
|
function MessageQueue:addMessage(newMessage)
|
||
|
for _, message in ipairs(self.messages) do
|
||
|
message:move()
|
||
|
end
|
||
|
table.insert(self.messages, 1, Message(self.scene, newMessage, false))
|
||
|
self.messages[MAX + 1] = nil
|
||
|
end
|
||
|
|
||
|
function MessageQueue:pinMessage(message)
|
||
|
if (self.permaMessage ~= nil and self.permaMessage.text ~= message) then
|
||
|
self.permaMessage = Message(self.scene, message, true)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function MessageQueue:update(dt)
|
||
|
for _, message in ipairs(self.messages) do
|
||
|
message:update(dt)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function MessageQueue:draw()
|
||
|
for _, message in ipairs(self.messages) do
|
||
|
message:draw()
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return MessageQueue
|