From 4a31011a2649b57530fc45f5b45e2a9937023724 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 30 May 2020 23:02:59 +0100 Subject: [PATCH] Updated Tasks --- expcore/datastore.lua | 2 +- modules/control/tasks.lua | 38 +++++++++++++++++++------------------- modules/control/warps.lua | 2 +- modules/gui/task-list.lua | 10 +++++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/expcore/datastore.lua b/expcore/datastore.lua index 0a471b07..f0d5baa9 100644 --- a/expcore/datastore.lua +++ b/expcore/datastore.lua @@ -559,7 +559,7 @@ function Datastore:remove(key) key = self:serialize(key) local old_value = self:raw_get(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.parent and self.parent.auto_save then return self.parent:save(key) end end diff --git a/modules/control/tasks.lua b/modules/control/tasks.lua index 0e8fb941..ec0f8c38 100644 --- a/modules/control/tasks.lua +++ b/modules/control/tasks.lua @@ -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 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 = {} -- Global lookup table for force name to task ids -local force_tasks = {} +local force_tasks = {_uid=1} Global.register(force_tasks, function(tbl) force_tasks = tbl end) --- Task store is keyed by task id, value is a table -local task_store = Store.register() -Tasks.store = task_store - --- Setters. -- functions used to created and alter tasks -- @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) -- 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' + force_tasks._uid = force_tasks._uid + 1 -- Get the existing tasks for this force local tasks = force_tasks[force_name] @@ -67,13 +67,13 @@ function Tasks.add_task(force_name, task_number, player_name, task_message) end -- Add the new task to the store - Store.set(task_store, task_id, { + TaskData:set(task_id, { task_id = task_id, force_name = force_name, message = task_message, last_edit_name = player_name or '', last_edit_time = game.tick, - curently_editing = editing + currently_editing = editing }) return task_id @@ -87,10 +87,10 @@ 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 table.remove_element(force_tasks[force_name], task_id) - Store.clear(task_store, task_id) + TaskData:remove(task_id) end --[[-- 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) - Store.update(task_store, task_id, function(task) + TaskData:update(task_id, function(_, task) task.last_edit_name = player_name or '' task.last_edit_time = game.tick 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) - Store.update(task_store, task_id, function(task) - task.curently_editing[player_name] = state + TaskData:update(task_id, function(_, task) + task.currently_editing[player_name] = state end) end @@ -135,7 +135,7 @@ end) ]] function Tasks.on_update(handler) - Store.watch(task_store, handler) + TaskData:on_update(handler) end --- Getters. @@ -151,7 +151,7 @@ local task = Tasks.get_task(task_id) ]] function Tasks.get_task(task_id) - return Store.get(task_store, task_id) + return TaskData:get(task_id) end --[[-- 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) - local task = Store.get(task_store, task_id) - return task.curently_editing[player_name] + local task = TaskData:get(task_id) + return task.currently_editing[player_name] end -- Module Return diff --git a/modules/control/warps.lua b/modules/control/warps.lua index a61e80d4..07be1b0f 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -25,7 +25,7 @@ local Datastore = require 'expcore.datastore' --- @dep expcore.datastore local Global = require 'utils.global' --- @dep utils.global 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') WrapData:set_serializer(function(raw_key) return raw_key.warp_id end) diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index bdc57818..a83b3aa5 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -240,7 +240,7 @@ local function update_task(player, task_table, task_id) -- Update the edit flow local edit_flow = task_table['edit-'..task_id] 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 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 local task_entry = task_flow[task_editing.name] or task_label(task_flow, task) 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 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') end) ---- When a new task is added it will udpate the task list for everyone on that force -Tasks.on_update(function(task, task_id, removed_task) +--- When a new task is added it will update the task list for everyone on that force +Tasks.on_update(function(task_id, task, old_task) -- Get the force to update, task is nil when removed local force if task then force = game.forces[task.force_name] else - force = game.forces[removed_task.force_name] + force = game.forces[old_task.force_name] end -- Update the task for all the players on the force