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")
|
SoundMan.play_sound("assets/sfx/talk_god#{(1..8).sample}.ogg")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -18,7 +18,10 @@ module Funfriend::ConfigMan
|
||||||
},
|
},
|
||||||
"sound" => {
|
"sound" => {
|
||||||
"volume" => 0.2.as(ConfigValue)
|
"volume" => 0.2.as(ConfigValue)
|
||||||
}
|
},
|
||||||
|
"buddies" => {
|
||||||
|
"types" => "funfriend".as(ConfigValue)
|
||||||
|
},
|
||||||
}.as(Config)
|
}.as(Config)
|
||||||
|
|
||||||
def get_config_path : Path
|
def get_config_path : Path
|
||||||
|
|
|
@ -35,7 +35,9 @@ module Funfriend
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.init_contexts
|
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]
|
@@main_context = @@contexts[0]
|
||||||
at_exit { contexts.each &.destroy }
|
at_exit { contexts.each &.destroy }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue