Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli argument for mod folder path #28

Merged
merged 4 commits into from
Jan 15, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ var mod_data = {}
# Order for mods to be loaded in, set by `_get_load_order`
var mod_load_order = []

# Path provided if cli arguments are added
var mods_path = ""
otDan marked this conversation as resolved.
Show resolved Hide resolved

# Any mods that are missing their dependancies are added to this
# Example property: "mod_id": ["dep_mod_id_0", "dep_mod_id_2"]
var mod_missing_dependencies = {}
Expand All @@ -97,7 +100,12 @@ func _init():
# if mods are not enabled - don't load mods
if REQUIRE_CMD_LINE && (!_check_cmd_line_arg("--enable-mods")):
return


# check if we want to use a different mods path that is provided as a command line argument
var cmd_line_mod_path = _get_cmd_line_arg("--mods-path")
if cmd_line_mod_path != "":
mods_path = cmd_line_mod_path
otDan marked this conversation as resolved.
Show resolved Hide resolved

# Loop over "res://mods" and add any mod zips to the unpacked virtual
# directory (UNPACKED_DIR)
_load_mod_zips()
Expand Down Expand Up @@ -484,13 +492,25 @@ func _check_cmd_line_arg(argument) -> bool:

return false

# Get the command line argument value if present when launching the game
func _get_cmd_line_arg(argument) -> String:
for arg in OS.get_cmdline_args():
if arg == argument:
if arg.find("=") > -1:
var key_value = arg.split("=")
return key_value[1]
otDan marked this conversation as resolved.
Show resolved Hide resolved

return ""

# Get the path to the (packed) mods folder, ie "res://mods" or the OS's equivalent
func _get_mod_folder_dir():
var gameInstallDirectory = OS.get_executable_path().get_base_dir()

if OS.get_name() == "OSX":
gameInstallDirectory = gameInstallDirectory.get_base_dir().get_base_dir().get_base_dir()

if (mods_path != ""):
gameInstallDirectory = mods_path
otDan marked this conversation as resolved.
Show resolved Hide resolved

# Fix for running the game through the Godot editor (as the EXE path would be
# the editor's own EXE, which won't have any mod ZIPs)
Expand Down