Skip to content

Commit

Permalink
Add support for new DFHack config location (fixes #181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pidgeot committed Sep 17, 2022
1 parent 9c694e4 commit 42ff74e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PyLNP.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"to_import": [
["text_prepend", "<df>/gamelog.txt"],
["text_prepend", "<df>/ss_fix.log"],
["text_prepend", "<df>/dfhack.history"],
["text_prepend", "<dfhack_config>/dfhack.history"],
["copy_add", "<df>/data/save"],
["copy_add", "<df>/soundsense"]
],
Expand Down
5 changes: 5 additions & 0 deletions core/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions core/hacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'])
Expand Down
9 changes: 9 additions & 0 deletions core/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,20 @@ def do_imports(from_df_dir):
for st, src, dest in raw_config:
if '<df>' in src:
newsrc = src.replace('<df>', from_df_dir)
elif '<dfhack_config>' in src:
if os.path.exists(os.path.join(from_df_dir, 'hack', 'init')):
newsrc = src.replace('<dfhack_config>', os.path.join(
from_df_dir, 'dfhack-config', 'init'))
else:
newsrc = src.replace('<dfhack_config>', from_df_dir)
else:
newsrc = os.path.join(from_df_dir, '../', src)
newsrc = os.path.abspath(os.path.normpath(newsrc))
if '<df>' in dest:
newdest = dest.replace('<df>', paths.get('df'))
elif '<dfhack_config>' in src:
newdest = dest.replace(
'<dfhack_config>', paths.get('dfhack_config'))
else:
newdest = paths.get('root', dest)
newdest = os.path.abspath(os.path.normpath(newdest))
Expand Down
2 changes: 1 addition & 1 deletion core/lnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def initialize_program(self):
"to_import": [
['text_prepend', '<df>/gamelog.txt'],
['text_prepend', '<df>/ss_fix.log'],
['text_prepend', '<df>/dfhack.history'],
['text_prepend', '<dfhack_config>/dfhack.history'],
['copy_add', '<df>/data/save'],
['copy_add', '<df>/soundsense',
'LNP/Utilities/Soundsense/packs'],
Expand Down

0 comments on commit 42ff74e

Please sign in to comment.