Difference between revisions of "Visual Studio Code"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>ChikkenChazer
(Introduced usage and compilation guide)
imported>ChikkenChazer
(Added link to compiler package)
Line 13: Line 13:
===Install packages===
===Install packages===
* Papyrus [https://marketplace.visualstudio.com/items?itemName=plankton020.papyrus] (syntax highlighting)
* Papyrus [https://marketplace.visualstudio.com/items?itemName=plankton020.papyrus] (syntax highlighting)
* Papyrus Compiler [https://marketplace.visualstudio.com/items?itemName=mr-andersen.vs-papyrus-compiler] (run the Papyrus compiler from the command menu)


==Usage==
==Usage==


After installing VS Code, install the Papyurs package by browsing to the package's extension page and click install or the VS Code's extension installer (CTRL+SHIFT+X)
After installing VS Code, install the Papyurs packages by browsing to the package's extension page and click install or the VS Code's extension installer (CTRL+SHIFT+X)


If your project is using project files (.ppj) you may want to associate .ppj files as XML
If your project is using project files (.ppj) you may want to associate .ppj files as XML
Line 44: Line 45:
===Compilation===
===Compilation===


If you want to compile your Papyrus scripts from within Visual Studio Code you can utilize VS Code's build and tasks system.
If you want to compile your Papyrus scripts from within Visual Studio Code you can use the Papyrus Compiler package (see packages section). The package contributes commands to VSC for running the Papyrus compiler. See the package homepage for setup.
 
Alternatively you can utilize VS Code's build and tasks system.


Note: Replace occurences of '''<GAME-DIRECTORY>''' with the path to the directory where your game is installed (Eg.: '''C:\Program Files (x86)\Steam\steamapps\common\Fallout 4''')
Note: Replace occurences of '''<GAME-DIRECTORY>''' with the path to the directory where your game is installed (Eg.: '''C:\Program Files (x86)\Steam\steamapps\common\Fallout 4''')

Revision as of 06:53, 4 February 2018

Visual Studio Code is a source code editor developed by Microsoft. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is also customizable, so users can change the editor's theme, keyboard shortcuts, and preferences. It is free and open-source, although the official download is under a proprietary license.

Visual Studio Code is based on Electron, a framework which is used to deploy Node.js applications for the desktop running on the Blink layout engine. Although it uses the Electron framework, the software does not use Atom and instead employs the same editor component (codenamed "Monaco") used in Visual Studio Team Services (formerly called Visual Studio Online).

See Wikipedia's page for more information.

Installation

Install Visual Studio Code

Go to the Visual Studio Code website, download the setup file, and run it.

Install packages

  • Papyrus [1] (syntax highlighting)
  • Papyrus Compiler [2] (run the Papyrus compiler from the command menu)

Usage

After installing VS Code, install the Papyurs packages by browsing to the package's extension page and click install or the VS Code's extension installer (CTRL+SHIFT+X)

If your project is using project files (.ppj) you may want to associate .ppj files as XML Go to File > Settings and add the following to *user settings*:

"files.associations": {
    "*.ppj": "xml"
}

User settings should look something like this:

{
    ...
    "editor.fontSize": 13,
    
    "files.associations": {
        "*.ppj": "xml"
    }

    ...
}

Compilation

If you want to compile your Papyrus scripts from within Visual Studio Code you can use the Papyrus Compiler package (see packages section). The package contributes commands to VSC for running the Papyrus compiler. See the package homepage for setup.

Alternatively you can utilize VS Code's build and tasks system.

Note: Replace occurences of <GAME-DIRECTORY> with the path to the directory where your game is installed (Eg.: C:\Program Files (x86)\Steam\steamapps\common\Fallout 4)

Compile single file using default build task

  1. First add the ScriptCompileDevVS.bat to your <GAME-DIRECTORY>\Data\Scripts\Source\User directory. The bat file contains basic compiler configuration for development.
  2. If not exists create a directory named '.vscode' (without quotes) in your <GAME-DIRECTORY>\Data\Scripts\Source\User directory.
  3. Add the file tasks.json in the new .vscode directory.
  4. In tasks.json make sure the directory paths in the windows.command property are correct.
  5. Save tasks.json

Now, you may test to see if everything is working as expected by opening one of your .tsc files. Press CTRL+SHIFT+B (Run Build Task) to compile. The built-in terminal should automatically open and output the results. If everything has been configured correctly you should see the compilation succss message.

Tasks can be tweaked to better suit your particular needs. Please consult the documentation for more information: https://code.visualstudio.com/docs/editor/tasks

For example you may create a task that runs the compiler based on a projects You may also create a task for each step in the workflow (development, release, final etc.)

Compile file on CTRL+S

If you want to compile the edited file every time you save the file (CTRL+S) you can add a hook in keybindings.json

1. Choose File > Preferences > Keyboard Shortcuts 2. Click the keybindings.json link at the top of the screen (below the search input) 3. In your keybindings.json add the following JSON object to the JSON array (between the brackets)

    {
        "key": "ctrl+s",          
        "command": "workbench.action.tasks.build",
        "when": "editorLangId == papyrus" 
    }

This will run the build task for the currently edited Papyrus file each time you save the file using the CTRL+S shortcut. Please note that the task will not run if save is triggered from elsewhere in VS Code (eg. Menu - File > Save)

Read more about keybindings here: https://code.visualstudio.com/docs/getstarted/keybindings

Files

ScriptCompileDevVS.bat

set compilerPath=%2
set gameDirectory=%~3

%compilerPath% %1 -f="%gameDirectory%\Data\Scripts\Source\Base\Institute_Papyrus_Flags.flg" -i="%gameDirectory%\Data\Scripts\Source\User;%gameDirectory%\Data\Scripts\Source\Base" -o="%gameDirectory%\Data\Scripts"

.vscode/tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile Papyrus Script (development)",
            "type": "shell",
            "windows": {
                "command": ".\\ScriptCompileDevVS.bat '${file}' 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Fallout 4\\Papyrus Compiler\\PapyrusCompiler.exe' 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Fallout 4'",
            },
            "presentation": {
                "reveal": "always"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}


See Also