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 3096 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: 5766
  • 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: 509
    • 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: 241
    • 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: 920
    • 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.

nocluewhatimdoing

  • Ensign
  • *
  • Posts: 31
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #7 on: August 08, 2021, 07:46:40 AM »

Could this maybe get updated for JDK 16.0.2 as that changes the file name to jre1.8.0_281 also how very bottom do I need to paste the code
Logged

Yunru

  • Admiral
  • *****
  • Posts: 920
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #8 on: August 08, 2021, 08:21:01 AM »

Could this maybe get updated for JDK 16.0.2 as that changes the file name to jre1.8.0_281 also how very bottom do I need to paste the code
Starsector uses 1.7, and thus so must you.

Jaghaimo

  • Commander
  • ***
  • Posts: 241
    • View Profile
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #9 on: August 17, 2021, 06:27:56 AM »

Having to use JDK 1.7 is incorrect. You can use anything up to, and including 15 as long as you set your source and target compatibility to 1.7 (Java 7). In 16 support for Java 7 (1.7) was dropped, so you won't be able to build 1.7 versions anymore.
Logged
Stellar Networks - collection of useful intel boards
Starpocalypse - fortresses and regulations

HandsomeGeorge

  • Ensign
  • *
  • Posts: 1
    • View Profile
    • Email
Re: [GUIDE] Setting up Visual Studio Code to mod
« Reply #10 on: August 29, 2021, 03:18:32 PM »

hello everyone
id like to first express my gratitude towards the time and effort that has been put into tutorials and tools for people looking to create mods

by following the instructions i have been able to set up vs code with java sdk and extensions and have successful built and packaged a release using Jaghaimo's template
i have been trying to create a star system for a day now but to no avail. i am not sure this is the right place to ask but i exhausted all my ideas and need help

i have tried:
using only bare minimum code (only create and move lines)
using different package namespaces
moving the jar file and adding the path to it in the mod_info.json
i found two ways of logging by looking at other mods source code but am unable to find the logged lines or any errors in starsector-core/starsector.log

i was able to add a test ship and add it to a fleet with console command and i am also getting these logs:
INFO  com.fs.starfarer.loading.LoadingUtils  - Loading JSON from [DIRECTORY: ..\starsector-core\..\mods\pantheonorbitalworks (data/campaign/econ/economy.json)]
INFO  com.fs.starfarer.loading.LoadingUtils  - Loading CSV data from [DIRECTORY: ..\starsector-core\..\mods\pantheonorbitalworks]
INFO  com.fs.starfarer.loading.LoadingUtils  - Loading JSON from [DIRECTORY: ..\starsector-core\..\mods\pantheonorbitalworks (data/campaign/starmap.json)]
INFO  com.fs.starfarer.loading.LoadingUtils  - Loading JSON from [DIRECTORY: ..\starsector-core\..\mods\pantheonorbitalworks (data/campaign/econ/economy.json)]
INFO  com.fs.starfarer.loading.LoadingUtils  - Loading JSON from [DIRECTORY: ..\starsector-core\..\mods\pantheonorbitalworks (data\campaign\econ/POW_Sol.json)]
INFO  com.fs.starfarer.loading.SpecStore  - Loaded spec with id [Pantheon_|_constellation]

i think this narrows down the problem to running the java code
i have uploaded the code and build release to github in hopes someone can spot what i have done wrong https://github.com/GeorgeMarinov/pantheonorbitalworks
any help would be very appreciated!

UPDATE:

i was able to load up the java code by adding these two lines to the mod_info.json

    "jars":["pantheonorbitalworks.jar"],
    "modPlugin":"pantheonorbitalworks.POW_modPlugin"

the template will place the compiled code in the same directory as the mod_info.json, the name will be {your mod id}+.jar
as for the mod plugin, since i changed my package name while trying to load the code from data.scripts to pantheonorbitalworks that is the namespace i had to add to mod_info.json so it should be data.scripts.yourModPluginClass by default
« Last Edit: August 30, 2021, 01:21:24 PM by HandsomeGeorge »
Logged