config/picture_io.yml
config/license.yml
config/speech_balloon.yml
+config/element.yml
config/profile.json
config/test_layout
lib/test/temp/
class GroundColor < ActiveRecord::Base
+ include Element
include ElementInspire
belongs_to :panel
belongs_to :color
end
end
+ def self.list_opt_for_panel
+ {
+ :ground_colors => {
+ }
+ }
+ end
+
+ def self.show_opt_for_panel
+ {
+ :ground_colors => {
+ }
+ }
+ end
+
+ def self.json_opt_for_panel
+ {
+ }
+ end
+
+ def self.has_picture?
+ false
+ end
+
def supply_default
self.code ||= 0
if self.panel
class GroundPicture < ActiveRecord::Base
+ include Element
include ElementInspire
belongs_to :panel
belongs_to :picture
end
end
+ def self.list_opt_for_panel
+ {
+ :ground_pictures => {
+ :picture => {:artist => {}, :license => {}}
+ }
+ }
+ end
+
+ def self.show_opt_for_panel
+ {
+ :ground_pictures => {
+ :picture => {:artist => {}, :license => {}}
+ }
+ }
+ end
+
+ def self.json_opt_for_panel
+ {
+ :picture => {:artist => {}, :license => {}}
+ }
+ end
+
+ def self.has_picture?
+ true
+ end
+
def supply_default
self.x = 0
self.y = 0
end
end
+ def self.each_element_class_names
+ Pettanr::Application.elements.each do |k, n|
+ yield k
+ end
+ end
+
+ def self.class_name_to_class k
+ Object.const_get k
+ end
+
+ def self.each_element_classes
+ self.each_element_class_names do |k|
+ e = self.class_name_to_class k
+ yield e
+ end
+ end
+
+ def elements_by_class_name class_name
+ self.__send__ class_name.tableize
+ end
+
def supply_default
self.border = 2
self.publish = 0
end
def self.list_opt
- {
- :panel_pictures => {
- :picture => {:artist => {}, :license => {}}
- },
- :speech_balloons => {:balloon => {}, :speech => {}},
- :ground_pictures => {
- :picture => {:artist => {}, :license => {}}
- },
- :ground_colors => {
- },
+ r = {
:author => {}
}
+ self.each_element_classes do |e|
+ r.merge!(e.list_opt_for_panel)
+ end
+ r
end
def self.show rid, roles
end
def self.show_opt
- {:include => {
- :panel_pictures => {
- :picture => {:artist => {}, :license => {}}
- },
- :speech_balloons => {:balloon => {}, :speech => {}},
- :ground_pictures => {
- :picture => {:artist => {}, :license => {}}
- },
- :ground_colors => {
- },
+ r = {
:author => {}
- }}
+ }
+ self.each_element_classes do |e|
+ r.merge!(e.show_opt_for_panel)
+ end
+ {:include => r}
end
def parts_element
- ((self.panel_pictures || []) + (self.speech_balloons || []) + (self.ground_colors || []) + (self.ground_pictures || [])).compact
- end
-
- def parts
+ r = []
+ self.class.each_element_class_names do |k|
+ r += (self.elements_by_class_name(k) || [])
+ end
+ r
end
def zorderd_elements
res
end
- @@elm_json_opt = {
- 'PanelPicture' => {
- :picture => {:artist => {}, :license => {}}
- },
- 'SpeechBalloon' => {:balloon => {}, :speech => {}},
- 'GroundPicture' => {
- :picture => {:artist => {}, :license => {}}
- },
- 'GroundColor' => {
- },
- }
-
- def self.elm_json_opt e
- @@elm_json_opt[e.class.to_s]
- end
-
def elements
self.panel_elements.map {|e|
#(-_-;)<... kore wa hidoi
- JSON.parse e.to_json({:include => Panel.elm_json_opt(e)})
+ JSON.parse e.to_json({:include => e.class.json_opt_for_panel})
}
end
def licensed_pictures
r = {}
- ((self.panel_pictures || []) + (self.ground_pictures || [])).compact.each do |elm|
+ self.panel_elements.each do |elm|
+ next unless elm.class.has_picture?
r[elm.picture_id] = elm.picture unless r[elm.picture_id]
end
r
end
def validate_serial_list
+ l = []
+ self.class.each_element_class_names do |k|
+ l << self.elements_by_class_name(k)
+ end
[
- {:elements => [self.panel_pictures, self.speech_balloons, self.ground_colors, self.ground_pictures], :name => :t, :offset => 0},
- {:elements => [self.panel_pictures, self.speech_balloons, self.ground_colors, self.ground_pictures], :name => :z, :offset => 1}
+ {:elements => l, :name => :t, :offset => 0},
+ {:elements => l, :name => :z, :offset => 1}
]
end
def validate_child
class PanelPicture < ActiveRecord::Base
+ include Element
include ElementInspire
belongs_to :panel
belongs_to :picture
end
end
+ def self.list_opt_for_panel
+ {
+ :panel_pictures => {
+ :picture => {:artist => {}, :license => {}}
+ }
+ }
+ end
+
+ def self.show_opt_for_panel
+ {
+ :panel_pictures => {
+ :picture => {:artist => {}, :license => {}}
+ }
+ }
+ end
+
+ def self.json_opt_for_panel
+ {
+ :picture => {:artist => {}, :license => {}}
+ }
+ end
+
+ def self.has_picture?
+ true
+ end
+
def visible? roles
if MagicNumber['run_mode'] == 0
return false unless guest_role_check(roles)
class SpeechBalloon < ActiveRecord::Base
+ include Element
include ElementInspire
has_one :balloon, :dependent => :destroy
has_one :speech, :dependent => :destroy
end
end
+ def self.list_opt_for_panel
+ {
+ :speech_balloons => {:balloon => {}, :speech => {}}
+ }
+ end
+
+ def self.show_opt_for_panel
+ {
+ :speech_balloons => {:balloon => {}, :speech => {}}
+ }
+ end
+
+ def self.json_opt_for_panel
+ {
+ :balloon => {}, :speech => {}
+ }
+ end
+
+ def self.has_picture?
+ false
+ end
+
def supply_default
if self.panel
self.t = self.panel.new_t
def self.licenses
@@licenses || {}
end
-
+
def self.speech_balloons=(ary)
@@speech_balloons = ary
end
def self.speech_balloons
@@speech_balloons || {}
end
- end
+
+ def self.elements=(ary)
+ @@elements = ary
+ end
+
+ def self.elements
+ @@elements || {}
+ end
+ end
end
Pettanr::Application.licenses = YAML.load(open(Rails.root + 'config/license.yml').read)
Pettanr::Application.speech_balloons = YAML.load(open(Rails.root + 'config/speech_balloon.yml').read)
+Pettanr::Application.elements = YAML.load(open(Rails.root + 'config/element.yml').read)
MagicNumber = YAML.load(open(Rails.root + 'config/magic_number.yml').read)
MagicNumber['test_layout'] = if File.exist? Rails.root + 'config/test_layout'
'test'
--- /dev/null
+ PanelPicture: panel_pictures
+ SpeechBalloon: speech_balloons
+ GroundPicture: ground_pictures
+ GroundColor: ground_colors
require 'ar_helper'
require 'import_result'
require 'common'
+require 'element'
+require 'element'
Pettanr::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
--- /dev/null
+module Element
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.__send__ :include, InstanceMethods
+ end
+
+ module ClassMethods
+ def list_opt_for_panel
+ {}
+ end
+
+ def show_opt_for_panel
+ {}
+ end
+
+ def json_opt_for_panel
+ {}
+ end
+ end
+
+ module InstanceMethods
+ private
+
+ public
+
+ def has_picture?
+ false
+ end
+
+ end
+end
+
r.include?(@gp).should be_true\r
end\r
end\r
- describe 'コマ部品に於いて' do\r
- before do\r
- end\r
- context 'つつがなく終わるとき' do\r
- it 'コマ部品集合を利用している' do\r
- r = @panel.parts\r
- end\r
- end\r
- it 'リストを返している' do\r
- r = @panel.parts\r
- end\r
- end\r
\r
describe 'z順コマ部品に於いて' do\r
before do\r
end\r
context 'つつがなく終わるとき' do\r
it 'コマ部品を利用している' do\r
- Panel.any_instance.stub(:parts).with(any_args).and_return([])\r
- Panel.any_instance.should_receive(:parts).with(any_args).exactly(1)\r
+ Panel.any_instance.stub(:parts_element).with(any_args).and_return([])\r
+ Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)\r
r = @panel.panel_elements\r
end\r
end\r
end\r
context 'つつがなく終わるとき' do\r
before do\r
- Panel.stub(:elm_json_opt).with(@pp).and_return({})\r
- Panel.stub(:elm_json_opt).with(@sb).and_return({})\r
- Panel.stub(:elm_json_opt).with(@gp).and_return({})\r
- Panel.stub(:elm_json_opt).with(@gc).and_return({})\r
+ PanelPicture.stub(:json_opt_for_panel).and_return({})\r
+ SpeechBalloon.stub(:json_opt_for_panel).and_return({})\r
+ GroundPicture.stub(:json_opt_for_panel).and_return({})\r
+ GroundColor.stub(:json_opt_for_panel).and_return({})\r
end\r
- it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do\r
- Panel.should_receive(:elm_json_opt).with(@pp).exactly(1)\r
+ it 'コマ絵にjson出力オプションを依頼している' do\r
+ PanelPicture.should_receive(:json_opt_for_panel).exactly(1)\r
r = @panel.elements\r
end\r
- it 'ã\82³ã\83\9eè¦\81ç´ ã\81®jsonå\87ºå\8a\9bã\82ªã\83\97ã\82·ã\83§ã\83³ã\81«ã\83\95ã\82ã\83\80ã\82·json出力オプションを依頼している' do\r
- Panel.should_receive(:elm_json_opt).with(@sb).exactly(1)\r
+ it 'ã\83\95ã\82ã\83\80ã\82·ã\81«json出力オプションを依頼している' do\r
+ SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1)\r
r = @panel.elements\r
end\r
- it 'コマ要素のjson出力オプションに絵地json出力オプションを依頼している' do\r
- Panel.should_receive(:elm_json_opt).with(@gp).exactly(1)\r
+ it '絵地にjson出力オプションを依頼している' do\r
+ GroundPicture.should_receive(:json_opt_for_panel).exactly(1)\r
r = @panel.elements\r
end\r
- it 'コマ要素のjson出力オプションに色地json出力オプションを依頼している' do\r
- Panel.should_receive(:elm_json_opt).with(@gc).exactly(1)\r
+ it '色地にjson出力オプションを依頼している' do\r
+ GroundColor.should_receive(:json_opt_for_panel).exactly(1)\r
r = @panel.elements\r
end\r
end\r