File size: 2,325 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
DefineClass.InvisibleObject = {
	__parents = { "CObject" },
	flags = {},
	HelperEntity = "PointLight",
	HelperScale = 100,
	HelperCursor = false,
}

function InvisibleObject:ConfigureInvisibleObjectHelper(helper)

end

function ConfigureInvisibleObjectHelper(obj, helper)
	if not obj.HelperEntity then return end
	
	if not helper then
		helper = InvisibleObjectHelper:new()
	end
	if not helper:GetParent() then
		obj:Attach(helper)
	end
	helper:ChangeEntity(obj.HelperEntity)
	helper:SetScale(obj.HelperScale)
	obj:ConfigureInvisibleObjectHelper(helper)
end

local function CreateHelpers()
	MapForEach("map", "attached", false, "InvisibleObject",
		function(obj)
			ConfigureInvisibleObjectHelper(obj)
		end
	)
end

local function DeleteHelpers()
	MapDelete("map", "InvisibleObjectHelper")
end

if FirstLoad then
	InvisibleObjectHelpersEnabled = true
end

function ToggleInvisibleObjectHelpers()
	SetInvisibleObjectHelpersEnabled(not InvisibleObjectHelpersEnabled)
end

function SetInvisibleObjectHelpersEnabled(value)
	if not InvisibleObjectHelpersEnabled and value then
		CreateHelpers()
	elseif InvisibleObjectHelpersEnabled and not value then
		DeleteHelpers()
	end
	InvisibleObjectHelpersEnabled = value
end

DefineClass.InvisibleObjectHelper = {
	__parents = { "CObject", "ComponentAttach" },
	entity = "PointLight",
	flags = { efShadow = false, efSunShadow = false },
	properties = {},
}

if Platform.editor then
	AppendClass.InvisibleObject = {
		__parents = { "ComponentAttach" },
		flags = { cfEditorCallback = true, },
	}
	
	function OnMsg.GameEnteringEditor() -- called before GameEnterEditor, allowing XEditorFilters to catch these objects
		if InvisibleObjectHelpersEnabled then
			CreateHelpers()
		end
	end
	function OnMsg.EditorCallback(id, objects, ...)
		if id == "EditorCallbackPlace" or id == "EditorCallbackClone" or id == "EditorCallbackPlaceCursor" then
			for i = 1, #objects do
				local obj = objects[i]
				if obj:IsKindOf("InvisibleObject") and not obj:GetParent() and not obj:GetAttach("InvisibleObjectHelper") and 
					(id ~= "EditorCallbackPlaceCursor" or obj.HelperCursor) and
					InvisibleObjectHelpersEnabled then
						ConfigureInvisibleObjectHelper(obj)
				end
			end
		end
	end
	function OnMsg.GameExitEditor()
		if InvisibleObjectHelpersEnabled then
			DeleteHelpers()
		end
	end
end