-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsetting_init.lua
More file actions
197 lines (185 loc) · 8.82 KB
/
setting_init.lua
File metadata and controls
197 lines (185 loc) · 8.82 KB
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
195
196
197
--- @alias setting_allowed_value
--- | 'none'
--- | 'chest'
--- | 'warehouse'
--- | 'chest-warehouse'
--- | 'trashdump'
--- | 'chest-trashdump'
--- | 'warehouse-trashdump'
--- | 'chest-warehouse-trashdump'
--- @alias register_options
--- | { disable_chest?: boolean, disable_warehouse?: boolean, disable_trashdump?: boolean }
--- | { default_value?: setting_allowed_value, order?: string }
--- | { size_settings?: boolean, inventory_settings?: boolean, threshold_setting?: boolean, circuit_connection_setting?: boolean }
--- Creates a mod setting for configuring how `chest_name` should be mergeable.
--- Also allows to configure other mod settings for each chest type separately.
--- @param chest_name string Name of the mergeable chest (for example 'wooden-chest', 'iron-chest' or 'steel-chest')
--- @param options register_options | nil
function MergingChests.create_mergeable_chest_setting(chest_name, options)
options = options or {}
local allowed_values = {
'none'
}
if not options.disable_chest then
table.insert(allowed_values, 'chest')
end
if not options.disable_warehouse then
table.insert(allowed_values, 'warehouse')
end
if not options.disable_trashdump then
table.insert(allowed_values, 'trashdump')
end
if not options.disable_chest and not options.disable_warehouse then
table.insert(allowed_values, 'chest-warehouse')
end
if not options.disable_chest and not options.disable_trashdump then
table.insert(allowed_values, 'chest-trashdump')
end
if not options.disable_warehouse and not options.disable_trashdump then
table.insert(allowed_values, 'warehouse-trashdump')
end
if not options.disable_chest and not options.disable_warehouse and not options.disable_trashdump then
table.insert(allowed_values, 'chest-warehouse-trashdump')
end
if table_size(allowed_values) <= 1 then
error('All mergeable modes are disabled for '..chest_name)
end
options.size_settings = options.size_settings or MergingChests.is_mod_active(MergingChests.override_size_settings_mod_name)
options.inventory_settings = options.inventory_settings or MergingChests.is_mod_active(MergingChests.override_inventory_settings_mod_name)
local has_custom_settings = options.size_settings or options.inventory_settings or options.threshold_setting or options.circuit_connection_setting
data:extend({
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.mergeable_chest, chest_name),
type = 'string-setting',
setting_type = 'startup',
default_value = options.default_value or allowed_values[#allowed_values],
allowed_values = allowed_values,
order = (has_custom_settings and '99-' or '01-')..(options.order or chest_name)..'-01'
}
})
if options.size_settings then
data:extend({
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_width, chest_name),
type = 'int-setting',
setting_type = 'startup',
minimum_value = 2,
default_value = 10,
order = '99-'..(options.order or chest_name)..'-02'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_height, chest_name),
type = 'int-setting',
setting_type = 'startup',
minimum_value = 2,
default_value = 10,
order = '99-'..(options.order or chest_name)..'-03'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_area, chest_name),
type = 'int-setting',
setting_type = 'startup',
minimum_value = 2,
default_value = 100,
order = '99-'..(options.order or chest_name)..'-04'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.whitelist, chest_name),
type = 'string-setting',
setting_type = 'startup',
default_value = 'NxN',
allow_blank = true,
order = '99-'..(options.order or chest_name)..'-05'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.mirror_whitelist, chest_name),
type = 'bool-setting',
setting_type = 'startup',
default_value = false,
order = '99-'..(options.order or chest_name)..'-06'
}
})
end
if options.inventory_settings then
data:extend({
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.inventory_size_multiplier, chest_name),
type = 'double-setting',
setting_type = 'startup',
minimum_value = 0,
default_value = 1.0,
order = '99-'..(options.order or chest_name)..'-07'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.inventory_size_limit, chest_name),
type = 'int-setting',
setting_type = 'startup',
minimum_value = 1,
maximum_value = 65535,
default_value = 1000,
order = '99-'..(options.order or chest_name)..'-08'
},
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.inventory_type, chest_name),
type = 'string-setting',
setting_type = 'startup',
default_value = 'with_bar',
allowed_values = {
'normal',
'with_bar',
'with_filters_and_bar'
},
order = '99-'..(options.order or chest_name)..'-09'
}
})
end
if options.threshold_setting then
data:extend({
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.warehouse_threshold, chest_name),
type = 'int-setting',
setting_type = 'startup',
minimum_value = 2,
default_value = 5,
order = '99-'..(options.order or chest_name)..'-10'
}
})
end
if options.circuit_connection_setting then
data:extend({
{
name = MergingChests.chest_specific_setting_name(MergingChests.setting_names.circuit_connector_position, chest_name),
type = 'string-setting',
setting_type = 'startup',
default_value = 'center-center',
allowed_values = {
'center-center',
'right-top',
'right-middle',
'right-bottom',
'left-top',
'left-middle',
'left-bottom',
'bottom-right',
'bottom-middle',
'bottom-left'
},
order = '99-'..(options.order or chest_name)..'-11'
}
})
end
end
--- Deletes specified chest name settings. Useful for other mods which remove some type of chest
--- @param chest_name string
function MergingChests.delete_chest_name_settings(chest_name)
data.raw['string-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.mergeable_chest, chest_name)] = nil
data.raw['int-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_width, chest_name)] = nil
data.raw['int-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_height, chest_name)] = nil
data.raw['int-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.max_area, chest_name)] = nil
data.raw['string-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.whitelist, chest_name)] = nil
data.raw['bool-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.mirror_whitelist, chest_name)] = nil
data.raw['int-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.inventory_size_limit, chest_name)] = nil
data.raw['double-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.inventory_size_multiplier, chest_name)] = nil
data.raw['int-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.warehouse_threshold, chest_name)] = nil
data.raw['string-setting'][MergingChests.chest_specific_setting_name(MergingChests.setting_names.circuit_connector_position, chest_name)] = nil
end