2 class SpeechBalloonTemplate < Peta::SystemResource
4 has_many :speech_balloons
5 belongs_to :system_picture
7 validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
8 validates :classname, :presence => true, :length => {:maximum => 50}
9 validates :caption, :presence => true, :length => {:maximum => 30}
10 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
11 validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
12 validates :settings, :presence => true
18 self.t = SpeechBalloonTemplate.count.to_i if self.new_record?
22 self.system_picture.tmb_opt_img_tag
29 def self.list_json_opt
37 def self.show_json_opt
41 def self.store name, attr
42 #settingsにはHashデータが丸っと文字列化されて入る
43 r = SpeechBalloonTemplate.replace_system_picture(attr || {})
44 attr["settings"] = r["settings"] ? r["settings"].to_json : nil
45 r = SpeechBalloonTemplate.modify_object name, attr
52 @template_settings ||= JSON.parse(self.settings)
55 def my_engine_resource
56 Manifest.manifest.system_resources.engine_resources['speech_balloon_templates']
60 self.my_engine_resource.resource_items[self.classname]
64 self.my_engine_resource.resource_items.include? self.classname
67 def engine_module_name
68 self.engine_name.camelize
72 Object.const_get self.engine_module_name
75 def engine_speech_balloon_model
76 engine.const_get 'SpeechBalloon'
79 def engine_speech_balloon_module
80 engine.const_get 'SpeechBalloonModule'
83 def engine_extend_module
87 def engine_balloon_model
88 engine.const_get 'Balloon'
91 def engine_balloon_module
92 engine.const_get 'BalloonModule'
95 def engine_speech_model
96 engine.const_get 'Speech'
99 def engine_speech_module
100 engine.const_get 'SpeechModule'
103 def self.import filename
104 SpeechBalloonTemplate.import_file(filename) {|name, attr| SpeechBalloonTemplate.store(name, attr)}
107 def self.disp_import_error r
109 puts "json file error. file does not exist or broken"
113 put sbt.errors.full_messages