indexing
description: "[
THIS CLASS WAS AUTO-GENERATED WITH THE COMMAND
em_settings_generator settings.xml --no-widgets
DO NOT EDIT THIS CLASS
Settings that can be accessed, modified, loaded and saved
]"
date: "$Date$"
revision: "$Revision$"
class SETTINGS
inherit
XM_CALLBACKS_FILTER_FACTORY
export {NONE} all end
EM_SHARED_USER_DIRECTORY
export {NONE} all end
EM_SHARED_APPLICATION_ID
create
make
feature -- Initialization
make is
require
application_id_set: application_id.item /= void
do
set_user_file (user_directory.item, application_id.item + "_settings.xml")
-- Inits for Section: audio
music_genre := default_music_genre
music_enabled := default_music_enabled
music_volume := default_music_volume
sfx_enabled := default_sfx_enabled
sfx_volume := default_sfx_volume
num_of_starts := default_num_of_starts
-- Inits for Section: video
resolution_height := default_resolution_height
resolution_width := default_resolution_width
end
feature -- Attributes
-- Attributes for Section: audio
music_genre: STRING
music_enabled: BOOLEAN
music_volume: INTEGER
sfx_enabled: BOOLEAN
sfx_volume: INTEGER
num_of_starts: INTEGER
-- Attributes for Section: video
resolution_height: INTEGER
resolution_width: INTEGER
feature -- Defaults
-- Defaults for Section: audio
default_music_genre: STRING is "rock"
default_music_enabled: BOOLEAN is true
default_music_volume: INTEGER is 50
default_sfx_enabled: BOOLEAN is true
default_sfx_volume: INTEGER is 30
default_num_of_starts: INTEGER is 0
-- Defaults for Section: video
default_resolution_height: INTEGER is 110
default_resolution_width: INTEGER is 130
restore_all_defaults is
do
restore_audio_defaults
restore_video_defaults
end
restore_audio_defaults is
do
music_genre := default_music_genre
music_enabled := default_music_enabled
music_volume := default_music_volume
sfx_enabled := default_sfx_enabled
sfx_volume := default_sfx_volume
num_of_starts := default_num_of_starts
end
restore_video_defaults is
do
resolution_height := default_resolution_height
resolution_width := default_resolution_width
end
feature -- Element change
-- Setter for Section: audio
set_music_genre (val: STRING) is
do
music_genre := val
end
set_music_enabled (val: BOOLEAN) is
do
music_enabled := val
end
set_music_volume (val: INTEGER) is
do
music_volume := val
end
set_sfx_enabled (val: BOOLEAN) is
do
sfx_enabled := val
end
set_sfx_volume (val: INTEGER) is
do
sfx_volume := val
end
set_num_of_starts (val: INTEGER) is
do
num_of_starts := val
end
-- Setter for Section: video
set_resolution_height (val: INTEGER) is
do
resolution_height := val
end
set_resolution_width (val: INTEGER) is
do
resolution_width := val
end
feature -- User settings
set_user_file (a_directory: STRING; a_filename: STRING) is
require
a_filename /= void
a_directory.item (a_directory.count) = '/'
do
create user_dir.make (a_directory)
create user_file.make (a_directory + a_filename)
end
user_dir: KL_DIRECTORY
user_file: PLAIN_TEXT_FILE
write_user_settings is
do
if not user_file.exists then
if not user_dir.exists then
user_dir.recursive_create_directory
end
if user_file.is_creatable then
user_file.create_read_write
user_file.close
end
end
if user_file.exists and then user_file.is_writable then
user_file.open_write
user_file.put_string ("%N%N")
user_file.put_string ("%N")
-- Write audio settings
if not music_genre.is_equal(default_music_genre) then
user_file.put_string ("%T%N")
end
if not music_enabled.is_equal(default_music_enabled) then
user_file.put_string ("%T%N")
end
if not music_volume.is_equal(default_music_volume) then
user_file.put_string ("%T%N")
end
if not sfx_enabled.is_equal(default_sfx_enabled) then
user_file.put_string ("%T%N")
end
if not sfx_volume.is_equal(default_sfx_volume) then
user_file.put_string ("%T%N")
end
if not num_of_starts.is_equal(default_num_of_starts) then
user_file.put_string ("%T%N")
end
-- Write video settings
if not resolution_height.is_equal(default_resolution_height) then
user_file.put_string ("%T%N")
end
if not resolution_width.is_equal(default_resolution_width) then
user_file.put_string ("%T%N")
end
user_file.put_string("%N%N")
user_file.close
else
debug
io.put_string("Failed to write settings%N")
end
end
end
user_settings_parser: XM_EIFFEL_PARSER
user_settings_filter: EM_SETTINGS_READER_XM_FILTER
user_settings_table: DS_HASH_TABLE[STRING, STRING]
read_user_settings is
do
if user_file.exists and then user_file.is_readable then
user_file.open_read
create user_settings_filter.make_null
create user_settings_parser.make
user_settings_parser.set_callbacks (callbacks_pipe (<>))
user_file.read_stream (user_file.count)
user_settings_parser.parse_from_string (user_file.last_string)
user_settings_table := user_settings_filter.user_settings_table
user_file.close
-- Apply audio settings
if user_settings_table.has("music_genre") then
music_genre := user_settings_table.item("music_genre")
end
if user_settings_table.has("music_enabled") then
if user_settings_table.item("music_enabled").is_boolean then
music_enabled := user_settings_table.item("music_enabled").to_boolean
end
end
if user_settings_table.has("music_volume") then
if user_settings_table.item("music_volume").is_integer then
music_volume := user_settings_table.item("music_volume").to_integer
end
end
if user_settings_table.has("sfx_enabled") then
if user_settings_table.item("sfx_enabled").is_boolean then
sfx_enabled := user_settings_table.item("sfx_enabled").to_boolean
end
end
if user_settings_table.has("sfx_volume") then
if user_settings_table.item("sfx_volume").is_integer then
sfx_volume := user_settings_table.item("sfx_volume").to_integer
end
end
if user_settings_table.has("num_of_starts") then
if user_settings_table.item("num_of_starts").is_integer then
num_of_starts := user_settings_table.item("num_of_starts").to_integer
end
end
-- Apply video settings
if user_settings_table.has("resolution_height") then
if user_settings_table.item("resolution_height").is_integer then
resolution_height := user_settings_table.item("resolution_height").to_integer
end
end
if user_settings_table.has("resolution_width") then
if user_settings_table.item("resolution_width").is_integer then
resolution_width := user_settings_table.item("resolution_width").to_integer
end
end
end
end
end