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
|
# File 'lib/procon_bypass_man/web/setting_parser/top_level_layer.rb', line 15
def to_hash_group_by_button
h = { prefix_keys_for_changing_layer: prefix_keys_for_changing_layer || [] }
h[:layers] ||= {}
@layers.each do |key, layer|
h[:layers][key] ||= {}
next if layer.nil?
if !@installed_plugin[:macros].empty?
h[:installed_macros] = @installed_plugin[:macros]
end
if !@installed_plugin[:modes].empty?
h[:installed_modes] = @installed_plugin[:modes]
end
layer.to_hash.dig(:flip)&.each do |button, value|
h[:layers][key][button] ||= {}
h[:layers][key][button][:open] = true
h[:layers][key][button][:flip] ||= {}
h[:layers][key][button][:flip][:enable] = true
if value
h[:layers][key][button][:flip].merge!(value)
end
end
if layer.to_hash.dig(:macro)
h[:layers][key][:macro] = []
if(macros = layer.to_hash.dig(:macro))
macros.transform_values! { |x| x[:if_pressed] }
h[:layers][key][:macro] = macros
end
end
if layer.to_hash.dig(:mode)
h[:layers][key][:mode] = { layer.to_hash.dig(:mode) => true }
end
layer.to_hash.dig(:remap)&.each do |button, value|
h[:layers][key][button] ||= {}
h[:layers][key][button][:remap] ||= {}
h[:layers][key][button][:open] = true
if value
h[:layers][key][button][:remap].merge!(value)
end
end
end
h
end
|