Introducing a mod-manager for Lugaru

The place to discuss all things Lugaru.
iLag
Posts: 24
Joined: Tue May 11, 2010 9:45 pm

Introducing a mod-manager for Lugaru

Post by iLag » Tue May 11, 2010 10:21 pm

After corrupting my Lugaru install after trying out several mods, I thought, "somebody needs to make a mod manager for this awesome game." So I volunteered myself made one.
Keep in mind that I'm not a very good programmer, but I at least know something. My mod manager is programmed in python, so that it's cross-platform, there's no compiling because it's an interpreted language, and because I can't for the life of me figure out how C even works. It's probably some really simple thing that I haven't realized yet, but that's beside the point. I've made a basic mod manager for Lugaru, and I'm releasing it here.
You will need to download the python interpreter for this to work. You can get it here if you don't have it, but make sure to get the 2.6 version, as I have not tested it on version 3.

I have tested this script and it SHOULD work. The key word is SHOULD. There's always a chance that something can go wrong, especially if you're running Windows or Mac, as I have not tested this script on either operating system. So, if for some reason something goes wrong, I'm not responsible.
Anyway, here is the script. Copy and paste the following text into a text file with an extension of .py and you should be good. Just make sure to follow the directions at the top of the file and to start out with a clean Data file.
UPDATES:
All listed updates are already put into the main script. The links are only there for reference.
Windows Support (and a grammatical error) fixed by Xuor

Code: Select all

#!/usr/bin/python2.6
# Script created by iLag!!!!!
# Windows support fixed by Xuor
# Released under cc-by-sa 3.0 license
# http://creativecommons.org/licenses/by-sa/3.0/
# Neither iLag nor any other contributor is responsible for any damage which might be inflicted upon your computer
#  through the use of this script, even though no damage should be inflicted at all.  *NOT A GUARANTEE.

# READ THROUGH EVERYTHING AND FOLLOW ALL INSTRUCTIONS UP TO THE LINE I MADE

# This script should be placed in the main Lugaru directory

# When first ran, this script will create a Mods directory if it isn't present.
# Place all of the mod folders in this directory.

# For the mod folders, make sure that the contents of the folder are in the same directory structure as the main data folder.
# That means that any the mod's textures folder (which would have its contents copied into Data/Textures) should be named Textures and
#  be in the directory directly below the main mod's folder.  If you don't know what I mean, then I'm sorry that I'm horrible at
#  explaining things.  If you can do a better job, please correct me.

# When you run this script, you'll need to run it in a console or terminal window, or else it will hang.
# In Windows, this should be automatic.  In Linux w/Gnome, you can tell it to run in terminal when you launch it.
# I am unsure about other Linux Desktop Environments or Mac.  Please correct me.

# One final note: If for some reason a mod doesn't work right, such as textures not working right, check the mod folder's structure.
#  Chances are that the author, through no fault of his own, didn't have everything packaged just right for this script to work.
#  You'll have to fix that yourself.

import os
import shutil

# IMPORTANT!!!! MAKE SURE THAT THE VARIABLE BELOW IS THE PROPER COMMAND TO LAUNCH LUGARU FROM THE DIRECTORY CONTAINING THE EXECUTABLE.
# For Windows users, it should be Lugaru.exe.
# For Linux, ./lugaru (or wine ./Lugaru.exe if you're using the windows .exe like me, which I recommend)
# For Mac, I believe that it's the same as linux, but I do not know for sure.  Please correct me.
lexe="wine ./Lugaru.exe"

# Don't edit anything below this unless you know what you're doing.
#==================================================================================================

# Create the Mods dir if it doesn't exist
if not os.path.exists("./Mods/"):
	os.mkdir("./Mods/")
os.chdir("./Mods/")

# Copy over the Data folder if it isn't already in the Mods folder.
if not os.path.exists("./Data/"):
	shutil.move("../Data/","./Data/")
#  Don't forget to move the saves to the saves folder.
#   This will make the necessary folders if they don't already exist.
if not os.path.exists("../saves/"):
	os.mkdir("../saves/")
if not os.path.exists("../saves/Data/"):
	os.mkdir("../saves/Data/")
#   If the file in question is already in the save folder, delete it if it's in the data folder.
#   Otherwise, move it to the save folder.
if os.path.isfile("../saves/config.txt"):
	if os.path.isfile("./Data/config.txt"):
		os.remove("./Data/config.txt")
