-
Notifications
You must be signed in to change notification settings - Fork 482
/
calc.rb
75 lines (70 loc) · 2.08 KB
/
calc.rb
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
# == Schema Information
#
# Table name: levels
#
# id :integer not null, primary key
# game_id :integer
# name :string(255) not null
# created_at :datetime
# updated_at :datetime
# level_num :string(255)
# ideal_level_source_id :integer
# solution_level_source_id :integer
# user_id :integer
# properties :text(65535)
# type :string(255)
# md5 :string(255)
# published :boolean default(FALSE), not null
# notes :text(65535)
#
# Indexes
#
# index_levels_on_game_id (game_id)
# index_levels_on_name (name)
#
class Calc < Blockly
serialized_attrs %w(
free_play
input_output_table
)
# List of possible skins, the first is used as a default.
def self.skins
['calc']
end
def self.create_from_level_builder(params, level_params)
create!(
level_params.merge(
user: params[:user],
game: Game.calc,
level_num: 'custom',
properties: {
solution_blocks: params[:program] || '',
toolbox_blocks: "<xml>#{toolbox}</xml>",
use_contract_editor: true
}
)
)
end
def self.toolbox
<<-XML.strip_heredoc.chomp
<category name="Number">
<block type="functional_plus"></block>
<block type="functional_minus"></block>
<block type="functional_times"></block>
<block type="functional_dividedby"></block>
<block type="functional_math_number"></block>
<block type="functional_math_number_dropdown">
<title name="NUM" config="0,1,2,3,4,5,6,7,8,9,10">???</title>
</block>
<block type="functional_sqrt"></block>
<block type="functional_squared"></block>
<block type="functional_pow"></block>
</category>
<category name="Functions" custom="PROCEDURE" />
<category name="Variables" custom="FUNCTIONAL_VARIABLE" />
XML
end
def toolbox(type)
Calc.toolbox
end
end