• 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.

ngppgn

Field Marshal
19 Badges
Jan 29, 2011
3.508
657
  • Crusader Kings III
  • Imperator: Rome
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV
  • Crusader Kings II: Monks and Mystics
  • Hearts of Iron IV: Cadet
  • Stellaris Sign-up
  • Stellaris
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Heir to the Throne
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Conquest of Paradise
  • Divine Wind
  • Europa Universalis III: Chronicles
  • Europa Universalis III
  • Crusader Kings II: The Old Gods
Hello, fellow modders! I want to humbly present you this tool:

CK2ide for Sublime Text 3 (Download it from the attached file).
Now, if you haven't heard of Sublime Text 3, it's an awesome, fast and "moddable" text editor, that can be used for free for as long as you want.

This is a "package" - the name sublime uses for its user-made extensions - that aims to bolster your productivity while coding in ck2script.

Current version (0.2) features:
Syntax Highlighting
This is the first release, focusing on syntax highlighting -tinting different parts of text in different colors to distinguish at a glance e.g. a trigger section from an effect block. Here is an example:
highlight_example.png
You just need to enter you game and mod folder paths into a config file, and afterwards, opening any supported mod file will automatically apply the appropriate syntax.

Part of the syntax functionality is that some syntatic errors will be caught on the fly and you'll notice them before having to run the Validator. So if you write "trait genius" instead of "trait = genius" you'll see a pitch black square signalling the error. However, this can't (yet...) caught other types of error like trying to do "culture = catholic".
All text files in /events, /decisions, and /common (with a few unimportant exceptions) are supported. Files in /localisation are also supported but I need to improve the coloring of those. Support for files in /map and /interface will have to wait for a future update.