else:
	shutil.move("./Data/config.txt","../saves/")
if os.path.isfile("../saves/Data/Users"):
	if os.path.isfile("./Data/Users"):
		os.remove("./Data/Users")
else:
	shutil.move("./Data/Users","../saves/Data/")
#  If for some reason the Data folder already existed in the Mods folder, assume the script crashed and
#   delete the main Data folder.  This SHOULD be safe.  *NOT A GUARANTEE.
if os.path.exists("../Data/"):
	shutil.rmtree("../Data/")

# Get mod list
a=os.listdir("./")
#  Make Data appear on top
a.remove("Data")
a.append("Data")
a.reverse()

# Print the mod list, ask what you want.
b=1;
for c in a:
	print str(b)+") "+c
	b+=1
print "Please pick which mod you would like to load.  Note that entering something"
print " other than a number will cause the mod manager to fail."
d=int(raw_input())-1

# Copy back over Data
shutil.copytree("./Data/","../Data/")
if not d==0:
#  If you picked an actual mod, copy over the contents of Campaigns, Maps, and Textures.
#  Sorry, but I couldn't figure out how to make python copy everything...yet.
#  This WILL be changed.  I promise.  *IS A GUARANTEE.
	shutil.copytree(a[d],"./tocopy/")
	e=os.listdir("./tocopy/Campaigns/")
	for f in e:
		if os.path.isfile("../Data/Campaigns/"+f):
			os.remove("../Data/Campaigns/"+f)
		shutil.move("./tocopy/Campaigns/"+f,"../Data/Campaigns/")
	e=os.listdir("./tocopy/Maps/")
	for f in e:
		if os.path.isfile("../Data/Maps/"+f):
			os.remove("../Data/Maps/"+f)
		shutil.move("./tocopy/Maps/"+f,"../Data/Maps/")
	e=os.listdir("./tocopy/Textures/")
	for f in e:
		if os.path.isfile("../Data/Textures/"+f):
			os.remove("../Data/Textures/"+f)
		shutil.move("./tocopy/Textures/"+f,"../Data/Textures/")
	shutil.rmtree("./tocopy/")

# Make the saves directory if it doesn't exist already, and copy over the save files if they exist.
os.chdir("../")
if not os.path.exists("./saves/"):
	os.mkdir("./saves/")
if not os.path.exists("./saves/"+a[d]+"/"):
	os.mkdir("./saves/"+a[d]+"/")
if os.path.isfile("./saves/config.txt"):
	if os.path.isfile("./Data/config.txt"):
		os.remove("./Data/config.txt")
	shutil.copy2("./saves/config.txt","./Data/")
if os.path.isfile("./saves/"+a[d]+"/Users"):
	if os.path.isfile("./Data/Users"):
		os.remove("./Data/Users")
	shutil.copy2("./saves/"+a[d]+"/Users","./Data/")

# Launch that thing!
os.system(lexe)

# Set everything back up so that the game can run.
#  First, backup the saves.
if os.path.isfile("./saves/config.txt"):
	os.remove("./saves/config.txt")
shutil.move("./Data/config.txt","./saves/")
if os.path.isfile("./saves/"+a[d]+"/Users"):
	os.remove("./saves/"+a[d]+"/Users")
shutil.move("./Data/Users","./saves/"+a[d]+"/")
#  Next, delete our modified data folder
shutil.rmtree("./Data/")
#  Now move the main game and its save files back
shutil.move("./Mods/Data/","./Data/")
shutil.move("./saves/config.txt","./Data/")
if os.path.isfile("./saves/Data/Users"):
	shutil.move("./saves/Data/Users","./Data")
# DONE!
Please comment on this. Also, I promise that I WILL change the part that I mentioned I would in the program's comments.
Last edited by iLag on Sat May 15, 2010 6:11 pm, edited 2 times in total.

User avatar
Lotus Wolf
Posts: 2218
Joined: Sun Aug 31, 2008 6:03 pm

Re: Introducing a mod-manager for Lugaru

Post by Lotus Wolf » Tue May 11, 2010 10:49 pm

Nice, people have been wanting a mod manager.

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Introducing a mod-manager for Lugaru

