+ validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
+ validates :module_name, :presence => true, :length => {:maximum => 50}
+ validates :caption, :presence => true, :length => {:maximum => 30}
+ validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :settings, :presence => true
+
+ scope :find_index, -> do
+ self
+ end
+
+ scope :find_by_original_picture, -> (original_picture_id) do
+ find_index.where(original_picture_id: original_picture_id)
+ end
+
+ scope :with_panels, -> do
+ includes(speech_balloons: panel)
+ end
+
+ scope :find_by_panel, -> (panel_id) do
+ with_panels.where(Panel.arel_table[:id].eq panel_id).references(:panel)
+ end
+
+ scope :find_by_system_picture, -> (system_picture_id) do
+ find_index.where(system_picture_id: system_picture_id)
+ end
+
+ def supply_default
+ end
+
+ def overwrite
+ self.t = SpeechBalloonTemplate.count.to_i if self.new_record?
+ end
+
+ def symbol_option
+ self.system_picture.tmb_opt_img_tag
+ end
+
+ def self.show_opt
+ {}
+ end
+
+ def parsed_settings
+ @parsed_settings ||= JSON.parse(self.settings)
+ end
+
+ def self.store name, attr
+ #settingsにはHashデータが丸っと文字列化されて入る
+ r = SpeechBalloonTemplate.replace_system_picture(attr || {})
+ attr["settings"] = r["settings"] ? r["settings"].to_json : nil
+ r = SpeechBalloonTemplate.modify_object name, attr
+ r.overwrite
+ r.save
+ r