Setting up Visual Studio Code

From Frictional Wiki
Jump to navigation Jump to search
Alert icon.png Warning: This guide might be partially outdated for newer versions of VS Code.

This is an extended guide on how to setup Visual Studio Code to use Intellisense for HPL3 and SOMA. Visual Studio Code is a lightweight notepad-esque version of Microsoft's full IDE Visual Studio. As Visual Studio Code is still under active development, some steps of this guide may need to be altered, so feel free to do so as the need arises.

Note: Even though Visual Studio Code is a cross-platform program, HPL3 is designed to be modded on a Windows machine. As such, the instructions in this guide assume that you are on a Windows OS. (Linux users who have successfully gotten the HPL3 modding tools may use this guide as a base to get Intellisense working on their platform.)

This guide was made with SOMA in mind, so setting up for Rebirth will require applying common sense in certain points.

Install VS Code

You will need to download and install VS Code. You can do so from Microsoft's VS Code website. Simply choose your desired platform and download the installer. Follow the instructions given in the installer to install VS Code on your computer.

Open SOMA Folder in VS Code

VS Code has the capability of opening an entire folder into its internal directory tree. Doing this gives you the benefit to be able to quickly and easily navigate to files in that folder and in subsequent folders. It also grants added benefits for inter-file relationships, such as C++ linking capabilities.

To do this, simply navigate to your SOMA installation folder and right-click on the window background. (i.e. Don't click on any file or folder within the SOMA folder.) Then select the "Open with Code" option from the drop down menu:

01.png

Associate HPS files with C++

The first thing to do is to associate HPL3 script files with VS Code's C++ syntax highlighting engine. To do so, you need to open VS Code's preferences file:

02.png

In VS Code, settings are saved in a JSON file. The window on the left is the VS Code default settings, while the window on the right is a JSON file for creating and saving user configurations.

To associate <html>.hps</html> files with C++, simply copy the following text into the user preferences window (on the right):

"files.associations": {
    "*.hps": "cpp"
}

Afterwards, your preferences file should look something like this:

03.png

Install CPPTools extension

Next, you will need to get the C/C++ extension for VS Studio. To do this, go to the Extensions tab on the left side of the window. In the search bar, search for "C/C++". The extension you want should appear at the top of the list (it's authored by Microsoft). After you find it, click the green "Install" button:

04.png

(After you install it, the window will need to be reloaded twice. The first time is after installing the extension, and the second time is after the extension downloads and installs its needed dependencies. Simply click on the "Reload" button as it appears and VS Code will restart itself for you, retaining your open files.)

Configure The HPL3 Profile

Now you need to congifure the extension to use the HPL3 script files for its Intellisense. To do this, open the Command Palette by pressing "Ctrl-Shift-P". From there, find and select the "C/Cpp: Edit Configurations" option:

05.png

On this page, you will see a lot of existing JSON text. This was automatically generated by the extension, and there's no need to change it. Instead, we are going to add a new profile for the Intellisense to use in our projects.

Scroll to the bottom and put the cursor after the closing bracket of the last profile. (It's the third bracket from the bottom.)

06.png

After that bracket, add a comma, add a new line (press Enter), then paste the following text:

{
    "name": "HPL3",
    "includePath": [
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/agents",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/areas",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/base",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/critters",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/custom_depth",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/custom_depth/helper_custom_depth_imgui",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/effects",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/helpers",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/interfaces",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/modules",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/player",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/props",
        "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/utilities"
    ],
    "intelliSenseMode": "clang-x64",
    "browse":{
        "path":[
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/agents",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/areas",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/base",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/critters",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/custom_depth",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/custom_depth/helper_custom_depth_imgui",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/effects",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/helpers",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/interfaces",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/modules",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/player",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/props",
            "F:/Program Files (x86)/Steam/steamapps/common/SOMA/script/utilities"
        ]
    }
}

(Change the path in each one to the folder where your installation of SOMA is located, obviously.)

Afterwards, the text should look like this (the new text is highlighted):

07.png

(If your text has any red squiggles in it, then you copied the text into the wrong place. Compare your text to the image above to make sure it looks the same.)

Now your profile is ready to go. Save and close the file, then go back to your map script. Open the Command Palette again ("Ctrl-Shift-P") and navigate to "C/Cpp: Select a Configuration":

08.png

Under the drop-down menu, select "HPL3":

09.png

And that's it! You're done! Go ahead and test it out in your map script:

10.png

Optional: Launch SOMA from VS Code

Another useful thing you can do with Visual Studio Code is to set Custom Debug Configuration. With that in mind, we can make VS Code launch the SomaDev.bat (or any other custom bat) file through the debugger.

Go to the Debug Panel by pressing "Ctrl+Shift+D". On the Debug tab, press on the configuration button and select C/C++ (Windows).

Override the existing code with the following:

{

// Use IntelliSense to learn about possible attributes.

// Hover to view descriptions of existing attributes.

// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [
{

      "name": "SOMA",

      "type": "cppvsdbg",

      "request": "launch",

      "program": "${workspaceFolder}/SomaDevCMD.bat",

      "args": [],

      "stopAtEntry": false,

      "cwd": "${workspaceFolder}",

      "environment": [],

      "externalConsole": true

    }

  ]

}

You can add more configurations by pressing on the "Add Configuration" Button at the bottom right and selecting again C/C++ Windows (Launch).

Now, just select the debugger you want and press on the green arrow to launch it.