z_mirror/TaskList

git clone https://git.raiguard.me/z_mirror/TaskList

Caleb HeuerRename global to storage4a85a42

austinrobichaux18/Twiggy/AddPriorityAndArea
1.2 KiB47 linesraw
1local active_task_button = require("scripts.gui.active-task-button")
2local tasks_gui = require("scripts.gui.tasks.index")
3
4local player_data = {}
5
6--- Initializes the player's `storage` table.
7--- @param player LuaPlayer
8function player_data.init(player)
9  --- @class PlayerTable
10  storage.players[player.index] = {
11    --- @type number[]
12    completed_tasks = {},
13    flags = {},
14    --- @type PlayerGuis
15    guis = {},
16    --- @type number[]
17    tasks = {},
18  }
19end
20
21--- @class PlayerGuis
22--- @field active_task_button LuaGuiElement?
23--- @field edit_task EditTaskGui?
24--- @field tasks TasksGui?
25
26--- Refreshes the player's data, including GUIs, based on changes.
27--- @param player LuaPlayer
28--- @param player_table PlayerTable
29function player_data.refresh(player, player_table)
30  local TasksGui = player_table.guis.tasks
31  if TasksGui then
32    TasksGui:destroy()
33  end
34  tasks_gui.new(player, player_table)
35
36  local EditTaskGui = player_table.guis.edit_task
37  if EditTaskGui then
38    EditTaskGui:destroy()
39  end
40
41  active_task_button.destroy(player_table)
42  if player.mod_settings["tlst-show-active-task"].value ~= "off" then
43    active_task_button.build(player, player_table)
44  end
45end
46
47return player_data