File size: 5,430 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
local function not_attached(obj)
	return not obj:GetParent()
end

--[[@@@
@class ComponentAttach
Objects inheriting this class can attach other objects or be attached to other objects
--]]

DefineClass.ComponentAttach = {
	__parents = { "CObject" },
	flags = { cofComponentAttach = true },
	properties = {
		{ category = "Child", id = "AttachOffset",   name = "Attached Offset",  editor = "point",  default = point30, no_edit = not_attached, dont_save = true },
		{ category = "Child", id = "AttachAxis",     name = "Attached Axis",    editor = "point",  default = axis_z,  no_edit = not_attached, dont_save = true },
		{ category = "Child", id = "AttachAngle",    name = "Attached Angle",   editor = "number", default = 0,       no_edit = not_attached, dont_save = true, min = -180*60, max = 180*60, slider = true, scale = "deg" },
		{ category = "Child", id = "AttachSpotName", name = "Attached At",      editor = "text",   default = "",      no_edit = not_attached, dont_save = true, read_only = true },
		{ category = "Child", id = "Parent",         name = "Attached To",      editor = "object", default = false,   no_edit = not_attached, dont_save = true, read_only = true },
		{ category = "Child", id = "TopmostParent",  name = "Topmost Parent",   editor = "object", default = false,   no_edit = not_attached, dont_save = true, read_only = true },
		{ category = "Child", id = "AngleLocal",     name = "Local Angle",      editor = "number", default = 0,       no_edit = not_attached, dont_save = true, min = -180*60, max = 180*60, slider = true, scale = "deg" },
		{ category = "Child", id = "AxisLocal",      name = "Local Axis",       editor = "point",  default = axis_z,  no_edit = not_attached, dont_save = true },
	},
}

ComponentAttach.SetAngleLocal = CObject.SetAngle
ComponentAttach.SetAxisLocal = CObject.SetAxis

DefineClass.StripComponentAttachProperties = {
	__parents = { "ComponentAttach" },
	properties = {
		{ id = "AttachOffset",   },
		{ id = "AttachAxis",     },
		{ id = "AttachAngle",    },
		{ id = "AttachSpotName", },
		{ id = "Parent",         },
	},
}

function ComponentAttach:GetAttachSpotName()
	local parent = self:GetParent()
	return parent and parent:GetSpotName(self:GetAttachSpot())
end

DefineClass.ComponentCustomData = {
	__parents = { "CObject" },
	flags = { cofComponentCustomData = true },
	-- when inheriting ComponentCustomData from multiple parents you have to:
	-- 1. review if its use is not conflicting
	-- 2. add member CustomDataType = "<class-name>" to suppress the class system error
	
	GetCustomData = _GetCustomData,
	SetCustomData = _SetCustomData,
	GetCustomString = _GetCustomString,
	SetCustomString = _SetCustomString,
}

if Platform.developer then
function OnMsg.ClassesPreprocess(classdefs)
	for name, class in pairs(classdefs) do
		if table.find(class.__parents, "ComponentCustomData") then
			if not class.CustomDataType then
				class.CustomDataType = name
			end
		end
	end
end
end

function SpecialOrientationItems()
	local SpecialOrientationNames = { "soTerrain", "soTerrainLarge", "soFacing", "soFacingY", "soFacingVertical", "soVelocity", "soZOffset", "soTerrainPitch", "soTerrainPitchLarge" }
	table.sort(SpecialOrientationNames)
	local items = {}
	for i, name in ipairs(SpecialOrientationNames) do
		items[i] = { text = name, value = const[name] }
	end
	table.insert(items, 1, { text = "", value = const.soNone })
	return items
end

DefineClass.ComponentExtraTransform = {
	__parents = { "CObject" },
	flags = { cofComponentExtraTransform = true },
	properties = {
		{ id = "SpecialOrientation", name = "Special Orientation", editor = "choice", default = const.soNone, items = SpecialOrientationItems },
	},
}

DefineClass.ComponentInterpolation = {
	__parents = { "CObject" },
	flags = { cofComponentInterpolation = true },
}

DefineClass.ComponentCurvature = {
	__parents = { "CObject" },
	flags = { cofComponentCurvature = true },
}

DefineClass.ComponentAnim = {
	__parents = { "CObject" },
	flags = { cofComponentAnim = true },
}

DefineClass.ComponentSound = {
	__parents = { "CObject" },
	flags = { cofComponentSound = true },
	properties = {
		{ category = "Sound", id = "SoundBank",     name = "Bank",     editor = "preset_id",  default = "", preset_class = "SoundPreset", dont_save = true },
		{ category = "Sound", id = "SoundType",     name = "Type",     editor = "preset_id",  default = "", preset_class = "SoundTypePreset", dont_save = true, read_only = true },
		{ category = "Sound", id = "Sound",         name = "Sample",   editor = "text",       default = "", dont_save = true, read_only = true },
		{ category = "Sound", id = "SoundDuration", name = "Duration", editor = "number",     default = -1, dont_save = true, read_only = true },
		{ category = "Sound", id = "SoundHandle",   name = "Handle",   editor = "number",     default = -1, dont_save = true, read_only = true },
	},
}

function ComponentSound:GetSoundBank()
	local sname, sbank, stype, shandle, sduration, stime = self:GetSound()
	return sbank or ""
end
function ComponentSound:GetSoundType()
	local sname, sbank, stype, shandle, sduration, stime = self:GetSound()
	return stype or ""
end
function ComponentSound:GetSoundHandle()
	local sname, sbank, stype, shandle, sduration, stime = self:GetSound()
	return shandle or -1
end
function ComponentSound:GetSoundDuration()
	local sname, sbank, stype, shandle, sduration, stime = self:GetSound()
	return sduration or -1
end