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
|
# File 'lib/obf/sfy.rb', line 2
def self.to_external(path)
boards = []
images = []
sounds = []
plist = CFPropertyList::List.new(:file => path)
data = CFPropertyList.native_types(plist.value)
top = data['$top']['root']
list = data['$objects'][top]
items = {
'strings' => {},
'buttons' => []
}
board_ids = []
images = []
data['$objects'].each_with_index do |item, idx|
if item.is_a?(String)
items['strings'][idx] = item
elsif item.is_a?(Hash) && item['mScreen']
item['word'] = data['$objects'][item['wordKey']] if item['wordKey']
item['symbol'] = data['$objects'][item['imageName']] if item['imageName']
board_ids[item['mScreen']] = true
items['buttons'] << item
else
end
end
image_counter = 0
board_ids.each_with_index do |present, idx|
if present
name = "HOME"
if idx > 0
if boards[0]
name = boards[0]['buttons'][idx - 1]['label']
else
name = "Screen #{idx}"
end
end
raw_buttons = items['buttons'].select{|b| b['mScreen'] == idx }
buttons = []
rows = 0
columns = 0
raw_buttons.each do |b|
rows = [rows, b['mRow']].max
columns = [columns, b['mColumn']].max
end
rows += 1
columns += 1
grid = {
'rows' => rows,
'columns' => columns,
'order' => []
}
button_counter = 0
rows.times do |i|
grid['order'][i] = []
columns.times do |j|
grid['order'][i][j] = nil
raw_button = raw_buttons.detect{|b| b['mRow'] == i && b['mColumn'] == j }
colors = {
0 => 'rgb(255, 255, 255)', 1 => 'rgb(255, 0, 0)', 3 => 'rgb(255, 112, 156)', 2 => 'rgb(255, 115, 222)', 4 => 'rgb(250, 196, 140)', 5 => 'rgb(255, 196, 87)', 6 => 'rgb(255, 234, 117)', 7 => 'rgb(255, 241, 92)', 8 => 'rgb(252, 242, 134)', 9 => 'rgb(82, 209, 86)', 10 => 'rgb(149, 189, 42)', 11 => 'rgb(161, 245, 113)', 12 => 'rgb(196, 252, 141)', 13 => 'rgb(94, 207, 255)', 14 => 'rgb(148, 223, 255)', 15 => 'rgb(176, 223, 255)', 16 => 'rgb(194, 241, 255)', 17 => 'rgb(118, 152, 199)', 18 => 'rgb(208, 190, 232)', 19 => 'rgb(153, 79, 0)', 20 => 'rgb(0, 109, 235)', 21 => 'rgb(0, 0, 0)', 22 => 'rgb(161, 161, 161)', 23 => 'rgb(255, 108, 59)', }
if raw_button
image_id = nil
if raw_button['symbol']
if raw_button['symbol'].match(/-/)
else
images << {
'id' => image_counter,
'symbol' => {
'set' => 'sfy',
'name' => raw_button['symbol']
}
}
image_id = image_counter
image_counter += 1
end
end
button = {
'id' => button_counter,
'label' => raw_button['word'],
'background_color' => colors[raw_button['backgroundColorID']],
'image_id' => image_id,
'hidden' => !raw_button['isOpen'],
'ext_sfy_isLinked' => raw_button['isLinked'],
'ext_sfy_isProtected' => raw_button['isProtected'],
'ext_sfy_backgroundColorID' => raw_button['backgroundColorID']
}
if raw_button['customLabel'] && data['$objects'][raw_button['customLabel']] && data['$objects'][raw_button['customLabel']] != ""
button['vocalization'] = button['label']
button['label'] = data['$objects'][raw_button['customLabel']]
end
if idx == 0 && raw_button['isLinked'] && board_ids[button_counter + 1]
button['load_board'] = {
'id' => (button_counter + 1).to_s
}
end
grid['order'][i][j] = button['id']
buttons << button
end
button_counter += 1
end
end
board = {
'id' => idx.to_s,
'name' => name,
'buttons' => buttons,
'grid' => grid,
'ext_sfy_screen' => idx
}
boards << board
end
end
return {
'boards' => boards,
'images' => images,
'sounds' => []
}
end
|