Ok this is the actual inital code... need to convert from mongo to sqlite...
This commit is contained in:
parent
8c856ce465
commit
8fa1664bcb
13 changed files with 1168 additions and 0 deletions
50
entity_factory.rb
Normal file
50
entity_factory.rb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue