plugin/planimationLibrary.js
/**
     * call the Planimation API to get VFG file, load the images to pixijs and 
     * then call the set up function to initilaise all the objects.
     * @param  {Plaimation} planimation object
     */
call the Planimation API to get VFG file, load the images to pixijs and
then call the set up function to initilaise all the objects.
@param  {Plaimation} planimation object
call the Planimation API to get VFG file load the images to pixijs and then call the set up function to initilaise all the objects . @param { Plaimation } planimation object
function initialise(planimation) {
        var formData = new FormData();
        formData.append("domain", planimation.domainPDDL);
        formData.append("problem", planimation.problemPDDL);
        formData.append("animation", planimation.animationPDDL);
        var xhr = new XMLHttpRequest();
        var url = 'https://planimation.planning.domains/upload/pddl';
        xhr.open("Post", url);
        xhr.send(formData);
        xhr.onreadystatechange = function (e) {
            if (xhr.readyState === XMLHttpRequest.DONE) {
                var status = xhr.status;
                if (status === 0 || (status >= 200 && status < 400)) {
                    var vfg = JSON.parse(xhr.responseText);
                    planimation.vfg=vfg;
                    planimation.currentStage = vfg.visualStages[0].visualSprites;
                    var base64imgs = []
                    for (var i = 0; i < vfg.imageTable.m_keys.length; i++) {
                        var obj = {}
                        obj.name = vfg.imageTable.m_keys[i];
                        obj.url = "data:image/png;base64," + vfg.imageTable.m_values[i];
                        if (obj.name in resources) {
                            console.log(obj.name + " already exist")
                        } else {
                            base64imgs.push(obj)
                        }
                    }
                    loader
                        .add(base64imgs)
                        .on("progress", loadProgressHandler)
                        .load(() => setup(planimation));
                }
            } 
        }
    }
function initialise ( planimation ) { var formData = new FormData ( ) ; formData . append ( "domain" , planimation . domainPDDL ) ; formData . append ( "problem" , planimation . problemPDDL ) ; formData . append ( "animation" , planimation . animationPDDL ) ; var xhr = new XMLHttpRequest ( ) ; var url = 'https://planimation.planning.domains/upload/pddl' ; xhr . open ( "Post" , url ) ; xhr . send ( formData ) ; xhr . onreadystatechange = function ( e ) { if ( xhr . readyState === XMLHttpRequest . DONE ) { var status = xhr . status ; if ( status === 0 || ( status >= 200 && status < 400 ) ) { var vfg = JSON . parse ( xhr . responseText ) ; planimation . vfg = vfg ; planimation . currentStage = vfg . visualStages [ 0 ] . visualSprites ; var base64imgs = [ ] for ( var i = 0 ; i < vfg . imageTable . m_keys . length ; i ++ ) { var obj = { } obj . name = vfg . imageTable . m_keys [ i ] ; obj . url = "data:image/png;base64," + vfg . imageTable . m_values [ i ] ; if ( obj . name in resources ) { console . log ( obj . name + " already exist" ) } else { base64imgs . push ( obj ) } } loader . add ( base64imgs ) . on ( "progress" , loadProgressHandler ) . load ( ( ) => setup ( planimation ) ) ; } } } }
call the Planimation API to get VFG file, load the images to pixijs and
 then call the set up function to initilaise all the objects.
call the Planimation API to get VFG file load the images to pixijs and then call the set up function to initilaise all the objects .
// store the VFG file // Use initial stage as the current stage //load based64 images and run the setup function when it's done // Pixi resources is a global variable, we have to avoid load same image into pixi resources //This setup function will run when the image has loaded