Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.95a is out! (03/26/21); Blog post: Skill Changes, Part 2 (07/15/21)

Author Topic: [GUIDE] Setting up Visual Studio Code to mod  (Read 2618 times)

Tuv0x

  • Ensign
  • *
  • Posts: 11
    • View Profile
[GUIDE] Setting up Visual Studio Code to mod
« on: December 16, 2020, 02:29:57 AM »

Setting up VSCode for modding

There are a few guides here for intelliJ but I personally am a fan of VScode, I coded my first mod in NetBeans 10.0 but some of the features I'm used to in VSCode I just couldn't live without.
Also, if images aren't showing up when you click the spoilers, just reload the page, not sure what's going on there.

Anyways, here goes:
  • You can get vscode directly from their website or use your given package manager to download it (apt, pacman, etc.)
  • Once you have vscode installed, open it up and head over to the extensions tab
    Spoiler
    Should looks something like this
    [close]
  • Once you're there, pick up these two extensions (If it asks you to reload, go ahead and reload)
    Spoiler
    [close]
  • Now for the fun stuff: go ahead and hit Ctrl+Shift+P to bring up the command palette and type "Java", find "create Java project"  it should look like this after you click it:
    Spoiler
    [close]
  • Click "No Build Tools" to make this easier.
  • Now select a parent folder to put your project in (hint: it's about to ask you for a project name, this creates a folder with that name)
  • Name it whatever you want, it doesn't matter.
  • It's going to auto generate a project for you now, you can delete the App.java, README, and lib folder (unless you want to use them)

Now here's the very specific stuff for making this work for Starsector.

  • Starsector requires that you use Java 7 (aka jdk 1.7.0) when coding, so go pick that up from here
  • Now to make sure that the project manager is going to use Jdk1.7.0_80 to compile the .Jar go ahead and bring up the command palette with Ctrl+Shift+P.
  • Type "settings" and find "Preferences: Open Settings (JSON)"

At the very bottom paste this in.

Code
"java.configuration.runtimes": [
    {
      "name":"JavaSE-1.7",
      "path":"C:\\Program Files\\Java\\jdk1.7.0_80",
      "default":true
    }
]
NOTE: This is for Windows setups, given that jdk1.7.0_80 was installed in it's default location (64 bit), If you grabbed the 32 Bit version, it will be in C:\\Program Files (x86)... instead
If you grabbed an OpenJDK version, or just downloaded a zip, you'll have to point it to the correct directory yourself. Also, the double "\\" is intended, it's escaping the backslash, which Windows won't let die.
Linux Users: Most likely location is: /usr/lib/jvm/...
On Linux, I personally had to download the Zip and unzip it to that location.


If by default something else was there (It might use any previously installed Jdk's or installed openJDK and populated this already), delete it and replace it with this.

Okay, that's sorted.

Now how do I use this?
  • In the file explorer (Pages icon, top left), there should be a tab called "JAVA PROJECTS", open that up and make sure your project is expanded like so.
    Spoiler
    [close]
  • If you want to add libraries (starfarer.api.jar for example) click the plus sign that pops up when you mouse-over "Referenced Libraries" and find the .Jar
  • If you want to add a Class hit the plus sign that pops up next to "src." This supports names like "org.tuvox.TestMod" It will autocreate folders and the .java as well as include the correct package information in said file.
  • To build your project, when you mouse-over that panel, you will see this up top
    Spoiler
    [close]
  • Click it and uncheck everything except "bin" if you have dependencies (this ensures your dependencies don't get thrown into the compiled .Jar)
  • The default behavior for this is to just spit out the jar in the project folder, if you'd like to change that behavior click the Settings Cog all the way in the bottom left
  • Once there, type "Export Jar: Target Path" and you can change it. CAUTION: If User is selected in the top left, it will do this globally for EVERY project you work on, if you just want to change it for this Project, click Workspace.

And if you're familiar with Gradle and Git, I suggest you check out this template repo made by Jaghaimo here and use something like the Gradle Tasks extension in VScode.


Thaago

  • Global Moderator
  • Admiral
  • *****
  • Posts: 5674
  • Harpoon Affectionado
    • View Profile
    • Email
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #1 on: December 16, 2020, 03:08:27 AM »

Always great to see new guides on setting these things up, though at this point I'm very used to Netbeans! Thanks!
Logged

Tuv0x

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #2 on: December 16, 2020, 01:05:26 PM »

Always great to see new guides on setting these things up, though at this point I'm very used to Netbeans! Thanks!

The straw that broke the camels back when it comes to NetBeans for me was getting older versions on Windows to work properly without too much fuss. In Linux I had zero issues, other than it just didn't have all the features I wanted.
It's all user preference though, if I can help someone else who loves VScode have an easier time setting it up for modding, it was all worth it.

Nick XR

  • Admiral
  • *****
  • Posts: 503
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #3 on: December 16, 2020, 02:17:50 PM »

Can you debug with VSCode?  I did SS stuff for a year without knowing how to attach and debug, if there's anything that'll save you time, it's having a real debugger attached.

Tuv0x

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #4 on: December 16, 2020, 07:34:45 PM »

Can you debug with VSCode?  I did SS stuff for a year without knowing how to attach and debug, if there's anything that'll save you time, it's having a real debugger attached.

VScode has built in debugging, and extensions to add debugging for specific languages. I personally haven't gotten into it myself, I'm sure eventually I'll have to.

Jaghaimo

  • Commander
  • ***
  • Posts: 235
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #5 on: June 01, 2021, 04:49:30 AM »

Instead of creating a new thread, I'll add on to this (since it's still on front page anyway): you can vastly simplify VSCode setup by using my template.

  • Install VSCode and Java Language Support mentioned in the OP.
  • Install Gradle Support (not really needed but gives nice Gradle toolbar on the left to use - you want `build` and `release`).
  • Use a template (if using Github) / clone (if using git but not Github) /or download ZIP (if not using git at all) the template.
  • Open the code in VSCode, and you're done (well, edit mod_info.json in assets/mod_info.json and add some ModPlugin.java in src/main/java/<yourModId> to be precise).
Logged
Stellar Networks - collection of useful intel boards
Starpocalypse - fortresses and regulations

Yunru

  • Admiral
  • *****
  • Posts: 877
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #6 on: June 06, 2021, 02:46:39 PM »

In the file explorer (Pages icon, top left), there should be a tab called "JAVA PROJECTS", open that up and make sure your project is expanded like so.
Nope, I've got nothing like that? What did I do wrong?

EDIT: Ah, there's some more java things that need to be installed (although I don't know which was recommended and which was necessary), as a popup informed me when I accidentally opened App.java.