-
Notifications
You must be signed in to change notification settings - Fork 482
/
gamelab.rb
93 lines (84 loc) · 2.19 KB
/
gamelab.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# == 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)
#
require 'cdo/shared_constants'
class Gamelab < Blockly
before_save :update_palette
serialized_attrs %w(
free_play
text_mode_at_start
hide_animation_mode
start_in_animation_tab
all_animations_single_frame
show_d_pad
soft_buttons
submittable
data_properties
hide_view_data_button
show_debug_watch
expand_debugger
watchers_prepopulated
debugger_disabled
pause_animations_by_default
start_animations
teacher_markdown
)
# List of possible skins, the first is used as a default.
def self.skins
['gamelab']
end
# List of possible palette categories
def self.palette_categories
%w(gamelab sprites groups input control math variables functions)
end
def self.create_from_level_builder(params, level_params)
create!(
level_params.merge(
user: params[:user],
game: Game.gamelab,
level_num: 'custom',
properties: {
code_functions: JSON.parse(palette),
show_d_pad: true,
edit_code: true,
show_debug_watch: false
}
)
)
end
def xml_blocks
%w()
end
def update_palette
if code_functions.present? && code_functions.is_a?(String)
self.code_functions = JSON.parse(code_functions)
end
rescue JSON::ParserError => e
errors.add(:code_functions, "#{e.class.name}: #{e.message}")
return false
end
def self.palette
SharedConstants::GAMELAB_BLOCKS
end
end