+require_dependency "manifest/system_resource/engine_resource"
module Manifest
class SystemResources
+ include SystemResourceModule
def self.set_default system_resources_manifest
system_resources_manifest['engine_resources'] ||= {}
- system_resources_manifest['license_groups'] ||= {}
- system_resources_manifest['speech_balloon_templates'] ||= {}
- system_resources_manifest['writing_formats'] ||= {}
system_resources_manifest['elements'] ||= {}
system_resources_manifest['select_items'] ||= {}
- system_resources_manifest['select_items']['model_loader'] ||= {}
- system_resources_manifest['select_items']['magic_number'] ||= {}
#oh my ...
#JSON.stringify couldn't print 1.0
# 1 == 1.0 ?
#change class
- system_resources_manifest['select_items']['magic_number']['speech_font_size_items'] ||= {}
- system_resources_manifest['select_items']['magic_number']['speech_font_size_items'].each {|conf|
+ system_resources_manifest['select_items']['speech_font_size_items'] ||= {}
+ system_resources_manifest['select_items']['speech_font_size_items'].each {|conf|
conf[1] = conf[1].to_f
}
system_resources_manifest
end
- attr :engine_resources, :license_groups, :speech_balloon_templates, :writing_formats, :elements, :select_items
+ attr :engine_resources, :elements, :select_items
def initialize manifest, system_resources_manifest
@manifest = manifest
- @engine_resources = system_resources_manifest['engine_resources']
- @license_groups = system_resources_manifest['license_groups']
- @speech_balloon_templates = system_resources_manifest['speech_balloon_templates']
- @writing_formats = system_resources_manifest['writing_formats']
+ @system_resources_manifest = system_resources_manifest
+ @engine_resources = EngineResource.manager(self, @system_resources_manifest['engine_resources'])
@elements = system_resources_manifest['elements']
@select_items = system_resources_manifest['select_items']
end
+ # call after load app
+ def init
+ self.select_items_loader
+ end
+
+ def select_items_loader
+ @manifest.models.each {|model_name, model_manifest|
+ model_manifest.attributes.each {|attribute_name, attribute_manifest|
+ source_manifest = attribute_manifest.source
+ next unless source_manifest
+ next unless source_manifest.type == 'model'
+ resource_model_name = source_manifest.resource_model_name
+ resource_list_name = source_manifest.resource_list_name
+ caption = source_manifest.caption_name
+ list_group = @manifest.lists[resource_model_name]
+ raise "undefined resource model list for lists > #{resource_model_name}\n" unless list_group
+ list = list_group[resource_list_name]
+ raise "undefined resource list for lists > #{resource_model_name} > #{resource_list_name}\n" unless list
+ r = list.open nil, {}
+ @select_items[source_manifest.select_item_name] =
+ r.items.map {|item| [item.attributes[caption], item.id]}
+ }
+ }
+ end
+
end
end