2 class SpeechBalloonTemplate < Peta::Template
4 has_many :speech_balloons
5 belongs_to :system_picture
7 validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
8 validates :module_name, :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
14 scope :find_index, -> do
18 scope :find_by_original_picture, -> (original_picture_id) do
19 find_index.where(original_picture_id: original_picture_id)
22 scope :with_panels, -> do
23 includes(speech_balloons: panel)
26 scope :find_by_panel, -> (panel_id) do
27 with_panels.where(Panel.arel_table[:id].eq panel_id).references(:panel)
30 scope :find_by_system_picture, -> (system_picture_id) do
31 find_index.where(system_picture_id: system_picture_id)
38 self.t = SpeechBalloonTemplate.count.to_i if self.new_record?
42 self.system_picture.tmb_opt_img_tag
50 @parsed_settings ||= JSON.parse(self.settings)
53 def self.store name, attr
54 #settingsにはHashデータが丸っと文字列化されて入る
55 r = SpeechBalloonTemplate.replace_system_picture(attr || {})
56 attr["settings"] = r["settings"] ? r["settings"].to_json : nil
57 r = SpeechBalloonTemplate.modify_object name, attr
63 def self.import filename
64 SpeechBalloonTemplate.import_file(filename) {|name, attr| SpeechBalloonTemplate.store(name, attr)}
67 def self.disp_import_error r
69 puts "json file error. file does not exist or broken"
73 put sbt.errors.full_messages