[TOOL] CWTools - a mod scripting and validating extension for VS Code

  • We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Dayshine

Second Lieutenant
43 Badges
Aug 25, 2016
111
45
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Stellaris
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Horse Lords
  • BATTLETECH
  • Surviving Mars
  • Stellaris: Humanoids Species Pack
  • Cities: Skylines - Parklife
  • Imperator: Rome Deluxe Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Imperator: Rome
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Stellaris: Synthetic Dawn
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Stellaris - Path to Destruction bundle
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Call to arms event
  • Magicka
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Mare Nostrum
  • Sword of the Stars II
  • Crusader Kings II
CWTools is a library that provides common language services for paradox scripting files. This can be used to provide live validation of mod files as you are writing them. This is currently done through an extension for the text editor VS Code.

Current features are for Imperator, Stellaris, and Europa Universalis IV:
  • Immediate highlighting of syntax errors
  • Autocomplete everywhere, providing appropriate dynamically generated options and descriptions when available
  • Community supported rule based validation.
  • A wide range of validators for common, interface, and events, checking
    • That required localisation keys are defined
    • Existence of effects/triggers/modifiers
    • Scope context for used effects/triggers/modifiers
    • Usage of scripted effects/triggers
    • Correct entries for weights/AI_chance/etc
    • That event\_targets are saved before they're used
    • Check all "@" variables are defined before they're used
    • and a number of other specific validators
  • "Code actions" to generate .yml for missing localisation
  • Tooltips providing localisation info, effect documentation as well as scope information
  • A range of settings that allow you to customize what errors you see to fit your use

These all happen near-instantly as you're writing, just take a look at the examples below.
P740Ys4.gif




Validate syntax
cBVQtr8.gif



Check for correct scopes
806Pivp.gif



Find missing localisation
CwGMion.gif



Tooltips for effects
XS3gVZ0.gif



See all your errors in a nice convenient summary
e8ENFCM.png
Validation errors/Feedback
The validation rules that make CW Tools work aren't perfect, but are open to contribution from the community. If you think you've found an incorrect error (something that works in vanilla but errors in CW Tools) or have other feedback/suggestions, you can:
1. Post them here, but please provide a complete example
2. PM either @Urist_McDorf or @Dayshine
3. Have a try at fixing it yourself (Get in touch for details, it's really easy)

Contributors:
The initial set of rules that made this all possible were written almost entirely by @Urist_McDorf , and we'll try to acknowledge everyone who contributes here.
- Urist_McDorf
- ngppgn

Installation:
  1. Install VS Code from https://code.visualstudio.com/docs/setup/setup-overview
  2. Go to the extensions tab and search for "cwtools" (or go to https://marketplace.visualstudio.com/items?itemName=tboby.cwtools-vscode and press "install".
  3. Wait for it to install and "Reload".
  4. Open your mod folder directly, or open your Imperator folder in "Documents/Paradox Interactive".
  5. Select your vanilla installation folder when prompted (On windows this would be "Steam\steamapps\common\ImperatorRome")
  6. Start editing to get syntax validation immediately
  7. Wait up to a minute for the full analysis to kick in (First time will take a little longer).
  8. Take a look at configuration below for available settings.

Configuration:
The tool currently has the follow settings you can change:
Code:
 // The location of a vanilla EU4 installation
  "cwtools.cache.eu4": "",

  // The location of a vanilla HOI4 installation
  "cwtools.cache.hoi4": "",

  // The location of a vanilla Stellaris installation
  "cwtools.cache.stellaris": "",

// The location of a vanilla Imperator installation
"cwtools.cache.imperator": "",

// Error codes to ignore, list of IDs (e.g. "CW100" for syntax errors)
  "cwtools.errors.ignore": [ "CW100" ],

  // Files to ignore errors from, list of file names
  "cwtools.errors.ignorefiles": [
    "README.txt",
    "credits.txt",
    "credits_l_simp_chinese.txt",
    "reference.txt",
    "startup_info.txt"
  ],

  // Whether or not to show errors for vanilla files
  "cwtools.errors.vanilla": "false",

  // Whether or not to enable experimental features
  "cwtools.experimental": "false",

  // The list of languages to validate localisation for.
  "cwtools.localisation.languages": [
    "English", "German"
  ],

  // A folder containing custom rules to use
  "cwtools.rules_folder": "",

  // Which version of rules to auto-update to. Manual will use the local path set in rules_folder
  // Stable is recommended intially, but latest is updated frequently
  "cwtools.rules_version": "stable"

To change these:
1. File, Preferences, Settings (or Ctrl-comma)
2. Search for "cwtools"
3. Change the settings using the UI
4. Or press "edit in json" then press the pencil icon on the left to modify a setting, and edit them on the right
5. The changes should immediately take effect

Updates:
To update the extension go to the extensions tab, hit the three dots, and press "Check for updates". Then press the update button that appears next to the extension. Alternatively just turn on auto-updating extensions.

Planned (Current)
* Variables: Check variables are used in consistent scopes (if you set on a planet, you can only check on a planet)
* IDE: Contextual autocompletion, only show relevant keywords not all of them!
* Dead code detection (e.g. find events that are never called)
* Localisation: Scripted locs
* Localisation: Check correct scope for localisation keys

Future
* Localisation: Support custom localisations (e.g. mandarin)
* Variables: Unused by defined variables
* Syntax: Find multiple syntax errors in the same file

Blue skies
*

Completed
* Common: Check all effects/triggers/scopes in all files, not just events.
* Defines: Check defines overriden by mods exist in vanilla
* Effects/Triggers: Intelligently calculate scope for *recursive* effects/triggers
* Events: event_target is not defined but is used in effect/trigger
* IDE: Autocompletion
* Localisation: Check "default" language, i.e. localisation_synced
* Localisation: $keys$
* Localisation: Special command validator (the keywords in localisation strings)
* Localisation: Check validation file names
* Modifiers: Check existence of modifiers in common files (buildings, etc).
* Modifiers: Check correct scope usage of modifiers in common files (buildings, etc).
* Modifiers: Derive modifiers from ship sizes
* Variables: Check that variables have been defined somewhere
* Deal with file overwriting with multiple mods

Roadmap
This doesn't include the addition of extra individual validators, but the overall key features.
0.9 (In progress)
* Full support for CK2/HOI4
0.8 (DONE)
* Full support for Imperator
0.7 (DONE)
* Full support for EU4
0.6 (DONE)
* Basic syntax validation for EU4, HOI4.
0.5 (DONE)
* Tailored trigger/effect checking (e.g. check "who" in effects)
* Performance improvements, reduce startup time
0.4 (DONE)
* Basic effect/trigger/modifier support for all files
* Selective disabling of warnings
* Dependent revalidation (e.g. if you change the localisation file, recheck all files)
0.3 (DONE)
* Full localisation validation (of all required implicit and explicit keys)

Acknowledgements
Thanks to Jamie550 for getting me started.
Also thanks to Caligula, blackninja9939, the ExO team, the Paradoxial Development Group and many others for their patience with my neverending questions.
 
Last edited:
  • 2Love
  • 1Like
  • 1
Reactions:
We've worked very hard on this(while I did most of the config work, @Dayshine worked his butt off adding the support for stuff that wouldn't be covered by configs alone) so I'd really appreciate if everyone gave it a try. It really is the smarter, better way to organise the script and your changes to it compared to any other existing tool, and it should be the go-to IDE for everyone.

Right now the main shortcoming you can help with comes from a lack of docs outside of those provided by the game (trigger.log and such) - it's easy to help with that particular thing, so please consider doing so. As Dayshine mentioned, get in touch and we'll explain how to do that (it's fully open source, but links to github on PDX forums are best avoided just in case).
 
Last edited:
Questions:
1) Does this have to have an installation of (for example) Imperator on the local machine to work? Implication of the installation procedure given above is that it does...

2) What do you mean by "// The location of a vanilla Imperator installation"? On my machine that's a directory somewhere in "D:\Program Files (x86)\steamapps\common\" Should I replace the ""cwtools.cache.imperator"" with something, or the empty string ("") after it, or... what?

I'm aware that you've been as idiot-proof as you thought you could be, but I'm a perfect example of the fact that the universe keeps supplying better idiots! :p
 
Questions:
1) Does this have to have an installation of (for example) Imperator on the local machine to work? Implication of the installation procedure given above is that it does...

2) What do you mean by "// The location of a vanilla Imperator installation"? On my machine that's a directory somewhere in "D:\Program Files (x86)\steamapps\common\" Should I replace the ""cwtools.cache.imperator"" with something, or the empty string ("") after it, or... what?

I'm aware that you've been as idiot-proof as you thought you could be, but I'm a perfect example of the fact that the universe keeps supplying better idiots! :p
1) Yes, it does, it will combine the vanilla script files and your mod (or mods) when it does analysis. This means it's as close as possible to what the game will actually be running!

