Skip to content

Commit

Permalink
Major rework
Browse files Browse the repository at this point in the history
  • Loading branch information
trainb0y committed Sep 19, 2021
1 parent 1fc8852 commit e3443d4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 247 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ Although it is stable enough that I use it, it is a work in progress and **proba

## Steam Workshop support
PyMultibound supports steam workshop mods as part of profiles, but not in a conventional manner.
On a profile update it scans the currently installed workshop mods, and if you select `yes` when prompted it will take the `contents.pak`
of each mod, rename it to `workshop-mod-<id>.pak` and group it with the manually installed mods.
On profile creation it optionally scans the currently installed workshop mods, and takes the `contents.pak`
of each mod, renames it to `workshop-mod-<id>.pak` and groups it with the manually installed mods.
It is then safe to unsubscribe to your subscribed workshop mods; they are now part of the profile and will be loaded when the profile is selected.

## How it Works
PyMultibound creates snapshots of the `storage` and `mods` folders of Starbound, and saves them in "profiles" - a directory in the same location as the scripts.
It then starts Starbound with a profile-specific `sbinit.config` that directs Starbound to the profile's files.

The default mode is `use-sbinit: true` in `settings.json`. In this mode it will edit the selected profile's `sbinit.config` file, adding the `mods` and `storage` folders to the asset and storage directory fields in the init file. It then replaces Starbound's `sbinit.config` with this custom one, switching them back once Starbound exists.
In this mode PyMultibound will generate a fresh `sbinit.config` for each profile, meaning sbinits are profile-specific.


Originally PyMultibound did not edit `sbinit.config` and instead manually moved the `mods` and `storage` folders of each profile. It can take a while with large installs/many mods. This mode can be enabled by setting `use-sbinit` to `false` in the config.

## Character Appearance Editor
### THIS FEATURE IS EXPERIMENTAL, MAKE BACKUPS BEFORE USING
Expand Down
72 changes: 13 additions & 59 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from util import *

# Version of PyMultibound
version = "0.1-ALPHA"
version = "0.2-ALPHA"

# Fore, Back, etc. allow us to use colored text through Colorama
# It is automatically replaced with placeholder "" by settingsloader if colored-text is false
# It is automatically replaced with placeholder "" by util.py if colored-text is false
# How to use:
# print(f"{Fore.RED}RED TEXT{Style.RESET_ALL}")
# would print RED TEXT in the color red. f-strings make this
Expand Down Expand Up @@ -82,28 +82,9 @@ def select_profile(profiles):
print(profile_menu.display())


def load_profile():
global current_profile
"""Switch the currently loaded profile for a different one"""
# Have the user select a profile and then load it in
# profile = select_profile(profiles)
logging.debug("Asking user for load confirmation")
print(f"{Fore.GREEN}Load profile {current_profile.name}? (Y/N) ")
if not settings["use-sbinit"]:
print(f"{Fore.YELLOW}This will erase the current game data!")
print("Save it as a profile/update the profile first!")

if "y" in input().lower():
return current_profile.load()
else:
logging.info("Profile load aborted")
return False


def switch_profile():
"""Switch current profile but do no file manipulation"""
"""Switch current profile"""
global current_profile
current_profile.unload()
current_profile = select_profile(profiles)


Expand All @@ -113,7 +94,8 @@ def new_profile():
profile = Profile()
profile.create(profile_name, starbound_dir, workshop_dir)
profiles.append(profile)

if "y" in input("Move current Starbound data into profile?").lower():
profile.get_starbound_data(starbound_dir, workshop_dir)


def delete_profile():
Expand Down Expand Up @@ -151,47 +133,27 @@ def help_page():
{Fore.CYAN}
---- PyMultibound Menu Options ----
{Fore.GREEN}Help{Style.RESET_ALL}: Brings up this message (clearly you know this by now)
{Fore.GREEN}Run Starbound{Style.RESET_ALL}: This will run Starbound, with the currently installed profile
This works by deleting the current Starbound "mods" and "storage" folders,
and replacing them with the saved ones for this profile.
The current profile will be auto-updated when you quit starbound.
{Fore.GREEN}Update Profile{Style.RESET_ALL}: This sets the profile"s data to whatever is currently in the Starbound folder
{Fore.YELLOW}WARNING: if used while Starbound folder is empty, this can
effectively delete the current profile!
{Fore.GREEN}Switch Profile{Style.RESET_ALL}: Change the currently selected profile
{Fore.GREEN}New Profile{Style.RESET_ALL}: Creates a new profile, but does not define any mods/universe
Use "Update Profile" with the new profile selected to define mods
{Fore.GREEN}Help{Style.RESET_ALL}: Brings up this message (clearly you know this by now)
{Fore.GREEN}Run Starbound{Style.RESET_ALL}: Run Starbound with the currently selected profile
{Fore.GREEN}Switch Profile{Style.RESET_ALL}: Change the currently selected profile
{Fore.GREEN}New Profile{Style.RESET_ALL}: Creates a new profile, optionally moving the current Starbound save into this profile
{Fore.GREEN}Delete Profile{Style.RESET_ALL}: This will completely delete all of the selected profile"s data.
{Fore.GREEN}Quit{Style.RESET_ALL}: Quit the program
""")


def run_starbound():
"""Run starbound as it is now, and update the current profile on exit"""
global current_profile
if not load_profile(): # it failed
if not current_profile.load(): # it failed
logging.error(f"Failed to load profile {current_profile.name}, not starting Starbound.")
return
logging.info("Starting starbound...")
cmd = os.path.join(starbound_dir, settings["starbound"], "starbound.exe")
# os.path.join() does not escape spaces, so
# it thinks you are trying to run
# C:/Program because of the space in program files
# So, have to do some string work lol
cmd = f'"{os.path.join(starbound_dir, settings["starbound"], "starbound.exe")}" ' \
f'-bootconfig "{os.path.join(current_profile.directory, "sbinit.config")}"'
logging.info(f"Launch command: {cmd}")
os.system(f'"{cmd}"') # Run the game
logging.info("Starbound closed, updating profile")
print(f"{Fore.GREEN}Updating profile, please wait...")
if (not settings["use-sbinit"]) or settings["duration-warning"]:
print(f"{Fore.YELLOW}This may take a while if you have a large universe or many mods")
print(f"{Fore.GREEN}If it takes too long, try setting `use-sbinit` to true in settings.json.")
print(f"{Fore.GREEN}However, that is an experimental feature and likely has bugs.")
print(f"{Fore.GREEN}To disable this warning, set duration-warning to false in the settings file")
current_profile.unload()
print(f"{Fore.GREEN}Profile {current_profile.name} updated!")
if settings["compress-profiles"]:
print(f"{Fore.GREEN}Compressing {current_profile.name}. This may take a while.")
print(f"{Fore.GREEN}Profile compression can be disabled in settings.json!")
Expand All @@ -200,8 +162,6 @@ def run_starbound():


def quit_program():
global current_profile
current_profile.unload()
shutil.rmtree(temp_dir)
print(f"{Fore.CYAN}Profiles saved, quitting...")
logging.info(f"Quitting PyMultibound - {version}")
Expand All @@ -214,19 +174,13 @@ def quit_program():
print(f"{Fore.GREEN}By trainb0y1")
print()

if settings["backup-warning"]:
logging.debug("settings['backup-warning'] is True")
print(
f"{Fore.RED}{Back.YELLOW}{Style.BRIGHT}BE SURE TO MAKE A BACKUP BEFORE USING, THIS WILL DELETE THE STARBOUND DATA (See help for more info){Style.RESET_ALL}")
print(f"{Fore.RED} To disable this message, set backup-warning to false in settings.json")
logging.debug("Entering main menu loop")
while True: # Main Menu Loop
main_menu = menu.Menu(
"Main Menu", [
("Help", help_page),
(f"Run Starbound ({Fore.CYAN + current_profile.name + Style.RESET_ALL})", run_starbound),
("Switch Profile", switch_profile),
(f"Update Profile ({Fore.CYAN + current_profile.name + Style.RESET_ALL})", current_profile.update),
("New Profile", new_profile),
("Delete Profile", delete_profile),
("Character Appearance Editor", editor.character_editor_menu),
Expand Down
Loading

0 comments on commit e3443d4

Please sign in to comment.