Although Socially Distant is fairly straight-forward to build, it is slightly more complex than most .NET projects and therefore requires some prior one-time setup before you can successfully compile the game. Furthermore, this setup depends on what platform you're on. This article explains exactly how to build Socially Distant from source.
Socially Distant as a game is split into two parts: **Socially Distant OS** and **Career Mode.**
Socially Distant OS Is the open-source codebase you can find here at https://gitlab.acidiclight.dev/sociallydistant/sociallydistant/. Socially Distant OS contains the game's core engine and assets, but doesn't contain any of the game's story mode assets.
Career Mode is just Socially Distant OS byilt with career assets included. These assets are proprietary and cannot be included inside the open-source version of the game. Only team members have access to these assets, and therefore only team members can compile Career Mode builds.
- For Linux users, Wine or Docker. You will need a Wine environment to compile shaders with.
- Basic familiarity with the .NET CLI
- Git
If you plan on contributing to the game, an acidic light community account is also required. You can create an account on the [community GitLab server](https://gitlab.acidiclight.dev/) if you do not have any. Signing in with Discord, GitHub, and Patreon is also possible.
## Clone the game
Clone the open-source version of the game to get started.
If you plan to contribute to the game, you will need a fork on our GitLab server. Use the GitLab UI to create the fork, then add it as a remote to your cloned version of the repository.
If you are a team member, you should have access to the source assets for Career Mode. They can be found in the private repository: https://gitlab.acidiclight.dev/sociallydistant/career-mode-assets/.
You can compile the game with Career Mode assets with a few more steps after cloning the game.
1. Assuming you've forked the game, check out a `career` branch on your fork.
```bash
git checkout -b career
```
2. Obtain the Career Mode assets via git submodules.
```bash
mv career-gitmodules .gitmodules
git submodule update --init
```
3. Push the `career` branch to your fork.
```bash
git push -u fork career
```
Never merge or rebase your `career` branch onto other branches. You should do development on other branches, but test Career Mode on your `career` branch. Remember that Socially Distant is primarily open-source, so your code should be as well.
Socially Distant is made using **Ritchie's Toolbox,** a de facto custom game engine built on top of a fork of MonoGame. In order for .NET to acquire the required build tools and libraries for the game, you will need to add a new NuGet feed to your system's NuGet configuration. This only needs to be done once per user account per computer.
If, at any time, you want to remove this NuGet feed, run:
```bash
dotnet nuget remove source gitlab-acidiclight
```
## IMPORTANT: Shader compilation
Shader compilation is a **mandatory** part of game compilation, and rather unfortunately, is flaky due to MonoGame limitations. If you want it to smoothly, and don't feel like troubleshooting, then follow this section to the letter.
### If you're on Windows
Most likely, you will be fine. However, it is highly advised that you install Visual Studio with the ".NET Desktop Development" and "Desktop Development with C++" workloads. Even if you don't use Visual Studio as an IDE, this will ensure your system has the necessary native Windows libraries needed for asset compilation (including shader compilation) to succeed.
### If you're on Linux
A Windows-compatible build environment is required for shader compilation to succeed. This is because MonoGame shaders are written in HLSL and compiled using MojoShader, which uses the proprietary Direct3D shader compiler under the hood.
#### Using Wine directly
If you plan on actually developing the game, the recommended way to set up shader compilation is by using Wine directly.
You will need a 64-bit Wine installation, i.e `wine64`. Some distributions do not properly package Wine, resulting in a 32-bit environment being set up even when you specifically asked for a 64-bit one. If you run into this, your distro has done you a dis-service and the game will not build.
The esaiest way to check if your distribution is sane is to set up a 64-bit Wine prefix and check the `%PROCESSOR_ARCHITECTURE%` environment variable within the Windows environment.
```bash
export WINEARCH=win64
export WINEPREFIX="$HOME/.winetest"
wine64 wineboot
wine64 cmd
```
```bash
C:\> echo %PROCESSOR_ARCHITECTURE%
```
If it outputs `x86_64`, then great. Otherwise, you're on your own.
When you've installed Wine64 and verified that it actually works, navigate to the root of your repository and run the MGFXC Wine setup script.
```bash
chmod +x mgfxc-wine-setuo.sh
./mgfxc-wine-setup.sh
```
You will need to log out of and log back into your computer for the changes to take effect.
You can verify that the setup finished successfully, after re-logging, by checking the `MGFXC_WINE_PATH` environment variable has been set.
```bash
echo $MGFXC_WINE_PATH
# should look like
/home/ritchie/.winemonogame
```
If the environment variable isn't set, you may need to configure your login shell to set it to the value of `$HOME/.winemonogame`.
#### Docker
If you have Docker on your system, and want to build the game that way, a pre-configured Docker image with the necessary build tools for Socially Distant is available. However, this is built primarily around being used for CI/CD rather than as a development environment. Nonetheless, you can get a container and run a shell on it with this command.
```bash
docker run --rm -it cr.acidiclight.dev/docker-images/monogame-linux-build/dotnet-mgcb:latest /bin/bash
```
Note that you will need to add the custom NuGet feed within the container itself.
## Compile the game
If you've gotten this far, then everything from here on out is a breeze.
### Quickly run the game
Run the game by running the `SociallyDistant` project with `dotnet run`. This compiles the game and launches it.
```bash
cd src/SociallyDistant
dotnet run
```
### Build the game for release/installation
If you want to create a release version of the game, use `dotnet publish` to generate a self-contained build of the game for your platform. We do not create framework-dependent builds of the game for release, and we do not support the use of them, since self-contained builds are guaranteed to have the correct version of the .NET runtime bundled with them.
The third officially-supported way to build Socially Distant is to build its core framework (`SociallyDistant.Framework`). This builds only the parts of the game that are necessary to write mods with. In the future, the development workflow for mod developers will be streamlined.
Note: Do not do a self-contained build for `SociallyDistant.Framework`.