mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Updated Tasks
This commit is contained in:
@@ -559,7 +559,7 @@ function Datastore:remove(key)
|
|||||||
key = self:serialize(key)
|
key = self:serialize(key)
|
||||||
local old_value = self:raw_get(key)
|
local old_value = self:raw_get(key)
|
||||||
self:raw_set(key)
|
self:raw_set(key)
|
||||||
self:raise_event('on_update', key, old_value)
|
self:raise_event('on_update', key, nil, old_value)
|
||||||
if self.save_to_disk then self:write_action('remove', key) end
|
if self.save_to_disk then self:write_action('remove', key) end
|
||||||
if self.parent and self.parent.auto_save then return self.parent:save(key) end
|
if self.parent and self.parent.auto_save then return self.parent:save(key) end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,22 +10,21 @@ Tasks.update_task(task_id, 'We need more iron!', game.player.name)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Store = require 'expcore.store' --- @dep expcore.store
|
local Datastore = require 'expcore.datastore' --- @dep expcore.datastore
|
||||||
local Global = require 'utils.global' --- @dep utils.global
|
local Global = require 'utils.global' --- @dep utils.global
|
||||||
local Token = require 'utils.token' --- @dep utils.token
|
|
||||||
|
--- Stores all data for the warp gui
|
||||||
|
local TaskData = Datastore.connect('TaskData')
|
||||||
|
TaskData:set_serializer(function(raw_key) return raw_key.task_id end)
|
||||||
|
|
||||||
local Tasks = {}
|
local Tasks = {}
|
||||||
|
|
||||||
-- Global lookup table for force name to task ids
|
-- Global lookup table for force name to task ids
|
||||||
local force_tasks = {}
|
local force_tasks = {_uid=1}
|
||||||
Global.register(force_tasks, function(tbl)
|
Global.register(force_tasks, function(tbl)
|
||||||
force_tasks = tbl
|
force_tasks = tbl
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Task store is keyed by task id, value is a table
|
|
||||||
local task_store = Store.register()
|
|
||||||
Tasks.store = task_store
|
|
||||||
|
|
||||||
--- Setters.
|
--- Setters.
|
||||||
-- functions used to created and alter tasks
|
-- functions used to created and alter tasks
|
||||||
-- @section setters
|
-- @section setters
|
||||||
@@ -43,8 +42,9 @@ local task_id = Tasks.add_task(game.player.force.name, nil, game.player.name)
|
|||||||
]]
|
]]
|
||||||
function Tasks.add_task(force_name, task_number, player_name, task_message)
|
function Tasks.add_task(force_name, task_number, player_name, task_message)
|
||||||
-- Get a new task id
|
-- Get a new task id
|
||||||
local task_id = tostring(Token.uid())
|
local task_id = tostring(force_tasks._uid)
|
||||||
task_message = task_message or 'New Task'
|
task_message = task_message or 'New Task'
|
||||||
|
force_tasks._uid = force_tasks._uid + 1
|
||||||
|
|
||||||
-- Get the existing tasks for this force
|
-- Get the existing tasks for this force
|
||||||
local tasks = force_tasks[force_name]
|
local tasks = force_tasks[force_name]
|
||||||
@@ -67,13 +67,13 @@ function Tasks.add_task(force_name, task_number, player_name, task_message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Add the new task to the store
|
-- Add the new task to the store
|
||||||
Store.set(task_store, task_id, {
|
TaskData:set(task_id, {
|
||||||
task_id = task_id,
|
task_id = task_id,
|
||||||
force_name = force_name,
|
force_name = force_name,
|
||||||
message = task_message,
|
message = task_message,
|
||||||
last_edit_name = player_name or '<server>',
|
last_edit_name = player_name or '<server>',
|
||||||
last_edit_time = game.tick,
|
last_edit_time = game.tick,
|
||||||
curently_editing = editing
|
currently_editing = editing
|
||||||
})
|
})
|
||||||
|
|
||||||
return task_id
|
return task_id
|
||||||
@@ -87,10 +87,10 @@ Tasks.remove_task(task_id)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.remove_task(task_id)
|
function Tasks.remove_task(task_id)
|
||||||
local task = Store.get(task_store, task_id)
|
local task = TaskData:get(task_id)
|
||||||
local force_name = task.force_name
|
local force_name = task.force_name
|
||||||
table.remove_element(force_tasks[force_name], task_id)
|
table.remove_element(force_tasks[force_name], task_id)
|
||||||
Store.clear(task_store, task_id)
|
TaskData:remove(task_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Update the message and last edited information for a task
|
--[[-- Update the message and last edited information for a task
|
||||||
@@ -103,7 +103,7 @@ Task.update_task(task_id, 'We need more iron!', game.player.name)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.update_task(task_id, new_message, player_name)
|
function Tasks.update_task(task_id, new_message, player_name)
|
||||||
Store.update(task_store, task_id, function(task)
|
TaskData:update(task_id, function(_, task)
|
||||||
task.last_edit_name = player_name or '<server>'
|
task.last_edit_name = player_name or '<server>'
|
||||||
task.last_edit_time = game.tick
|
task.last_edit_time = game.tick
|
||||||
task.message = new_message
|
task.message = new_message
|
||||||
@@ -120,8 +120,8 @@ Tasks.set_editing(task_id, game.player.name, true)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.set_editing(task_id, player_name, state)
|
function Tasks.set_editing(task_id, player_name, state)
|
||||||
Store.update(task_store, task_id, function(task)
|
TaskData:update(task_id, function(_, task)
|
||||||
task.curently_editing[player_name] = state
|
task.currently_editing[player_name] = state
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ end)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.on_update(handler)
|
function Tasks.on_update(handler)
|
||||||
Store.watch(task_store, handler)
|
TaskData:on_update(handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Getters.
|
--- Getters.
|
||||||
@@ -151,7 +151,7 @@ local task = Tasks.get_task(task_id)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.get_task(task_id)
|
function Tasks.get_task(task_id)
|
||||||
return Store.get(task_store, task_id)
|
return TaskData:get(task_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets all the task ids that a force has
|
--[[-- Gets all the task ids that a force has
|
||||||
@@ -176,8 +176,8 @@ local editing = Tasks.get_editing(task_id, game.player.name)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.get_editing(task_id, player_name)
|
function Tasks.get_editing(task_id, player_name)
|
||||||
local task = Store.get(task_store, task_id)
|
local task = TaskData:get(task_id)
|
||||||
return task.curently_editing[player_name]
|
return task.currently_editing[player_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Module Return
|
-- Module Return
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ local Datastore = require 'expcore.datastore' --- @dep expcore.datastore
|
|||||||
local Global = require 'utils.global' --- @dep utils.global
|
local Global = require 'utils.global' --- @dep utils.global
|
||||||
local config = require 'config.gui.warps' --- @dep config.warps
|
local config = require 'config.gui.warps' --- @dep config.warps
|
||||||
|
|
||||||
--- Stores all data for the warp gui
|
--- Stores all data for the warp system
|
||||||
local WrapData = Datastore.connect('WrapData')
|
local WrapData = Datastore.connect('WrapData')
|
||||||
WrapData:set_serializer(function(raw_key) return raw_key.warp_id end)
|
WrapData:set_serializer(function(raw_key) return raw_key.warp_id end)
|
||||||
|
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ local function update_task(player, task_table, task_id)
|
|||||||
-- Update the edit flow
|
-- Update the edit flow
|
||||||
local edit_flow = task_table['edit-'..task_id]
|
local edit_flow = task_table['edit-'..task_id]
|
||||||
local player_allowed_edit = check_player_permissions(player, task)
|
local player_allowed_edit = check_player_permissions(player, task)
|
||||||
local players_editing = table.get_keys(task.curently_editing)
|
local players_editing = table.get_keys(task.currently_editing)
|
||||||
local edit_task_element = edit_flow[edit_task.name]
|
local edit_task_element = edit_flow[edit_task.name]
|
||||||
local discard_task_element = edit_flow[discard_task.name]
|
local discard_task_element = edit_flow[discard_task.name]
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ local function update_task(player, task_table, task_id)
|
|||||||
-- Check if the player is was editing and/or currently editing
|
-- Check if the player is was editing and/or currently editing
|
||||||
local task_entry = task_flow[task_editing.name] or task_label(task_flow, task)
|
local task_entry = task_flow[task_editing.name] or task_label(task_flow, task)
|
||||||
local player_was_editing = task_entry.type == 'textfield'
|
local player_was_editing = task_entry.type == 'textfield'
|
||||||
local player_is_editing = task.curently_editing[player.name]
|
local player_is_editing = task.currently_editing[player.name]
|
||||||
|
|
||||||
-- Update the task flow
|
-- Update the task flow
|
||||||
if not player_was_editing and not player_is_editing then
|
if not player_was_editing and not player_is_editing then
|
||||||
@@ -361,14 +361,14 @@ Gui.left_toolbar_button('utility/not_enough_repair_packs_icon', {'task-list.main
|
|||||||
return Roles.player_allowed(player, 'gui/task-list')
|
return Roles.player_allowed(player, 'gui/task-list')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- When a new task is added it will udpate the task list for everyone on that force
|
--- When a new task is added it will update the task list for everyone on that force
|
||||||
Tasks.on_update(function(task, task_id, removed_task)
|
Tasks.on_update(function(task_id, task, old_task)
|
||||||
-- Get the force to update, task is nil when removed
|
-- Get the force to update, task is nil when removed
|
||||||
local force
|
local force
|
||||||
if task then
|
if task then
|
||||||
force = game.forces[task.force_name]
|
force = game.forces[task.force_name]
|
||||||
else
|
else
|
||||||
force = game.forces[removed_task.force_name]
|
force = game.forces[old_task.force_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the task for all the players on the force
|
-- Update the task for all the players on the force
|
||||||
|
|||||||
Reference in New Issue
Block a user