configurable buddy types!!!
This commit is contained in:
parent
d2ed057df3
commit
e558a8531b
|
@ -99,4 +99,20 @@ module Funfriend
|
|||
SoundMan.play_sound("assets/sfx/talk_god#{(1..8).sample}.ogg")
|
||||
end
|
||||
end
|
||||
|
||||
BUDDIES = {
|
||||
"funfriend" => FunfriendBuddy,
|
||||
"catfriend" => CatfriendBuddy,
|
||||
"god" => GodBuddy,
|
||||
}
|
||||
|
||||
def self.make_buddy(name : String) : Buddy
|
||||
buddy_type = BUDDIES[name]?
|
||||
|
||||
if buddy_type
|
||||
return buddy_type.new
|
||||
else
|
||||
raise IndexError.new(message: "Invalid buddy type \"#{name}\". Supported buddies: #{BUDDIES.keys.map { |k| "\"#{k}\""} .join(", ")}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,10 @@ module Funfriend::ConfigMan
|
|||
},
|
||||
"sound" => {
|
||||
"volume" => 0.2.as(ConfigValue)
|
||||
}
|
||||
},
|
||||
"buddies" => {
|
||||
"types" => "funfriend".as(ConfigValue)
|
||||
},
|
||||
}.as(Config)
|
||||
|
||||
def get_config_path : Path
|
||||
|
|
|
@ -35,7 +35,9 @@ module Funfriend
|
|||
end
|
||||
|
||||
def self.init_contexts
|
||||
add_context(BuddyContext.new(FunfriendBuddy.new))
|
||||
ConfigMan.config["buddies"]["types"].as(String).split(",").each do |buddy_name|
|
||||
add_context(BuddyContext.new(make_buddy(buddy_name)))
|
||||
end
|
||||
@@main_context = @@contexts[0]
|
||||
at_exit { contexts.each &.destroy }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue