MV - Cross Engine can't deploy to web or mobile

● ARCHIVED · READ-ONLY
Started by Acinder 2 posts View original ↗
  1. The cross engine can't deploy to web or mobile and I'd like to fix that.

    Below is what I believe to be the problem. web and mobile do not have access to node functions. Does anyone know how I can get the images without using fs? I asked GPT and it said I can create a .json with all the image names and then do a get fetch request but that seems odd to me. Any thoughts?

    JavaScript:
    this.crossEngine={};
        var fs = require ("fs");
        //yanfly's doodads have a solution for path name changing when deployed
        //which I am using!
        var path = require('path');
        var base = path.dirname(process.mainModule.filename);
        //let dir = fs.readdirSync( './img/characters/' );
        let dir = fs.readdirSync( path.join(base, '/img/characters/'));
        this.crossEngine.characterNameList = dir.filter( elm => elm.match(new RegExp(`.*\.(png)`, 'ig')));
        this.crossEngine.characterNameListLC=['hello world'];//this should never appear in game.
        //slice off the .png extension
        for (var index =0; index<this.crossEngine.characterNameList.length;index++)
        {
            this.crossEngine.characterNameList[index]=this.crossEngine.characterNameList[index].slice(0, -4);
            //create a lower case version of it so that we can do case matching for poses
            this.crossEngine.characterNameListLC[index]=this.crossEngine.characterNameList[index].toLowerCase();
        }
  2. I haven't looked into android yet but I managed the fix the issue mentioned above. fs is only used to get a list of image names in img/character. One way to replace it is to create an array list manually but I wanted something more automated.

    I instead check if 'fs' is available and if it is, I create a txt file of all of the files. Then, an http request can be done to get the txt file if 'fs' is not available (if player is on web or mobile). This should fix the problem where I don't have to think about it or change it again. Hope this helps someone else:


    Code:
        this.crossEngine={};
    
        // Check if has fs. Update dir txt if so. Use dirTxt if on mobile - Acinder
        let dir = false;
        try {
            var fs = require("fs");
            //yanfly's doodads have a solution for path name changing when deployed. Which I am using!
            var path = require('path');
            var base = path.dirname(process.mainModule.filename);
            dir = fs.readdirSync( path.join(base, '/img/characters/'));
            fs.writeFileSync( path.join(base, '/img/characters/dirlist.txt'), dir.join('\n') );
        } catch (e) {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', 'img/characters/dirlist.txt', false)
            xhr.send();
    
            if (xhr.status === 200) {
                dir = xhr.responseText.split('\n');
            }
        }