These are the colors I'm using for the different parts of text. Any suggestion you have in how to improve them is welcome:
colors.png
Setup instructions:
  1. Have Sublime Text 3 already installed.
  2. Download the attacked .zip file.
  3. Open Sublime Text 3 and click on 'Preferences' > 'Browse Packages...'. A window (which we will call "Packages" from now on) will open in your explorer.
  4. Drop the contents of the .zip file (a single folder called "ck2IDE" in the folder/window you opened in step 3.
  5. You'll see that a new option was added to the topbar menu, called "ck2IDE". click on it and then on the "Settings" option. This'll open the settings file for you to edit.
  6. Modify only the parts between the ' ' signs. Altering the file in any other way may render it useless. (You can always use ck2IDE -> Restore Settings to return the settings file to its default state) . Between the ' ' enter the path to your ck2 installation, the path where you have your mods and the name of the font you want to use. Note that the font must be installed on your machine and, to make the most out of the syntax highlighting, it should support italics, boldface, and if possible, be monospace.
  7. Now you're all set. Open one of the supported files and it should color automatically.
Known issues:
  • Files take a tiny bit more than usual to open. This is because their location needs to be tested because a different syntax have to be applied to each type of file (decision, files, artifacts, etc. all follow different rules).
  • The colors for localisation are not so good, probably. Feel free to suggest a better color pattern.
  • If you find any issue that is not in here, please report it in this thread!
  • As of 0.2, the color scheme used by the supported ck2 files is a modified version of the default Monokai color scheme. Please tell me here or by PM if you'd like me to add support for other color schemes.
Find errors in current file
  • You can click anywhere in the editing area and use the option "ckwIDE: Go to next error" to move the screen to the next detected syntax flaw.
Changelog:
#Fixes
-Fixed game rules and scripted triggers not being highlighted.
-Fixed some minor "false positive" errors.
#-Features
-Added "ck2IDE" tab to the topbar menu. For now it only contains options to open the ck2IDE settings file and for resetting its values.
-Added "ck2IDE: Go to next error" option to the contextual menu in the editing area.
-The highlighting when errors occur are now much less intrusive, making actually writing (as opposed to just reviewing files) a much smoother experience.
-The "Toggle comment" feature of Sublime Text 3 now works for all the supported files.
#-Fixes
-Fixes several false positives, including trigger_switch with several types of values, and several decision fields and triggers added in 2.8 to being correctly parsed.
-Badly named on_actions are now reported as errors.
v0.1: First release
Plans for future versions:
  • Add support for the files not already covered
  • Improve the localisation colouring
  • Add completions, so that e.g. you type 'if', hit enter and the program writes the '= { limit = { } }' part. That should speed up your scripting by quite a bit.
  • Adding more error detection
  • Adding some misc tools for batch creating files etc.
  • Anything you may suggest that is within my (little, but slowly growing) python abilities.
Credits, thanks and acknowledgments:
  • To @zimxavier , who previously did work on this subject which have been the foundation for this.
  • To @zijistark , whose syntax I also had the oportunity to study
  • To the Sublime community for answering my noobish questions and the ck2 community for all the info on the wiki and the forums.
  • To the devs for the game in the first place and their support to it.
[/spoiler]​
 

Attachments

  • ck2IDE_0_2a.zip
    225,3 KB · Views: 312
Last edited:
I've noticed that some triggers (like liked_by_offmap) some of the newest decision fields (like third_party_filter) and some values for trigger_switch are being flagged as erroneous.

I'm ironing those out, and in passing making it less painful to write (currently, when you start writing a keyword, the coloring will break for the rest of the file until you finish writing it aand its value) by redtructuring the lexer.
I'll also add a couple commands to scroll to the first syntax issue in the current file and to to report all files with syntax issues in the open project.

If you spot any sound code that is being reported as erroneous, please let me know in case I missed it.
 
Version 0.2 uploaded to the OP. It fixes several misbehaviours of the syntax highlighting as well as adds a few features:
-Adds a main menu. From here you can open directly the settings file without having to search for it in your filesystem. More options will be added to it in future versions.
-Adds an option to the edit area's context menu to move the current view to the file's next parsing error.
-Adds support for toggling comments to all the supported files.
-Syntax error are much less intrussive now, making editing a more pleasant experience.
 
Not really into having background colors in syntax highlighting myself. Common colors I see for comments are a muted green or a light blue.

Other than that I love this :D I've been hoping someone would put together something like this. I wonder if CK2 can load any text file regardless of extension... except .info, of course. We could create community agreed upon extensions for different files to ease projects like this. Subtle differences in syntax and grammar between, say, decisions and events could be covered more thoroughly.
 
Not really into having background colors in syntax highlighting myself. Common colors I see for comments are a muted green or a light blue.

Other than that I love this :D I've been hoping someone would put together something like this. I wonder if CK2 can load any text file regardless of extension... except .info, of course. We could create community agreed upon extensions for different files to ease projects like this. Subtle differences in syntax and grammar between, say, decisions and events could be covered more thoroughly.

I'll add to the OP a little tutorial on how to customise the color scheme. Feel free then to post your modifications in case others find them more palatable - I won't claim to have any taste whatsoever in picking colors, that's for sure, haha.

CK2 seems to load any image regardless of extensions (I'e seen reports of it loading .png files, which I've never seen used in vanilla or a mod) but for text files it seems to look for specific extensions. I've had files with .bak .scratch and a few other extensions, which otherwise were perfectly normal event files, and they were ignored.

That being said, I wonder how I/O intensive would be to change the extensions of all the text files in a mod or vanilla when a project is open in Sublime Text, and changed back to .txt when it is closed. That'd help a lot in adding support for features like "Go to definition" which otherwise I could only try to simulate with workarounds. Great suggestion; will look at it when I have some time to spare.

I can't get this to work at all. The only reason I can think of is because I work on my mod from a git repo, not in the mods directory. I tried setting my GitHub folder and the root directory of my mod as my "mods" folder, but neither worked.

Any tips?
Say your mod is located in A/B/C (so you have A/B/C/Mymod/decisions, A/B/C/Mymod/events, etc. In that example, your mods_path setting should look like this mods_path = 'A/B/C'. If this is already the case... I'm at a loss on what might be happening. Please tell me if this helps you.
 
I'll add to the OP a little tutorial on how to customise the color scheme. Feel free then to post your modifications in case others find them more palatable - I won't claim to have any taste whatsoever in picking colors, that's for sure, haha.

CK2 seems to load any image regardless of extensions (I'e seen reports of it loading .png files, which I've never seen used in vanilla or a mod) but for text files it seems to look for specific extensions. I've had files with .bak .scratch and a few other extensions, which otherwise were perfectly normal event files, and they were ignored.

I've had my .bak files from WinMerge get loaded by the game and cause weird errors (necessitating that I configure WinMerge to put them in a dedicated directory outside of my repo), so some more thorough study may be warranted.

Alternatively (to something that happens on load and unload) there could be a "publish ck2 mod" function with this that would be the equivalent of WebPack or compilation.

That being said, I wonder how I/O intensive would be to change the extensions of all the text files in a mod or vanilla when a project is open in Sublime Text, and changed back to .txt when it is closed. That'd help a lot in adding support for features like "Go to definition" which otherwise I could only try to simulate with workarounds. Great suggestion; will look at it when I have some time to spare.


Say your mod is located in A/B/C (so you have A/B/C/Mymod/decisions, A/B/C/Mymod/events, etc. In that example, your mods_path setting should look like this mods_path = 'A/B/C'. If this is already the case... I'm at a loss on what might be happening. Please tell me if this helps you.

I'll give this a try when I get home from work.
 
My mod is not the top-level of my repo, but going one level down didn't work either. I also thought it might be an issue with escape character vs path delimiter stupidness in Windows, but that didn't help either.

Is there an error log the plugin might be dumping to that I could look at?
 
Not at the moment, sorry. The paths separators should't be an issue: you would put a single \ if on wimdows and a single / otherwise. Would you mind writing the path you're using? I'll try recreating that on on pc to see if I can repro your issue.

Note: I've noticed some more typos and issues I'm working ln fixing atm. I hope to have a new version in a couple days
 
I tried to run this on linux, but it doesn't seem to work. The console show this traceback:

Code:
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 935, in is_visible_
    ret = self.is_visible()
  File "/home/bellu/.config/sublime-text-3/Packages/ck2IDE/scripts.py", line 129, in is_visible
    if views[self.view.id()]: return True
KeyError: 13

Edit: the package is oddly very specific. It requires the mod to be base level so to have path with only two members: Folder/File.txt. What I have on my system is a path with 4 members: ['mod', 'ModName, 'subFolder', 'file.txt']. As it is, the package cannot work with my settings.

Edit2: Alright, understood what I did wrong and fixed some stuff too. Man your script.py is a mess :p

Here is my modified file.

Changes:
  • I removed your helper function "common_prefix" and replaced it with the native one. Downside is that the common prefix will always be populated (either / or c:\)
  • Made sure the path are escaped under windows, \ is used by the interpreter to do crazy things link inserting new lines (\n). Doubling the back slashes ensure that the interpreter understand that we really need back slashes.
  • Some logic were a bit headache inducing. os.path.exists to check if a string isn't empty and decide whether or not it is the mod path we want?
Overall, do not be afraid to use more lines as the overall script would gain in readability.
I maybe wrong with escaping characters in the configuration file. But it is necessary for everything down the line and usually safer.

Edit3:
Your common_prefix function is buggy. Try this:
Code:
common_prefix('c:\this\is\a\path', 'c:\this\is\one\path')
 

Attachments

  • scripts.py.7z
    2,2 KB · Views: 26
Last edited:
I tried to run this on linux, but it doesn't seem to work. The console show this traceback:

Code:
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 935, in is_visible_
    ret = self.is_visible()
  File "/home/bellu/.config/sublime-text-3/Packages/ck2IDE/scripts.py", line 129, in is_visible
    if views[self.view.id()]: return True
KeyError: 13

Edit: the package is oddly very specific. It requires the mod to be base level so to have path with only two members: Folder/File.txt. What I have on my system is a path with 4 members: ['mod', 'ModName, 'subFolder', 'file.txt']. As it is, the package cannot work with my settings.

Edit2: Alright, understood what I did wrong and fixed some stuff too. Man your script.py is a mess :p

Here is my modified file.

Changes:
  • I removed your helper function "common_prefix" and replaced it with the native one. Downside is that the common prefix will always be populated (either / or c:\)
  • Made sure the path are escaped under windows, \ is used by the interpreter to do crazy things link inserting new lines (\n). Doubling the back slashes ensure that the interpreter understand that we really need back slashes.
  • Some logic were a bit headache inducing. os.path.exists to check if a string isn't empty and decide whether or not it is the mod path we want?
Overall, do not be afraid to use more lines as the overall script would gain in readability.
I maybe wrong with escaping characters in the configuration file. But it is necessary for everything down the line and usually safer.

Edit3:
Your common_prefix function is buggy. Try this:
Code:
common_prefix('c:\this\is\a\path', 'c:\this\is\one\path')

Yup, my script is a mess, no arguing around that XD. Thanks for the suggestions and the proposed fix. Alas, I've working on a major overhaul, including that part.

Will study it and see what is still relevant to my working version.

That said, said working version won't be available until mid or late July, I reckon.
 
Thanks! This is really helpful.

I've been trying to set this up on sublime on a mac and I can't get it to work (It works fine on windows for me, though) is mac not supported or am I using the wrong paths (I hate finder and macOS pathing)
Code:
game_path: '\Users\<username>\Library\Application Support\Steam\steamapps\common\Crusader Kings II'
mods_path: '\Users\<username>\Documents\Paradox Interactive\Crusader Kings II\mod'
 
Thanks! This is really helpful.

I've been trying to set this up on sublime on a mac and I can't get it to work (It works fine on windows for me, though) is mac not supported or am I using the wrong paths (I hate finder and macOS pathing)
Code:
game_path: '\Users\<username>\Library\Application Support\Steam\steamapps\common\Crusader Kings II'
mods_path: '\Users\<username>\Documents\Paradox Interactive\Crusader Kings II\mod'

Turn those slashes around and you should be good.
 
Hmm. Just tried that and it's still not working.
In the view menu, select "Show Console". The shortcut should be ctrl+~ (~ being the key above tab). It should give you a bit more verbose output as to what is going on whenever you open a file.

If you know a bit of python, you can fiddle a bit with the scripts.py file to see what goes wrong.