77from threading import current_thread
88from typing import Any
99
10- import toml
11- from xdg_base_dirs import xdg_config_home
12-
1310from fantasy_forge .area import Area
1411from fantasy_forge .config import Config
1512from fantasy_forge .player import Player
1613from fantasy_forge .world import World
1714
1815
19- def read_config_options (user_config : dict [str , Any ]) -> Config :
20- config = Config ()
21- config_options = dir (Config )
22- for option in config_options :
23- if option in user_config :
24- setattr (config , option , user_config [option ])
25-
26- return config
27-
28-
2916def parse_args (config : Config , argv = argv [1 :]):
3017 parser = ArgumentParser (description = "Fantasy Forge: A text-based RPG" )
3118 parser .add_argument ("--version" , action = "version" , version = "%(prog)s 0.1.0" )
@@ -43,21 +30,9 @@ def parse_args(config: Config, argv=argv[1:]):
4330 return parser .parse_args (argv )
4431
4532
46- def user_config () -> dict [str , Any ]:
47- config_file = xdg_config_home () / "fantasy_forge.toml"
48-
49- if not config_file .exists ():
50- config_file .touch ()
51-
52- with config_file .open () as file :
53- config = toml .load (file )
54-
55- return config
56-
57-
5833def main ():
5934 # load config and args
60- config = read_config_options ( user_config () )
35+ config = Config . read ( )
6136 args = parse_args (config )
6237 description = args .description
6338
@@ -84,7 +59,7 @@ def main():
8459 ):
8560 if name_input :
8661 player_name = name_input
87- setattr (config , ' name' , name_input )
62+ setattr (config , " name" , name_input )
8863 print (
8964 world .l10n .format_value (
9065 "character-name-change-successful" , {"chosen_name" : name_input }
@@ -111,6 +86,8 @@ def main():
11186 )
11287 continue
11388
89+ config .save ()
90+
11491 print ()
11592 player = Player (world , player_name , description , current_thread ())
11693
0 commit comments