volume setting

This commit is contained in:
Jill 2023-06-01 16:36:10 +03:00
parent ef5325bbf2
commit be3e13794e
Signed by: oat
GPG Key ID: 33489AA58A955108
2 changed files with 11 additions and 3 deletions

View File

@ -8,13 +8,16 @@ module Funfriend::ConfigMan
CONFIG_NAME = "cfg.ini"
alias ConfigValue = String | Int32 | Bool
alias ConfigValue = String | Int32 | Bool | Float64
alias ConfigSection = Hash(String, ConfigValue)
alias Config = Hash(String, ConfigSection)
DEFAULT_CONFIG = {
"window" => {
"funfriend_size" => 64.as(ConfigValue)
},
"sound" => {
"volume" => 0.2.as(ConfigValue)
}
}.as(Config)
@ -59,8 +62,9 @@ module Funfriend::ConfigMan
when String
value
when Int32
puts "huh"
value.to_i32?
when Float64
value.to_f64?
when Bool
value === "1" || value.downcase === "true"
end
@ -70,9 +74,13 @@ module Funfriend::ConfigMan
# write to config
@@config[sect_i][key] = casted_val.not_nil!
end
else
# keep as a string just incase it's ever needed
@@config[sect_i][key] = value
end
end
end
File.write(config_file, INI.build(@@config))
end
@@config_initialized = true

View File

@ -20,6 +20,6 @@ module Funfriend::SoundMan
SDL::Mix.init(SDL::Mix::Init::OGG); at_exit { SDL::Mix.quit }
SDL::Mix.open
SDL::Mix::Channel.volume = SDL::Mix::MAX_VOLUME // 5
SDL::Mix::Channel.volume = SDL::Mix::MAX_VOLUME * ConfigMan.config["sound"]["volume"].as(Float64)
end
end