Difference between revisions of "User:FallenAvatar/Code Based Mod"

From wiki
Jump to: navigation, search
m
m
Line 31: Line 31:
 
** Click Add
 
** Click Add
 
** Click Ok
 
** Click Ok
 
''The project is now able to be built and loaded as a Mod, of course it doesn't do much at the moment''
 
 
 
* Add a new Text File and name it StaxelMod.mod
 
* Add a new Text File and name it StaxelMod.mod
 
** Replace StaxelMod with what you named your project
 
** Replace StaxelMod with what you named your project
 
** Simply add "{}" without the quotation marks to the file and save it.
 
** Simply add "{}" without the quotation marks to the file and save it.
 
*** This file is a config file. However nothing is supported in it yet. In the future, this ''might'' change.
 
*** This file is a config file. However nothing is supported in it yet. In the future, this ''might'' change.
 +
** Right Click this file in the Solution Explorer and select properties. Change "Copy to Output Directory" to "Copy if newer"
 
* Rename the Class1 class to Mod and allow Visual Studio to rename all references to it.
 
* Rename the Class1 class to Mod and allow Visual Studio to rename all references to it.
* Open Mod.cs and replace its content with:
+
* Open Mod.cs and replacing "StaxelMod" as necessary, overwrite its content with:
 
<pre>
 
<pre>
 
using Plukit.Base;
 
using Plukit.Base;
Line 93: Line 91:
  
 
</pre>
 
</pre>
** Again, replace "StaxelMod" as necessary.
+
'' '''Note''': Currently ClientContextDeinitialize is called during initialization intead of ClientContextInitializeInit
** '' '''Note''': Currently ClientContextDeinitialize is called during initialization intead of ClientContextInitializeInit
+
 
*
+
''The project is now able to be built, copied to the Staxel bin directory and loaded as a Mod, of course it doesn't do much at the moment''
 +
 
 +
== Setting up Debugging ==
 +
This section is technically optional, but it will make your life much, ''much'', '''much''' easier in the long run.
  
= Interface Documentation =
+
== Interface Documentation ==
  
 
* [[IAchievementComponentBuilder]]
 
* [[IAchievementComponentBuilder]]

Revision as of 22:28, 2 February 2018

[[Category:Modding]] Staxel also supports adding in your own code which can attach itself to interfaces within Staxel's code. This attachment is fairly rudimentary, and isn't tested as much as the other features. However, if you've ever wanted to add new features to Staxel, this is the way to do it.


Creating The Project

This page assumes that you are running Visual Studio 2017. If you run other versions of Visual Studio, locations of things may have changed. Other IDE's will definitely have different methods for some actions.

You should not need any external dependencies to develop Mods for Staxel. However, complex changes to the game may need XNA. In that case you can find what you need here: MXA

To create a new Code Based Mod:

Your New Project dialog may not look exactly like this.
  • Open Visual Studio
  • Create a New Project (File > New > Project)
  • Select a Class Library (Installed > Visual C# > Windows Classic Desktop > Class Library (.NET Framework))
    • Note You should be able to use your .Net Language of choice, but all sample code is in C#.
    • You may name it how you like, and use the newest version of the framework.
      • Tested with up to 4.7.1
  • Pick where you want your mod saved
  • Click Ok

Setting Up The Project

Now the project needs to be setup to recognize Staxel's code and build itself correctly for debugging.

Add References
  • Add a Reference by Right-Clicking the Project and selecting Add > Reference
    • Click Browse at the bottom right and navigate to where Staxel is installed, and open the bin folder.
      • For Staxel on Steam on Windows, this is likely "C:\Program Files (x86)\Steam\steamapps\common\Staxel\bin"
    • Hold Ctrl (Control) and select:
      • Plukit.Base.dll
      • Staxel.dll
    • Click Add
    • Click Ok
  • Add a new Text File and name it StaxelMod.mod
    • Replace StaxelMod with what you named your project
    • Simply add "{}" without the quotation marks to the file and save it.
      • This file is a config file. However nothing is supported in it yet. In the future, this might change.
    • Right Click this file in the Solution Explorer and select properties. Change "Copy to Output Directory" to "Copy if newer"
  • Rename the Class1 class to Mod and allow Visual Studio to rename all references to it.
  • Open Mod.cs and replacing "StaxelMod" as necessary, overwrite its content with:
using Plukit.Base;
using Staxel.Items;
using Staxel.Logic;
using Staxel.Tiles;

namespace StaxelMod {
	public class Mod : Staxel.Modding.IModHookV2 {
#region Loading
		public void GameContextInitializeInit() {}
		public void ClientContextInitializeInit() {}
		public void ClientContextInitializeBefore() {}
		public void GameContextInitializeBefore() {}
		public void GameContextInitializeAfter() {}
		public void ClientContextInitializeAfter() {}
#endregion

#region Running
	#region Every From
		public void UniverseUpdateAfter() {}
		public void UniverseUpdateBefore( Universe universe, Timestep step ) {}
	#endregion

		public bool CanPlaceTile( Entity entity, Vector3I location, Tile tile, TileAccessFlags accessFlags ) {
			return true;
		}

		public bool CanRemoveTile( Entity entity, Vector3I location, TileAccessFlags accessFlags ) {
			return true;
		}

		public bool CanReplaceTile( Entity entity, Vector3I location, Tile tile, TileAccessFlags accessFlags ) {
			return true;
		}
#endregion

#region Closing
		public void CleanupOldSession() { }
		public void GameContextDeinitialize() { }
		public void ClientContextDeinitialize() { }
		public void Dispose() { }
#endregion

#region Reloading
		public void ClientContextReloadBefore() { }
		public void GameContextReloadBefore() { }
		public void GameContextReloadAfter() { }
		public void ClientContextReloadAfter() { }
#endregion
	}
}

Note: Currently ClientContextDeinitialize is called during initialization intead of ClientContextInitializeInit

The project is now able to be built, copied to the Staxel bin directory and loaded as a Mod, of course it doesn't do much at the moment

Setting up Debugging

This section is technically optional, but it will make your life much, much, much easier in the long run.

Interface Documentation