load "entities/entity.rb" load "entities/player.rb" load "entities/monster.rb" load "entities/boss.rb" load "entities/random_event.rb" class EntityFactory @mc = nil def initialize(mc) @mc = mc end # Convert the symbol into a class. There might be a way to automate this better... # Make sure to load the class if you're adding a new one here. def get_ent_class(type) ent_class = nil case type when :player ent_class = Player when :monster ent_class = Monster when :boss ent_class = Boss when :random_event ent_class = RandomEvent end return ent_class end # get a new entity if doc is nil, otherwise load from that doc def get(type, doc=nil) return get_ent_class(type).new(@mc, doc) end # try to load an object instance of an entity based on the doc def build_instance(doc) if doc['type'] != nil then return get_ent_class(doc['type']).new(@mc, doc) else return nil end end def run_query(filter={}) return @mc.collection().find(filter) end end