js type hints for AI scripting

For AI and campaign script related discussions and questions
Post Reply
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

js type hints for AI scripting

Post by wanjia1 »

I turned the Markdown Document of JavaScript Scripting API into a .js file:
pylint.js
When you open both your AI script and pylint.js in IDE like vscode,
the type hinting will be enabled and you can see each function's document, type of arguments, type of return,
like it is TypeScript.
it also contains names of most constants,like DORDER_MOVE.

the pylint.js was generates from Markdown Document of API of 4.3.2.
you can run the z-jslist.py to re-generate the pylint.js

license:CC0
Attachments
wzlint.zip
(41.55 KiB) Downloaded 33 times
Last edited by wanjia1 on 16 Dec 2023, 04:41, edited 2 times in total.
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

Re: js type hints for AI scripting

Post by wanjia1 »

a fragment of the pylint.js reads as follow:

var object=class {
constructor() {
this.type=0,
this.id=0,
this.x=0,
this.y=0,
this.z=0,
this.player=0,
this.selected=false,
this.name="object",
this.health=100,
this.armour=1,
this.thermal=1,
this.born=0
}}
var object0=new object()

...

/**Returns an array of droid objects. If no parameters given, it will
return all of the droids for the current player. The second, optional parameter
is the name of the droid type. The third parameter can be used to filter by
visibility - the default is not to filter.*/
function enumDroid(player, droidType, playerFilter) {return [droid0]}

/**Returns an array of all features seen by player of given name, as defined in "features.json".
If player is ```ALL_PLAYERS```, it will return all features irrespective of visibility to any player. If
name is empty, it will return any feature.*/
function enumFeature(playerFilter, featureName) {return [object0]}
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

Re: js type hints for AI scripting

Post by wanjia1 »

bugfix:
fix some type hints that hint a wrong type.
type hinting for global constants.
Attachments
wzlint.zip
(44.41 KiB) Downloaded 28 times
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

Re: js type hints for AI scripting

Post by wanjia1 »

bugfix:
remove attribute names of classes from constant hints
now every function have type hinting for arguments, in jsdoc format.
Attachments
wzlint_jsdoc.zip
(45.33 KiB) Downloaded 28 times
Last edited by wanjia1 on 19 Dec 2023, 12:05, edited 3 times in total.
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

Re: js type hints for AI scripting

Post by wanjia1 »

a sample of jsdoc, in the pylint.js, reads as follow:

/** Start factory production of new droid with the given name, body, propulsion and turrets.
The reserved parameter should be passed **null** for now. The components can be
passed as ordinary strings, or as a list of strings. If passed as a list, the first available
component in the list will be used. The second reserved parameter used to be a droid type.
It is now unused and in 3.2+ should be passed "", while in 3.1 it should be the
droid type to be built. Returns a boolean that is true if production was started.
* @param {_struct} factory
* @param {String} templateName
* @param {String[]|String} body
* @param {String[]|String} propulsion
* @param {""} reserved
* @param {""} reserved
* @param {(String[]|String)[]} turrets
*/
function buildDroid(factory, templateName, body, propulsion, reserved, reserved, ...turrets) {return true}
wanjia1
Rookie
Rookie
Posts: 27
Joined: 01 Nov 2023, 06:05

Re: js type hints for AI scripting

Post by wanjia1 »

bugfix:
fixed return type of special cases
fixed markdown document of eventSyncRequest:

at version 4.4.2, if player 0 calls syncRequest(1,2,3)
the expected event is eventSyncRequest(1,2,3,null,null)
but, in fact it is eventSyncRequest(0,1,256,384,null,null), different to document.
argument 0 is "from" player, other arguments is shifted right. x and y are multiplied by 128.

this now fixed by modifying markdown document that generates type hinting.

link of issue:
https://github.com/Warzone2100/warzone2100/issues/3193
Attachments
wzlint_jsdoc2.zip
(45.6 KiB) Downloaded 24 times
Post Reply