2010-06-09 19:56:47 -07:00
|
|
|
class Zone < StaticResource
|
2010-06-22 09:42:25 -07:00
|
|
|
AttributeNames = ['id', 'label', 'depth', 'type_id']
|
|
|
|
ItemZoneSets = {}
|
2010-06-09 19:56:47 -07:00
|
|
|
|
|
|
|
attr_reader *AttributeNames
|
2010-09-08 19:49:39 -07:00
|
|
|
# When selecting zones that an asset occupies, we allow the zone to set
|
|
|
|
# whether or not the zone is "sometimes" occupied. This is false by default.
|
|
|
|
attr_writer :sometimes
|
2010-06-09 19:56:47 -07:00
|
|
|
|
|
|
|
def initialize(attributes)
|
|
|
|
AttributeNames.each do |name|
|
|
|
|
instance_variable_set "@#{name}", attributes[name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-08 19:49:39 -07:00
|
|
|
def uncertain_label
|
|
|
|
@sometimes ? "#{label} sometimes" : label
|
|
|
|
end
|
|
|
|
|
2012-10-08 19:20:18 -07:00
|
|
|
def self.find_set(name)
|
|
|
|
ItemZoneSets[plain(name)]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.plain(name)
|
|
|
|
name.delete('\- /').downcase
|
|
|
|
end
|
|
|
|
|
2010-06-09 19:56:47 -07:00
|
|
|
n = 0
|
|
|
|
@objects = YAML.load_file(Rails.root.join('config', 'zones.yml')).map do |a|
|
|
|
|
a['id'] = (n += 1)
|
2010-06-22 09:42:25 -07:00
|
|
|
obj = new(a)
|
|
|
|
if obj.type_id == 2 || obj.type_id == 3
|
2012-10-08 19:20:18 -07:00
|
|
|
plain_name = plain(obj.label)
|
|
|
|
|
|
|
|
ItemZoneSets[plain_name] ||= []
|
|
|
|
ItemZoneSets[plain_name] << obj
|
2010-06-22 09:42:25 -07:00
|
|
|
end
|
|
|
|
obj
|
2010-06-09 19:56:47 -07:00
|
|
|
end
|
|
|
|
n = nil
|
2012-10-08 19:20:18 -07:00
|
|
|
|
|
|
|
# Add aliases to keys like "lowerforegrounditem" to "lowerforeground"
|
|
|
|
# ...unless there's already such a key, like "backgrounditem" to "background",
|
|
|
|
# in which case we don't, because that'd be silly.
|
|
|
|
ItemZoneSets.keys.each do |name|
|
|
|
|
if name.end_with?('item')
|
|
|
|
stripped_name = name[0..-5]
|
|
|
|
ItemZoneSets[stripped_name] ||= ItemZoneSets[name]
|
|
|
|
end
|
|
|
|
end
|
2010-05-20 16:04:56 -07:00
|
|
|
end
|