38 lines
829 B
Lua
38 lines
829 B
Lua
|
|
local Widget = {}
|
||
|
|
local Reactive = require("Core.Reactive")
|
||
|
|
|
||
|
|
local function ResetWatcher(widget)
|
||
|
|
if widget.health_watcher then
|
||
|
|
widget.health_watcher:Destroy()
|
||
|
|
widget.health_watcher = nil
|
||
|
|
end
|
||
|
|
if widget.hunger_watcher then
|
||
|
|
widget.hunger_watcher:Destroy()
|
||
|
|
widget.hunger_watcher = nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function Widget:OnDestroy()
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
function Widget:Refresh(args)
|
||
|
|
local role = args.role
|
||
|
|
if role == nil then return end
|
||
|
|
self:BindRole(role)
|
||
|
|
end
|
||
|
|
|
||
|
|
function Widget:BindRole(role)
|
||
|
|
ResetWatcher(self)
|
||
|
|
self.health_watcher = Reactive.Watcher(function()
|
||
|
|
self.HealthBar:SetPercent(role:GetHealthPercent())
|
||
|
|
end)
|
||
|
|
|
||
|
|
self.hunger_watcher = Reactive.Watcher(function()
|
||
|
|
self.HungerBar:SetPercent(role:GetHungerPercent())
|
||
|
|
end)
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
return Class(nil, nil, Widget)
|