From 42ff74e8236cbdad76711ca0b817e6c5876bb778 Mon Sep 17 00:00:00 2001 From: Michael Madsen Date: Sat, 17 Sep 2022 15:33:55 +0200 Subject: [PATCH] Add support for new DFHack config location (fixes #181) --- PyLNP.json | 2 +- core/df.py | 5 +++++ core/hacks.py | 4 ++-- core/importer.py | 9 +++++++++ core/lnp.py | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/PyLNP.json b/PyLNP.json index bd62076..b3c431d 100644 --- a/PyLNP.json +++ b/PyLNP.json @@ -17,7 +17,7 @@ "to_import": [ ["text_prepend", "/gamelog.txt"], ["text_prepend", "/ss_fix.log"], - ["text_prepend", "/dfhack.history"], + ["text_prepend", "/dfhack.history"], ["copy_add", "/data/save"], ["copy_add", "/soundsense"] ], diff --git a/core/df.py b/core/df.py index 104905b..93ca585 100644 --- a/core/df.py +++ b/core/df.py @@ -49,6 +49,11 @@ def set_df_folder(path): paths.register('save', paths.get('data'), 'save', allow_create=False) paths.register('extras', paths.get('lnp'), 'Extras') paths.register('defaults', paths.get('lnp'), 'Defaults') + if os.path.exists(paths.get('df', 'hack', 'init')): + paths.register( + 'dfhack_config', paths.get('df', 'dfhack-config', 'init')) + else: + paths.register('dfhack_config', paths.get('df'), allow_create=False) lnp.df_info = DFInstall(paths.get('df')) lnp.settings = lnp.df_info.settings if lnp.args.release_prep or lnp.args.raw_lint: diff --git a/core/hacks.py b/core/hacks.py index 64a4d38..57fe6e2 100644 --- a/core/hacks.py +++ b/core/hacks.py @@ -23,7 +23,7 @@ def read_hacks(): hacklines = [] for init_file in ('dfhack', 'onLoad', 'onMapLoad'): try: - with open(paths.get('df', init_file + '_PyLNP.init'), + with open(paths.get('dfhack_config', init_file + '_PyLNP.init'), encoding='latin1') as f: hacklines.extend(l.strip() for l in f.readlines()) except IOError: @@ -108,7 +108,7 @@ def toggle_hack(name): is_enabled = True hacks[name] = hack # Write back to the file - fname = paths.get('df', init_file + '_PyLNP.init') + fname = paths.get('dfhack_config', init_file + '_PyLNP.init') log.i('Rebuilding {} with the enabled hacks'.format(fname)) lines = ['# {}\n# {}\n{}\n\n'.format( k, h['tooltip'].replace('\n', '\n#'), h['command']) diff --git a/core/importer.py b/core/importer.py index 6d03d23..64e4709 100644 --- a/core/importer.py +++ b/core/importer.py @@ -122,11 +122,20 @@ def do_imports(from_df_dir): for st, src, dest in raw_config: if '' in src: newsrc = src.replace('', from_df_dir) + elif '' in src: + if os.path.exists(os.path.join(from_df_dir, 'hack', 'init')): + newsrc = src.replace('', os.path.join( + from_df_dir, 'dfhack-config', 'init')) + else: + newsrc = src.replace('', from_df_dir) else: newsrc = os.path.join(from_df_dir, '../', src) newsrc = os.path.abspath(os.path.normpath(newsrc)) if '' in dest: newdest = dest.replace('', paths.get('df')) + elif '' in src: + newdest = dest.replace( + '', paths.get('dfhack_config')) else: newdest = paths.get('root', dest) newdest = os.path.abspath(os.path.normpath(newdest)) diff --git a/core/lnp.py b/core/lnp.py index a0940e1..a4bfbde 100755 --- a/core/lnp.py +++ b/core/lnp.py @@ -169,7 +169,7 @@ def initialize_program(self): "to_import": [ ['text_prepend', '/gamelog.txt'], ['text_prepend', '/ss_fix.log'], - ['text_prepend', '/dfhack.history'], + ['text_prepend', '/dfhack.history'], ['copy_add', '/data/save'], ['copy_add', '/soundsense', 'LNP/Utilities/Soundsense/packs'],