Change where assets are loaded from

● ARCHIVED · READ-ONLY
Started by SoapieSoap 12 posts View original ↗
  1. Currently each RMMV game has it's own sets of assets that it loads from, which isn't exactly space efficient if you have multiple games using the same set of assets. Right now it's something like:

    Game 1 loads pictures from Game 1\img\

    What I'm looking for is a plugin that allows you to change where your game assets are located, so you have Game 1 and Game 2 loading from the same folder. For example:

    Game 1 has map data in All Games\Game 1\data\
    Game 2 has map data in All Games\Game 2\data\
    Both games load images and tilesets from All Games\Assets\img\

    I made another thread and was told that I'd need to edit core MV scripts but I have no idea how to do that so... here I am. I was also asked to tag @High Plains Design Studio, not sure if that's how it works but hope that did it.

    I hope I'm explaining it right, please ask if you need clarification. Thanks in advance!
  2. Bump. Any help would be great!
  3. Sorry. I thought I had it, but then I still ran into errors :( I have started working on this problem, though. I am finally getting to it today. It is a problem of mine as well, and I need to find a solution.
    It seems there are a few more functions for reserving and requesting the bitmaps; they all have the directory hard coded as a string and probably need to be changed out.
    I'll need to do some more work to figure it out.
  4. It's okay, take your time! You're already doing much more than I could xD

    Just keep us posted please!
  5. Ok. Great. I've made some progress. I have created the plugin HPDS AssetsManager. It will change the directory for the images and the audio. However, the game will not work from the RMMV Play Test button if you change the folders to a folder outside of the game's directory. The game MUST be run from a server in order for the relative paths to properly translate to a URL.

    Also, the file structure within the "img" directory and the "audio" directory MUST remain the same. And, another bug that I've found is that the "Loading.png" image MUST remain in the /img/system directory of the game's main file structure. I haven't yet found out why that particular image is loaded a different way.

    @SoapieSoap , I will leave the code here for right now and you can be my first guinea pig to help get it going. Make a file called HPDS_AssetsManager.js and place it within your plugins folder. Then, paste the following code into the file and let me know your experience. Keep in mind, I was deploying for the web and then running the game on a web server.

    Spoiler
    Code:
    (function() {
      
    /*:
     * @plugindesc HPDS Assets Manager to change from where images and audio are loaded.
     * @author Michael Hernandez @ High Plains Design Studio www.highplainsdesignstudio.com
     *
     * @param images
     * @desc The directory that will hold the images. Can be relative (../assets/). This should contain the trailing "/".
     * @default img/
     *
     * @param audio
     * @desc The directory that will hold the audio. Can be relative (../assets/audio/). This should contain the trailing "/".
     * @default audio/
     */
    
        HPDS_ImageManager = {};
        HPDS_ImageManager.parameters = PluginManager.parameters("HPDS_AssetsManager");
    
        var imagesDir = HPDS_ImageManager.parameters["images"];
        var audioDir = HPDS_ImageManager.parameters['audio'];
    
        ImageManager.loadAnimation = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'animations/', filename, hue, true);
        };
      
        ImageManager.loadBattleback1 = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'battlebacks1/', filename, hue, true);
        };
      
        ImageManager.loadBattleback2 = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'battlebacks2/', filename, hue, true);
        };
      
        ImageManager.loadEnemy = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'enemies/', filename, hue, true);
        };
      
        ImageManager.loadCharacter = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'characters/', filename, hue, false);
        };
      
        ImageManager.loadFace = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'faces/', filename, hue, true);
        };
      
        ImageManager.loadParallax = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'parallaxes/', filename, hue, true);
        };
      
        ImageManager.loadPicture = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'pictures/', filename, hue, true);
        };
      
        ImageManager.loadSvActor = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'sv_actors/', filename, hue, false);
        };
      
        ImageManager.loadSvEnemy = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'sv_enemies/', filename, hue, true);
        };
      
        ImageManager.loadSystem = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'system/', filename, hue, false);
        };
      
        ImageManager.loadTileset = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'tilesets/', filename, hue, false);
        };
      
        ImageManager.loadTitle1 = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'titles1/', filename, hue, true);
        };
      
        ImageManager.loadTitle2 = function(filename, hue) {
            return this.loadBitmap(imagesDir + 'titles2/', filename, hue, true);
        };
    
        // reserve methods
        ImageManager.reserveAnimation = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'animations/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveBattleback1 = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'battlebacks1/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveBattleback2 = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'battlebacks2/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveEnemy = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'enemies/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveCharacter = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'characters/', filename, hue, false, reservationId);
        };
      
        ImageManager.reserveFace = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'faces/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveParallax = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'parallaxes/', filename, hue, true, reservationId);
        };
      
        ImageManager.reservePicture = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'pictures/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveSvActor = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'sv_actors/', filename, hue, false, reservationId);
        };
      
        ImageManager.reserveSvEnemy = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'sv_enemies/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveSystem = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'system/', filename, hue, false, reservationId || this._systemReservationId);
        };
      
        ImageManager.reserveTileset = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'tilesets/', filename, hue, false, reservationId);
        };
      
        ImageManager.reserveTitle1 = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'titles1/', filename, hue, true, reservationId);
        };
      
        ImageManager.reserveTitle2 = function(filename, hue, reservationId) {
            return this.reserveBitmap(imagesDir + 'titles2/', filename, hue, true, reservationId);
        };
    
        // Request methods
        ImageManager.requestAnimation = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'animations/', filename, hue, true);
        };
      
        ImageManager.requestBattleback1 = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'battlebacks1/', filename, hue, true);
        };
      
        ImageManager.requestBattleback2 = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'battlebacks2/', filename, hue, true);
        };
      
        ImageManager.requestEnemy = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'enemies/', filename, hue, true);
        };
      
        ImageManager.requestCharacter = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'characters/', filename, hue, false);
        };
      
        ImageManager.requestFace = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'faces/', filename, hue, true);
        };
      
        ImageManager.requestParallax = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'parallaxes/', filename, hue, true);
        };
      
        ImageManager.requestPicture = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'pictures/', filename, hue, true);
        };
      
        ImageManager.requestSvActor = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'sv_actors/', filename, hue, false);
        };
      
        ImageManager.requestSvEnemy = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'sv_enemies/', filename, hue, true);
        };
      
        ImageManager.requestSystem = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'system/', filename, hue, false);
        };
      
        ImageManager.requestTileset = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'tilesets/', filename, hue, false);
        };
      
        ImageManager.requestTitle1 = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'titles1/', filename, hue, true);
        };
      
        ImageManager.requestTitle2 = function(filename, hue) {
            return this.requestBitmap(imagesDir + 'titles2/', filename, hue, true);
        };
    
        // The audio portion
        AudioManager._path           = audioDir;
    
    
    })();
  6. Thanks for your hard work! Your script works for the HTML version. I don't have my own server to test it on, but I managed to get it working by opening the .html file with Microsoft Edge (surprisingly this doesn't work with other browsers). I couldn't save the game when playing this way, but I think that's an unrelated issue.

    The script seems to partially work for the EXE version of the game, as it's looking for files in the place I specified using your script (../assets/img). It can't load anything though, and just shows an error (see attached). This leads me to believe that for exe versions of the game that you'd need to use something other than .. to indicate relative paths. I'm very rusty with programming so the only other alternative that I can think of is . but that doesn't work.

    A quick google search tells me RPGMaker was written using Ruby, but I couldn't figure out how Ruby uses relative paths. I also found this thread https://forums.rpgmakerweb.com/index.php?threads/check-if-local-file-exists.50866/ that discusses file paths in RPGMaker, and thought that it might help.

    Thanks again!

    ygcppYh.png
  7. Game 1 has map data in All Games\Game 1\data\
    Game 2 has map data in All Games\Game 2\data\
    Both games load images and tilesets from All Games\Assets\img\

    The scenario that you pointed out only seems suitable for web deployment, in my view and opinion. When you have several games sitting next to each other on a server, you would want to save space and reusing assets when possible. However, I'm not entirely sure it is something that can or should be done with an executable as each game is deployed with their own dll files and whatnot. Also, it doesn't seem like something that would be done on mobile apps either.
  8. Hmmm... I was worried that might be the case. Thank you for your help, hopefully you and other people can make use of the script (and me too if I do make web games).

    Please post if you do find a way to make it work for executables though!
  9. SoapieSoap said:
    Game 1 has map data in All Games\Game 1\data\
    Game 2 has map data in All Games\Game 2\data\
    Both games load images and tilesets from All Games\Assets\img\
    there is a big problem here that will cause you problems when loading data: your filepath does NOT conform to networking rules, and networking rules are required to have the engine load files correctly.

    so please check the directories that you're really using if they conform to networking rules or not.
    In the case of your examples, the problem are the spaces. Spaces are forbidden as part of the filenames and directory names under networking rules.

    you can use a directory named "all_games". You cannot use a directory named "all games" even if windows allows you to do that.
    And there are additional restrictions under networking rules like latin letters only and a limited number of special symbols and so on.


    EDIT:
    And your search got you to wrong data.
    RPG-Makers XP, VX and VXA use a Ruby-Variant.
    RPG-Makers 1995, 2000 and 2003 have no script capacity at all
    and RPG-Maker MV (the one you're appearently using) uses javascript
  10. When I ran the tests the folder names were all one word with no special characters or spaces, so I don't think that was the issue.

    As for using relative paths with javascript... what I found seems to be exclusive for websites so maybe it's just impossible for executable versions of RMMV games. Or is there some other way?

    This is what I was looking at btw: https://stackoverflow.com/questions/2188218/relative-paths-in-javascript-in-an-external-file
    Maybe it can help someone.
  11. Well, I just deployed to an executable to see the filesystem. You may need to make sure that you go up several paths like so: ../../assets/

    The asset files in the .exe deployment are in a folder called www, so you may need to go up another directory if you're trying to share assets with an .exe if it works. Tell me if that works.

    Because, as far as I understand it, I think it should only work for webservers because a webserver and a filesystem work a little differently for security reasons among other things.
  12. Looks like the script probably only works for webservers. I tried using ../../assets/ just now and got the same error that I showed before. Were you able to get your executable version working?