2) The installation directory in steamapps, yes, which should be a folder called "ImperatorRome". I'll make that clearer in the instructions. You shouldn't need to manually edit the settings there, just use the prompt to select the folder. If you want to manually edit your settings you can go to File -> Preferences -> Settings, search for cwtools and see your settings there too.
 
Just trying it out now, I can already tell this will be invaluable and will really speed up people's workflow! Looking forward to the coming updates on the roadmap :)

I did try opening a couple of other people's mods to see how it worked and there's hundreds of errors, though they are all localisation errors for things like 'country = syracuse', saying that the word country isn't defined in the localisation files. Is that something that needs to be addressed or am I just misunderstanding it perhaps? Either way thanks for all the hard work put into this!
 
Just trying it out now, I can already tell this will be invaluable and will really speed up people's workflow! Looking forward to the coming updates on the roadmap :)

I did try opening a couple of other people's mods to see how it worked and there's hundreds of errors, though they are all localisation errors for things like 'country = syracuse', saying that the word country isn't defined in the localisation files. Is that something that needs to be addressed or am I just misunderstanding it perhaps? Either way thanks for all the hard work put into this!

I'm not seeing this, could you give me an example of a mod? I can't find widespread use of `country = blah` in vanilla either, so a specific line would be useful :)
 
I'm not seeing this, could you give me an example of a mod? I can't find widespread use of `country = blah` in vanilla either, so a specific line would be useful :)

Hey, that was just an example and was a bad one sorry, it was things like 'country_culture = suebian' , saying suebian has no localisation. The mods I were looking at were the Veni Vidi Vici mod and EHI, I got them both from here: https://mods.paradoxplaza.com/games/imperator_rome

Here's a couple of examples, you can see all the red files on the left side too and the number of total errors at the bottom left. It could just be the mods themselves of course or perhaps I've not installed it correctly knowing me haha :p
Untitled-1.png
Untitled-2.png
 
1) Yes, it does, it will combine the vanilla script files and your mod (or mods) when it does analysis. This means it's as close as possible to what the game will actually be running!

2) The installation directory in steamapps, yes, which should be a folder called "ImperatorRome". I'll make that clearer in the instructions. You shouldn't need to manually edit the settings there, just use the prompt to select the folder. If you want to manually edit your settings you can go to File -> Preferences -> Settings, search for cwtools and see your settings there too.
Thanks. Installed and operating - works like a charm!
 
Hey, that was just an example and was a bad one sorry, it was things like 'country_culture = suebian' , saying suebian has no localisation. The mods I were looking at were the Veni Vidi Vici mod and EHI, I got them both from here: https://mods.paradoxplaza.com/games/imperator_rome

Here's a couple of examples, you can see all the red files on the left side too and the number of total errors at the bottom left. It could just be the mods themselves of course or perhaps I've not installed it correctly knowing me haha :p

Veni Vidi Vici is fine for me. Interestingly, this only happens when I load both EHI and VVV. I'll look into it a bit further because I can't see any conflicts between the localisation files.
 
Veni Vidi Vici is fine for me. Interestingly, this only happens when I load both EHI and VVV. I'll look into it a bit further because I can't see any conflicts between the localisation files.
Ah right, that's interesting. When I get around to actually using it for a mod it will probably be fine then, which is good to hear :)
 
Ah right, that's interesting. When I get around to actually using it for a mod it will probably be fine then, which is good to hear :)

I've released 0.8.3, which fixes this problem!
 
Is it just me or does the opening bracket return an erorr? This is a vanilla file
I'm fairly sure this is because of the character "|", which I haven't seen before.
I'll fix this today, although I'm not sure why the parsing error isn't being more useful!
 
I'm fairly sure this is because of the character "|", which I haven't seen before.
I'll fix this today, although I'm not sure why the parsing error isn't being more useful!
Has this been fixed? Seems to still happen for me. Mine just tells me it's expecting "value" instead of a bracket
uF6rWzn.png


EDIT: This may be a different issue, since brackets work fine in my modifiers file. If so, what is this error trying to get me to change?
 
Last edited:
Has this been fixed? Seems to still happen for me. Mine just tells me it's expecting "value" instead of a bracket
uF6rWzn.png


EDIT: This may be a different issue, since brackets work fine in my modifiers file. If so, what is this error trying to get me to change?
The parser currently shows errors in wrong places as a tradeoff for working quicker. It's being worked on, though.

The actual error will be somewhere inside the event's block, so take a closer look.