File size: 6,411 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
-- ========== GENERATED BY ClassDef Editor (Ctrl-Alt-F3) DO NOT EDIT MANUALLY! ==========

DefineClass.AnimComponentWeight = {
	__parents = { "PropertyObject", },
	__generated_by_class = "ClassDef",

	properties = {
		{ id = "AnimComponent", 
			editor = "preset_id", default = false, preset_class = "AnimComponent", },
		{ id = "BlendAfterChannel", help = "If false, the component will execute on the channel animation, if true, it will execute after the channel has beel blended with all before it.", 
			editor = "bool", default = false, },
	},
}

DefineClass.AnimLimbData = {
	__parents = { "PropertyObject", },
	__generated_by_class = "ClassDef",

	properties = {
		{ id = "fit_bone", help = "Bone name to be fit to target", 
			editor = "text", default = false, },
		{ id = "joint_bone", 
			editor = "text", default = false, },
		{ id = "joint_companion_bone", 
			editor = "text", default = false, },
		{ id = "top_bone", 
			editor = "text", default = false, },
		{ id = "top_companion_bone", 
			editor = "text", default = false, },
		{ id = "fit_normal", help = "Local bone space normal direction to be fit to target", 
			editor = "point", default = point(0, 1000, 0), },
		{ id = "fit_offset", help = "Local bone space position offset to be fit to target", 
			editor = "point", default = point(0, 0, 0), },
		{ id = "joint_axis", help = "Local bone space joint axis direction", 
			editor = "point", default = point(0, 0, 1000), },
	},
}

DefineClass.CommonGameSettings = {
	__parents = { "InitDone", },
	__generated_by_class = "ClassDef",

	properties = {
		{ category = "Modifiers", id = "game_difficulty", name = T(607013881337, --[[ClassDef Default CommonGameSettings name]] "Game difficulty"), 
			editor = "preset_id", default = false, preset_class = "GameDifficultyDef", },
		{ category = "Modifiers", id = "seed_text", name = T(968127954818, --[[ClassDef Default CommonGameSettings name]] "Seed"), help = T(657915341595, --[[ClassDef Default CommonGameSettings help]] "Text used to generate seed. If empty a random (async) seed will be used."), 
			editor = "text", default = "", },
		{ category = "Modifiers", id = "game_rules", name = T(567633276594, --[[ClassDef Default CommonGameSettings name]] "Game Rules"), 
			editor = "prop_table", default = false, },
		{ category = "Modifiers", id = "forced_game_rules", name = T(957452987296, --[[ClassDef Default CommonGameSettings name]] "Forced game rules"), help = T(745042998514, --[[ClassDef Default CommonGameSettings help]] "If a rule is set to true, it is force enabled, false means force disabled."), 
			editor = "prop_table", default = false, dont_save = true, no_edit = true, },
	},
	StoreAsTable = true,
	id = false,
	save_id = false,
	loaded_from_id = false,
}

function CommonGameSettings:Init()
	self.id = self.id or random_encode64(96)
	
	local difficulty = table.get(Presets, "GameDifficultyDef", 1) or empty_table
	difficulty = difficulty[(#difficulty + 1) / 2]
	self.game_difficulty = self.game_difficulty or difficulty and difficulty.id or nil
	
	self.game_rules = self.game_rules or {}
	self.forced_game_rules = self.forced_game_rules or {}
	ForEachPreset("GameRule", function(rule)
		if rule.init_as_active then
			self:AddGameRule(rule.id)
		end
	end)
end

function CommonGameSettings:ToggleListValue(prop_id, item_id)
	if prop_id == "game_rules" then
		self:ToggleGameRule(item_id)
		return
	end
	local value = self[prop_id]
	if value[item_id] then
		value[item_id] = nil
	else
		value[item_id] = true
	end
end

function CommonGameSettings:ToggleGameRule(rule_id)
	local value = self.game_rules[rule_id]
	if value then
		self:RemoveGameRule(rule_id)
	else
		self:AddGameRule(rule_id)
	end
end

function CommonGameSettings:AddGameRule(rule_id)
	if self:CanAddGameRule(rule_id) then
		self.game_rules[rule_id] = true
	end
end

function CommonGameSettings:RemoveGameRule(rule_id)
	if self:CanRemoveGameRule(rule_id) then
		self.game_rules[rule_id] = nil
	end
end

function CommonGameSettings:SetForceEnabledGameRule(rule_id, set)
	if set then
		self:AddGameRule(rule_id)
	else
		self:RemoveGameRule(rule_id)
	end
	self.forced_game_rules[rule_id] = set and true or nil
end

function CommonGameSettings:SetForceDisabledGameRule(rule_id, set)
	if set then
		self:RemoveGameRule(rule_id)
	end
	if set then
		self.forced_game_rules[rule_id] = false
	else
		self.forced_game_rules[rule_id] = nil
	end
end

function CommonGameSettings:CanAddGameRule(rule_id)
	if self.forced_game_rules[rule_id] == false then
		return
	end
	local rule = GameRuleDefs[rule_id]
	return not self:IsGameRuleActive(rule_id) and rule and rule:IsCompatible(self.game_rules)
end

function CommonGameSettings:CanRemoveGameRule(rule_id)
	return self.forced_game_rules[rule_id] == nil
end

function CommonGameSettings:IsGameRuleActive(rule_id)
	return self.game_rules[rule_id]
end

function CommonGameSettings:CopyCategoryTo(other, category)
	for _, prop in ipairs(self:GetProperties()) do
		if prop.category == category then
			local value = self:GetProperty(prop.id)
			value = type(value) == "table" and table.copy(value) or value
			other:SetProperty(prop.id, value)
		end
	end
end

function CommonGameSettings:Clone()
	local obj = CooldownObj.Clone(self)
	obj.id = self.id or nil
	obj.save_id = self.save_id or nil
	obj.loaded_from_id = self.loaded_from_id or nil
	return obj
end

DefineClass.Explanation = {
	__parents = { "PropertyObject", },
	__generated_by_class = "ClassDef",

	properties = {
		{ id = "Text", 
			editor = "text", default = false, translate = true, },
		{ id = "Id", 
			editor = "text", default = false, },
		{ id = "ObjIsKindOf", name = "Object is of type", help = "The explanation is provided only if the parameter object inherits the specified class.", 
			editor = "combo", default = "", items = function (self) return ClassDescendantsList("PropertyObject") end, },
		{ id = "Conditions", 
			editor = "nested_list", default = false, base_class = "Condition", },
	},
	EditorView = Untranslated("Explanation: <Text>"),
}

----- Explanation 

function GetFirstExplanation(list, obj, ...)
	local IsKindOf = IsKindOf
	local EvalConditionList = EvalConditionList
	for _, explanation in ipairs(list) do
		local kind_of = explanation.ObjIsKindOf or ""
		if (kind_of == "" or IsKindOf(obj, kind_of)) and EvalConditionList(explanation.Conditions, obj, ...) then
			return explanation.Text, explanation.Id
		end
	end
	return ""
end