Post by rudel_ic » Tue May 11, 2010 10:51 pm

I just make a backup of the Data/ folder before applying any mods.

That being said, for the opensource version, it would sure make sense to write a mechanism for handling mods that doesn't necessitate a restart or replacement of stuff in Data/.

User avatar
Jendraz
Posts: 640
Joined: Mon Nov 12, 2007 6:55 pm
Location: Los Angeles
Contact:

Re: Introducing a mod-manager for Lugaru

Post by Jendraz » Wed May 12, 2010 4:05 am

rudel_ic wrote:I just make a backup of the Data/ folder before applying any mods.

That being said, for the opensource version, it would sure make sense to write a mechanism for handling mods that doesn't necessitate a restart or replacement of stuff in Data/.
Doesn't matto's program handle that? Or do you mean not replacing files at all, even if it's automated?

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Introducing a mod-manager for Lugaru

Post by rudel_ic » Wed May 12, 2010 1:57 pm

Jendraz wrote:
rudel_ic wrote:I just make a backup of the Data/ folder before applying any mods.

That being said, for the opensource version, it would sure make sense to write a mechanism for handling mods that doesn't necessitate a restart or replacement of stuff in Data/.
Doesn't matto's program handle that? Or do you mean not replacing files at all, even if it's automated?
What I mean is making a menu point in the main menu called "Mods". When you click it, all mods you can choose appear. You choose a mod, the Data/ folder of some mod is chosen for reference. No restart, everything is just reloaded with that reference. Progress is preserved.

Basically, what matto did, but inside of Lugaru, and with a few tweaks.

User avatar
Jendraz
Posts: 640
Joined: Mon Nov 12, 2007 6:55 pm
Location: Los Angeles
Contact:

Re: Introducing a mod-manager for Lugaru

Post by Jendraz » Wed May 12, 2010 2:32 pm

rudel_ic wrote:
Jendraz wrote:
rudel_ic wrote:I just make a backup of the Data/ folder before applying any mods.

That being said, for the opensource version, it would sure make sense to write a mechanism for handling mods that doesn't necessitate a restart or replacement of stuff in Data/.
Doesn't matto's program handle that? Or do you mean not replacing files at all, even if it's automated?
What I mean is making a menu point in the main menu called "Mods". When you click it, all mods you can choose appear. You choose a mod, the Data/ folder of some mod is chosen for reference. No restart, everything is just reloaded with that reference. Progress is preserved.

Basically, what matto did, but inside of Lugaru, and with a few tweaks.
Gotcha. Feel like taking it on? :)

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Introducing a mod-manager for Lugaru

Post by rudel_ic » Wed May 12, 2010 2:39 pm

Jendraz wrote: Gotcha. Feel like taking it on? :)
There's more important things. The build system has to transfer to CMake, the code needs some cleaning up. Then, the modding tools I made need to be expanded so that skeletons, animations and maps can easily be made from scratch (not the case right now).
After that, yeah, sure. Along with shader support, expanding map making limits and other stuff.

But I don't want to get caught up in the diversification that's going on right now. There's like 4 repositories in the wild. It might get worse. So I'm going to step back for a few weeks to see which repository actually survives.

User avatar
Jendraz
Posts: 640
Joined: Mon Nov 12, 2007 6:55 pm
Location: Los Angeles
Contact:

Re: Introducing a mod-manager for Lugaru

Post by Jendraz » Wed May 12, 2010 4:01 pm

Exciting stuff. I wish I was competent enough/interested enough in coding to be a part of it. The thought of coding more than html just does not sound pleasing to me. To each his own.

iLag
Posts: 24
Joined: Tue May 11, 2010 9:45 pm

Re: Introducing a mod-manager for Lugaru

Post by iLag » Wed May 12, 2010 6:20 pm

So, no comments on my script? Has anyone else even tried it yet?

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Introducing a mod-manager for Lugaru

Post by rudel_ic » Wed May 12, 2010 7:08 pm

iLag wrote:So, no comments on my script? Has anyone else even tried it yet?
What is there to say? I read it, it should work. Great!

User avatar
Sandurz
Posts: 1105
Joined: Wed Dec 31, 2008 10:55 pm
Location: My House

Re: Introducing a mod-manager for Lugaru

Post by Sandurz » Wed May 12, 2010 10:32 pm

