configurable buddy types!!!

This commit is contained in:
Jill 2023-06-02 13:44:00 +03:00
parent d2ed057df3
commit e558a8531b
Signed by: oat
GPG Key ID: 33489AA58A955108
3 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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