• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Hierarchy-based import

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2008
Messages
300

Description


While coding on Shadows of Everwood, I realised that it was a real pain to keep triggers with only //! import-directives in the Trigger Editor, so I set out to fix that, and this is the result.

This program is a small application that traverses a folder and its subdirectories, constructing an import-hierarchy along the way.



What is it and what does it do?


Consider the following structure:
Code:
Source\
   .
   ....... sys\
   .        .
   .        ....... UnitIndexer.j
   .        ....... TimerUtils.j
   .        ....... core\
   .                  .
   .                  ....... GameScript.j
   .
   ....... res\
            .
            ....... SomeScriptFile.j
            ....... NYI DamageSystem.j

In order to import those files you'd have to write 4 import dirctives:
JASS:
//! import "Source\\sys\\UnitIndexer.j"
//! import "Source\\sys\\TimerUtils.j"
//! import "Source\\sys\\core\\GameScript"
//! import "Source\\res\\SomeScriptFile.j"

Now imagine on a real map, with a lot more than 4 triggers.. that's a lot to write.

The aim was, for me, to only write one import directive:
JASS:
//! import "Source\\import.j"

And that's what I've created - a program that creates a tree of import directives.
After using my program on that folder, it'll look like this:
Code:
Source\
   .
   ....... import.j
   ....... sys\
   .        .
   .        ....... import.j
   .        ....... UnitIndexer.j
   .        ....... TimerUtils.j
   .        ....... core\
   .                  .
   .                  ....... import.j
   .                  ....... GameScript.j
   .
   ....... res\
            .
            ....... import.j
            ....... SomeScriptFile.j
            ....... NYI DamageSystem.j
The import.j files would contain import directives for files in the same folder, and for the import.j files in its subfolders:
Code:
                                                             Source\sys\core\GameScript.j
                                                            /
                                    Source\sys\core\import.j
                                   /
                Source\sys\import.j - Source\sys\UnitIndexer.j
               /                   \ 
Source\import.j                     Source\sys\TimerUtils.j
               \
                Source\res\import.j
                                   \
                                    Source\res\SomeScriptFile.j
Which, in my opinion, is neat.

You may ask "what about the NYI DamageSystem.j?".
- The program ignores files prefixed with 'NYI' (Not Yet Implemented)

Default working directory is "Source\", use param specified below to change!

The program will also accept a couple of command line parameters:
  • -d debug mode - output some information that may or may not be useful.
  • -f <path> change directory - will work on the specified path instead of "Source\".
  • -s silent mode - hides console window & does not ask for user input to start / exit.
  • -r root mode - tells program to write all import directives to root import.j-file.

Integrating with JNGP


You can easily integrate this program with JNGP using the jasshelper.conf-file.

Quick-guide:
  • Download this program and place it in your jasshelper folder. (\jassnewgenpack5d\jasshelper\)

  • Back one folder (to jassnewgenpack5d) and open jasshelper.conf in any text editor software.
    (Do not open the jasshelper.conf file inside your jasshelper folder.)

  • Find the line where it says [externaltools].

  • Add the following line: "ImportGenerator","jasshelper\\scriptgen.exe"

  • Save jasshelper.conf and open up the World Editor (restart it if you already had it opened)

  • Write: //! external ImportGenerator <your command line arguments here>

    Root folder is jassnewgenpack5d, so if you'd want to generate import files for the jass folder you'd write:
    //! external ImportGenerator -f jass

    If you have different projects inside that folder, perhaps something like this would suffice:
    //! external ImportGenerator -f jass\\mymapname

  • Now add an import line somewhere in your map that imports the root import.j file: //! import "jass\\mymapname\\import.j"

  • Et voilá! Note that the //! external -call will still work even though you're not using JNGP.
    (I.e compiling using only jasshelper or clijasshelper)

Requirements


  • Admin privileges on Windows Vista or newer.
  • Windows-based OS (XP, Vista, Win7)
  • Microsoft Visual C++ 2010 Redistributable (32bit, 64bit)

License is bundled with the attached program.


Change log



version 1.1
  • New algorithm: recursive & depth-first. (Might run out of stack memory on very large folders.)
  • New command line parameter: -r root mode - will stuff all import directives in root import file
  • Some new info when starting program.


Please post if you have suggestions, feedback or have found a bug!
 

Attachments

  • scriptgen v1.2.7z
    23.3 KB · Views: 73
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
Have done this myself recently along with other tools for my private project. What about determining an order in which scripts are loaded? Like on the same level. Why do you make and link to import.j files in every folder instead of collecting everything directly in the root? .j files in the Source folder are not recognized.
 
Level 6
Joined
Feb 10, 2008
Messages
300
Thanks for the feedback!

To start off, I couldn't find any reason to actually order the import directives, since JassHelper does that internally when compiling everything.
Any suggestion?

I traverse the tree and create import files because I think it's more elegant than mashing everything into one file.
Might add a command line param if to force mashing if someone would want that.

Also forgot to mention that the 'root' folder will only link to subdirs.
It's my design philosophy, but I'll change it since other people might think differently.

Update due tomorrow!
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
When you do explicit requirements, JassHelper will sort it according to that. This won't quite work for me though because first I use structs instead of libraries, second it would cause whole colons of requirements or dozens everywhere. Since JassHelper converts calling struct members below the current line to trigger prototypes, I would actually prefer if it had an automatic top sort-function, so trigger execution will be avoided to a big extent.

Yes, do it with a parameter. It has the advantage that you can do tests by only importing the subdirectory but it might be kind of messy. Have you tested if the path will be primarily looked up in jngp folders? Maybe you should do the long version/make a parameter for it. Then again, you could also do the import directive yourself and mash everything spelled in full in the root. This way, you can work with the created data a bit like browsing and searching how it looks together without calling the compiler and making it extract it again.
 
Level 6
Joined
Feb 10, 2008
Messages
300
Not to be a dick, but if I'm not wrong jasshelper.conf has a line that sounds like a fix to your problem:
JASS:
//To disable automatic .evaluate of methods that are called from above their declaration
// add a line containing [forcemethodevaluate]

Implemented new recursive, depth-first algorithm which should be a little bit faster than the previous solution.
Might crash if you have tonnes of stuff in the working directory, tell me if so!

I actually like the idea of ordering import directives, but I'm not sure what to base the ordering on and what the real gain would be.
Any ideas?

EDIT:

Uploaded new version: 1.1
Change log:
  • New algorithm: recursive & depth-first. (Might run out of stack memory on very large folders.)
  • New command line parameter: -r root mode - will stuff all import directives in root import file
  • Some new info when starting program.

EDIT:

Updated first post with very basic instructions on how to integrate this program into JNGP.
 
Last edited:
Level 6
Joined
Feb 10, 2008
Messages
300
Hue hue hue ;)

Updated to version 1.2 with some changes:

  • Added program icon!
  • New -f argument: $FILENAME$ (i.e -f $FILENAME$\code)
    (Only works when used from JNGP.)

    Works like the grimextentions; $FILENAME$ = path to your map

  • -c clean directive - remove all import.j files in targeted dir and all its subdirs
 
Status
Not open for further replies.
Top