--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by Whimsical. --- DateTime: 2021-03-16 3:26 p.m. --- --- Original Memory Bag by MrStump --- https://steamcommunity.com/sharedfiles/filedetails/?id=953770080 ---@class MemoryListEntry ---@field public position Vector ---@field public rotation Vector ---@field public lock boolean local MemoryListEntry={} ---@type table local memory_list = {} local POSTFIX = { SAVE = "_memory_object", ZONE = "_memory_zone", SHUFFLE = "_memory_shuffle" } ---@type table local BUTTON = { POSITION = Vector(0, 0.3, -2), ROTATION = Vector(0, 180, 0), HEIGHT = 350, WIDTH = 800, FONT_SIZE = 250, COLOR = Color.Black, FONT_COLOR = Color.White } local ipairs = ipairs local pairs = pairs ---@return string local function get_prefix() return self:getDescription() end local function updateSave() local data_to_save = {["ml"]=memory_list} local saved_data = JSON.encode(data_to_save) self.script_state = saved_data end ---@param label string ---@param action string local function createButton(label, action) self:clearButtons() ---@type CreateClassicUIButton local parameters = { label = label, click_function = action, function_owner = self } for key, value in pairs(BUTTON) do parameters[key:lower()] = value end self:createButton(parameters) end local function create_place_button() createButton("Place", "place_objects") end local function create_recall_button() createButton("Recall", "recall_objects") end ---@param tag string ---@param lock boolean ---@return fun(object:TTSObject) local function create_object_callback(tag, lock) ---@param object TTSObject return function (object) object:setLock(lock) if object:hasTag(tag) then object:shuffle() end end end ---@param object TTSObject local function record_objects(object) memory_list[object:getGUID()] = { position = object:getPosition(), rotation = object:getRotation(), lock = object:getLock() } self:putObject(object) end ---@param objects TTSObject[] local function update_objects(objects) for _, object in ipairs(objects) do record_objects(object) end end --Sends objects from bag/table to their saved position/rotation function place_objects() local prefix = get_prefix() local shuffle_tag = prefix .. POSTFIX.SHUFFLE local content = self.getObjects() for _, item in ipairs(content) do local entry = memory_list[item.guid] if entry then self.takeObject { guid=item.guid, position=entry.position, rotation=entry.rotation, callback_function = create_object_callback(shuffle_tag, entry.lock) } end end broadcastToAll("Objects Placed", {1,1,1}) create_recall_button() end --Recalls objects to bag from table function recall_objects() memory_list = {} local prefix = get_prefix() if prefix=="" then broadcastToAll("Error in Memory Bag: Tag prefix not set.") return end local save_tag = prefix .. POSTFIX.SAVE local zone_tag = prefix .. POSTFIX.ZONE local zones = getObjectsWithTag(zone_tag) if #zones>0 then for _, zone in ipairs(zones) do update_objects(zone:getObjects()) end else update_objects(getObjectsWithTag(save_tag)) end updateSave() broadcastToAll("Objects Recalled", {1,1,1}) create_place_button() end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memory_list = loaded_data.ml else --Set up information for if there is no saved saved data memory_list = {} end if self:getQuantity()==0 then create_recall_button() else create_place_button() end end