OpenXcom Forum

Modding => Tools => Topic started by: SupSuper on August 30, 2018, 02:54:16 am

Title: Ruleset Validator for VSCode v0.9.11
Post by: SupSuper on August 30, 2018, 02:54:16 am
I made an extension for Visual Studio Code that checks your rulesets for syntax errors so you can catch them as you type instead of having to wait for OpenXcom to crash/spew nonsense/do nothing when you make a typo. It looks like this:

(https://i.imgur.com/Cgjd8k0.gif)

I figured it was more useful to extend a familiar text editor than trying to make an entirely separate tool. If this is worth developing further let me know.

Installation Instructions
1. Install Visual Studio Code (https://code.visualstudio.com/) if you don't already have it.
2. Install the OpenXcom Ruleset Tools extension (https://marketplace.visualstudio.com/items?itemName=openxcom.ruleset-tools) and follow the instructions.
3. Just open any .rul file and edit away.

Recommended Usage:
- Use File > Open Folder (or Open With Code in explorer) to open an entire mod at a time, so your workspace is preserved per mod.
- Open the View > Problems window to get a listing of all the errors in the currently open files.
- Use Trim Trailing Whitespace to fix tab errors (this can be done automatically in the Preferences).

What's Visual Studio Code? Isn't that some kind of IDE?
Despite the name, VSCode (for short) is just a fancy text editor in the vein of Notepad++/Sublime/Atom/etc. It's not related to Visual Studio (the IDE) which we use for developing OpenXcom.
It can be extended to be very powerful, but you don't need to be a programmer to use it. I know we've always recommended Notepad++ for YAML, but it's become kinda lackluster over the years.

Why not <insert your favorite editor>?
VSCode is free, cross-platform, and honestly it was the easiest to extend. It already had a powerful YAML extension available so I just had to build on that. If you'd rather port it to <insert your favorite editor> the source is here: https://github.com/OpenXcom/vscode-ruleset
Title: Re: Ruleset Validator for VSCode
Post by: The Reaver of Darkness on August 30, 2018, 02:32:30 pm
Very cool! I just use Notepad++ though. It doesn't do all that, but it does some of it at least.

I wonder if one could use this to scan for new rules they didn't know about?
Title: Re: Ruleset Validator for VSCode
Post by: davide on August 30, 2018, 03:11:31 pm
+100
Title: Re: Ruleset Validator for VSCode
Post by: Finnik on December 02, 2018, 04:13:12 pm
Its totally great! im using it full time for modding. one question - is there any way to add custom commands? as it counts all OXCE syntax as an errors.
Title: Re: Ruleset Validator for VSCode
Post by: Yankes on December 02, 2018, 08:20:01 pm
Yes it should allow as SupSuper careate it anybody can alter it to fit it goals.

btw SupSuper maybe add this file to `docs` folder in oxc repo? This could be source of truth for ruleset available for users.
When someone add new ruleset he need update this file, some thing like this I did for oxce documentation.
Title: Re: Ruleset Validator for VSCode
Post by: SupSuper on December 05, 2018, 08:51:07 pm
Yes it should allow as SupSuper careate it anybody can alter it to fit it goals.

btw SupSuper maybe add this file to `docs` folder in oxc repo? This could be source of truth for ruleset available for users.
When someone add new ruleset he need update this file, some thing like this I did for oxce documentation.
Arguably you could count this as the "source of truth": https://github.com/OpenXcom/vscode-ruleset/tree/master/schemas
Though it's already out-of-date :( I'm trying to figure out a way of having versioning and OXC/OXCE without making a mess of things.
Title: Re: Ruleset Validator for VSCode
Post by: Yankes on December 05, 2018, 10:49:44 pm
To reduce my work needed for describing every possible script function and its parameters I made hack, hole metadata need to parse string can be dump in semi human readable format. Something similar could be done for ruleset.

This probably would need some metaprograming or warper that will at once describe format and load data.

e.g.
Code: [Select]
void generateSchema()
{
  _schema = Schema<T>();
  _schema.field(&T::_id, "id of something");
  _schema.field(&T::_type, "type");
  _schema.field(&T::_weapon, "default weapon");
}
void load(Yaml::node& n)
{
   _schema.load(this, n);
}
Yaml::node save() //if we expand this do saves too
{
   return _schema.save(this);
}
std::string dump()
{
  return _schema.dump();
}

And then source of truth will be `oxc.exe --dump=filename.json`

[ps]

`dump()`  probably should dump YAML too, because it will be more compossible.
Title: Re: Ruleset Validator for VSCode
Post by: luke83 on December 18, 2018, 07:11:54 am
Trying this out tonight, i am making HEAPS of errors in my first Ruleset so i need all the help i can get :)

I have installed VS2017 Community edition, i have also followed the link but the Download Buttone does nothing, how do i install and Use this, is there a video tutorial? OK, trying CSCODE instead. :P

I have found and fixed more errors tonight since installing this ruleset checker than i have in the last 2 weeks combined, this is GREAT!!!!!!!

SupSUper - Question, does this only know about Vanilla commands? I noticed the AllowKneel command from OXCE is marked as a issue, i have ignored it for now.
Title: Re: Ruleset Validator for VSCode
Post by: Yankes on December 18, 2018, 01:36:15 pm
When I find some time I will fork this validator and add OXCE specific properties.
Title: Re: Ruleset Validator for VSCode
Post by: SupSuper on January 04, 2019, 12:25:03 am
OpenXcom Extended support is here! It's a Christmas New Years miracle! After updating the extension (should happen automatically next time you run VSCode) just go into your Settings and pick your preferred version. If you run into any bugs let me know.

(https://i.imgur.com/AauJnNp.gif)
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Thermite on April 14, 2020, 08:48:56 pm
randomProducedItems, refund and other OXCE .rul properties aren't accepted by the ruleset tools.
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Meridian on April 14, 2020, 09:13:22 pm
Two posts above is a visual guide how to switch between OXC validation and OXCE validation.
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Thermite on April 15, 2020, 01:09:38 am
Two posts above is a visual guide how to switch between OXC validation and OXCE validation.
Still doesn't work. keeps highlighting those as invalid
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Meridian on April 15, 2020, 09:45:07 am
.
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Thermite on April 15, 2020, 11:39:10 pm
What the heck?
It just works now?
Did the configuration change take forever to take place?
Title: Re: Ruleset Validator for VSCode v0.9.4
Post by: Nord on April 24, 2020, 05:55:03 pm
Looks like "refNode" still not supported.
Title: Re: Ruleset Validator for VSCode v0.9.11
Post by: Buscher on April 04, 2022, 10:40:19 pm
No clue if this is the right spot. I would like to report a few false positives shown by the OpenXcom Ruleset Tools (https://marketplace.visualstudio.com/items?itemName=openxcom.ruleset-tools). Some of these are related to how mod: - index: are handled as well as a list being allowed for customArmorPreviewIndex.

Code: [Select]
items:
  - type: STR_SOME_ITEM
    vaporColorSurface: {mod: 40k, index: 2} # Warning: Expected Integer # Works fine in Extended 7.5.8

armors:
  - type: STR_SOME_ARMOR
    moveSound: {mod: 40k, index: 700} # Warning: Expected Integer # Works fine in Extended 7.5.8
    customArmorPreviewIndex: [{mod: 40k, index: 560}, {mod: 40k, index: 561}, {mod: 40k, index: 562}] # Warning: Expected Integer # Works fine in Extended 7.5.8
    layersDefaultPrefix: 20 # Warning: Expected string # The value 20 is not nice but works in Extended 7.5.8

Also if one changes the accuracyMultiplier as a script and it's not part of scripts: and doesn't use the normal syntax, f. ex.
Code: [Select]
items:
# No Warning here
  - type: STR_SOME_ITEM
    accuracyMultiplier:
      firing: 1

accuracyMultiplier: | probably needs extra handling.

Code: [Select]
items:
# Warning: Use syntax from the code field above
  - type: STR_SOMETHING
    accuracyMultiplier: | # Works fine in Extended 7.5.8
      return bonus;
Title: Re: Ruleset Validator for VSCode v0.9.11
Post by: Meridian on April 04, 2022, 10:47:50 pm
Yes, this is the right spot.

Thanks for the report.
I'll fix it before the next release.
Title: Re: Ruleset Validator for VSCode v0.9.11
Post by: The Offensive Lemon on April 29, 2022, 07:51:18 pm
It appears moveCost for armors isn't supported.
Title: Re: Ruleset Validator for VSCode v0.9.11
Post by: Meridian on April 29, 2022, 09:41:59 pm
It appears moveCost for armors isn't supported.

Of course.
moveCost is not an officially released feature yet.
Title: Re: Ruleset Validator for VSCode v0.9.11
Post by: The Offensive Lemon on April 29, 2022, 10:48:50 pm
Of course.
moveCost is not an officially released feature yet.

Oh.  I was not aware of that.