I think he was looking for a pat on the back.

/pat

User avatar
Blorx
NOT A FRIGGIN PROGRAMMER
Posts: 3272
Joined: Wed Jan 26, 2005 4:01 pm
Location: South Carolina, United States
Contact:

Re: Introducing a mod-manager for Lugaru

Post by Blorx » Wed May 12, 2010 10:50 pm

Awesome work! I haven't tried it, but it looks great! :mrgreen:

Xuor
Posts: 1
Joined: Sat May 15, 2010 1:55 pm

Re: Introducing a mod-manager for Lugaru

Post by Xuor » Sat May 15, 2010 1:58 pm

Works for me. I tested it on the Temple mod from the front page. Renamed the folders inside the Temple folder (from "This goes in Textures" to "Textures") and ran the script. From the Windows side of things, there are a few bugs. Below is the corrected version of the script. I think it's just lines 47 and 140. And, of course, 35. (Fixed a typo in the comment on line 139.)

Code: Select all

#!/usr/bin/python2.6
# Script created by iLag!!!!!
# Released under cc-by-sa 3.0 license
# http://creativecommons.org/licenses/by-sa/3.0/
# Neither iLag nor any other contributor is responsible for any damage which might be inflicted upon your computer
#  through the use of this script, even though no damage should be inflicted at all.  *NOT A GUARANTEE.

# READ THROUGH EVERYTHING AND FOLLOW ALL INSTRUCTIONS UP TO THE LINE I MADE

# This script should be placed in the main Lugaru directory

# When first ran, this script will create a Mods directory if it isn't present.
# Place all of the mod folders in this directory.

# For the mod folders, make sure that the contents of the folder are in the same directory structure as the main data folder.
# That means that any the mod's textures folder (which would have its contents copied into Data/Textures) should be named Textures and
#  be in the directory directly below the main mod's folder.  If you don't know what I mean, then I'm sorry that I'm horrible at
#  explaining things.  If you can do a better job, please correct me.

# When you run this script, you'll need to run it in a console or terminal window, or else it will hang.
# In Windows, this should be automatic.  In Linux w/Gnome, you can tell it to run in terminal when you launch it.
# I am unsure about other Linux Desktop Environments or Mac.  Please correct me.

# One final note: If for some reason a mod doesn't work right, such as textures not working right, check the mod folder's structure.
#  Chances are that the author, through no fault of his own, didn't have everything packaged just right for this script to work.
#  You'll have to fix that yourself.

import os
import shutil

# IMPORTANT!!!! MAKE SURE THAT THE VARIABLE BELOW IS THE PROPER COMMAND TO LAUNCH LUGARU FROM THE DIRECTORY CONTAINING THE EXECUTABLE.
# For Windows users, it should be Lugaru.exe.
# For Linux, ./lugaru (or wine ./Lugaru.exe if you're using the windows .exe like me, which I recommend)
# For Mac, I believe that it's the same as linux, but I do not know for sure.  Please correct me.
lexe="Lugaru.exe"

# Don't edit anything below this unless you know what you're doing.
#==================================================================================================

# Create the Mods dir if it doesn't exist
if not os.path.exists("./Mods/"):
	 os.mkdir("./Mods/")
os.chdir("./Mods/")

# Copy over the Data folder if it isn't already in the Mods folder.
if not os.path.exists("./Data/"):
	 shutil.move("../Data/","./Data/")
#  Don't forget to move the saves to the saves folder.
#   This will make the necessary folders if they don't already exist.
if not os.path.exists("../saves/"):
	 os.mkdir("../saves/")
if not os.path.exists("../saves/Data/"):
	 os.mkdir("../saves/Data/")
#   If the file in question is already in the save folder, delete it if it's in the data folder.
#   Otherwise, move it to the save folder.
if os.path.isfile("../saves/config.txt"):
	 if os.path.isfile("./Data/config.txt"):
			os.remove("./Data/config.txt")
else:
	 shutil.move("./Data/config.txt","../saves/")
if os.path.isfile("../saves/Data/Users"):
	 if os.path.isfile("./Data/Users"):
			os.remove("./Data/Users")
else:
	 shutil.move("./Data/Users","../saves/Data/")
