-- This script checks whether a specific valuable has been taken or not
-- At the start of the level:
--   If the valuable has been taken, it deletes all shapes and bodies tagged with "truedelete"
--   If the valuable has NOT been taken, it deletes all shapes and bodies tagged with "falsedelete"

globalsearch = GetBoolParam("globalsearch", false)				-- Set to true to search for shapes and bodies globally in the hierarchy.
valuable = GetStringParam("valuable", "")						-- The registry name of the valuable to check, excluding the "savegame.valuable." part, i.e., "caveisland_crock-of-gold"

falseDeleteShapes = FindShapes("falsedelete", globalsearch)		-- Shapes to be deleted if the valuable hasn't been taken
falseDeleteBodies = FindBodies("falsedelete", globalsearch)		-- Bodies to be deleted if the valuable hasn't been taken

trueDeleteShapes = FindShapes("truedelete", globalsearch)		-- Shapes to be deleted if the valuable has been taken
trueDeleteBodies = FindBodies("truedelete", globalsearch)		-- Bodies to be deleted if the valuable has been taken

function init()
	if valuable ~= "" then  -- Don't do anything if the valuable string is empty
		if HasKey("savegame.valuable." .. valuable) and GetInt("savegame.valuable." .. valuable) ~= 0 then
			for i=1,#trueDeleteShapes do
				Delete(trueDeleteShapes[i])
			end
			for i=1,#trueDeleteBodies do
				Delete(trueDeleteBodies[i])
			end
		else
			for i=1,#falseDeleteShapes do
				Delete(falseDeleteShapes[i])
			end
			for i=1,#falseDeleteBodies do
				Delete(falseDeleteBodies[i])
			end
		end
	end
end