#  If for some reason the Data folder already existed in the Mods folder, assume the script crashed and
#   delete the main Data folder.  This SHOULD be safe.  *NOT A GUARANTEE.
if os.path.exists("../Data/"):
	 shutil.rmtree("../Data/")

# Get mod list
a=os.listdir("./")
#  Make Data appear on top
a.remove("Data")
a.append("Data")
a.reverse()

# Print the mod list, ask what you want.
b=1;
for c in a:
	 print str(b)+") "+c
	 b+=1
print "Please pick which mod you would like to load.  Note that entering something"
print " other than a number will cause the mod manager to fail."
d=int(raw_input())-1

# Copy back over Data
shutil.copytree("./Data/","../Data/")
if not d==0:
#  If you picked an actual mod, copy over the contents of Campaigns, Maps, and Textures.
#  Sorry, but I couldn't figure out how to make python copy everything...yet.
#  This WILL be changed.  I promise.  *IS A GUARANTEE.
	 shutil.copytree(a[d],"./tocopy/")
	 e=os.listdir("./tocopy/Campaigns/")
	 for f in e:
			if os.path.isfile("../Data/Campaigns/"+f):
				 os.remove("../Data/Campaigns/"+f)
			shutil.move("./tocopy/Campaigns/"+f,"../Data/Campaigns/")
	 e=os.listdir("./tocopy/Maps/")
	 for f in e:
			if os.path.isfile("../Data/Maps/"+f):
				 os.remove("../Data/Maps/"+f)
			shutil.move("./tocopy/Maps/"+f,"../Data/Maps/")
	 e=os.listdir("./tocopy/Textures/")
	 for f in e:
			if os.path.isfile("../Data/Textures/"+f):
				 os.remove("../Data/Textures/"+f)
			shutil.move("./tocopy/Textures/"+f,"../Data/Textures/")
	 shutil.rmtree("./tocopy/")

# Make the saves directory if it doesn't exist already, and copy over the save files if they exist.
os.chdir("../")
if not os.path.exists("./saves/"):
	 os.mkdir("./saves/")
if not os.path.exists("./saves/"+a[d]+"/"):
	 os.mkdir("./saves/"+a[d]+"/")
if os.path.isfile("./saves/config.txt"):
	 if os.path.isfile("./Data/config.txt"):
			os.remove("./Data/config.txt")
	 shutil.copy2("./saves/config.txt","./Data/")
if os.path.isfile("./saves/"+a[d]+"/Users"):
	 if os.path.isfile("./Data/Users"):
			os.remove("./Data/Users")
	 shutil.copy2("./saves/"+a[d]+"/Users","./Data/")

# Launch that thing!
os.system(lexe)

# Set everything back up so that the game can run.
#  First, backup the saves.
if os.path.isfile("./saves/config.txt"):
	 os.remove("./saves/config.txt")
shutil.move("./Data/config.txt","./saves/")
if os.path.isfile("./saves/"+a[d]+"/Users"):
	 os.remove("./saves/"+a[d]+"/Users")
shutil.move("./Data/Users","./saves/"+a[d]+"/")
#  Next, delete our modified data folder
shutil.rmtree("./Data/")
#  Now move the main game and its save files back
shutil.move("./Mods/Data/","./Data/")
shutil.move("./saves/config.txt","./Data/")
if os.path.isfile("./saves/Data/Users"):
	 shutil.move("./saves/Data/Users","./Data")
# DONE!

iLag
Posts: 24
Joined: Tue May 11, 2010 9:45 pm

Re: Introducing a mod-manager for Lugaru

Post by iLag » Sat May 15, 2010 6:03 pm

Xuor wrote:Works for me. I tested it on the Temple mod from the front page. Renamed the folders inside the Temple folder (from "This goes in Textures" to "Textures") and ran the script. From the Windows side of things, there are a few bugs. Below is the corrected version of the script. I think it's just lines 47 and 140. And, of course, 35. (Fixed a typo in the comment on line 139.)
Your updated version of the script runs perfectly with no alterations (other than to indentation) on my end. I'll update my first post with it.

Sparrow15
Posts: 18
Joined: Sun Nov 30, 2008 2:47 pm

Re: Introducing a mod-manager for Lugaru

Post by Sparrow15 » Mon May 17, 2010 2:04 pm

Can anyone tell me how to get this running on a mac? I got an error in line 39, I think it said.

Post Reply