Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ooker

I am working on an MMO with ImpactJS.
I have some javascript files that I include on the server with require
e.g.
mmoTypes.js:
mmoTypes = {
Messages: {
JOIN: 0,
SPAWN: 1,
MOVE: 2
}
};

I'd like to be able to use this file as-is on the client, but it seems that to use the Impact class loader, I need to create a module, etc. and as a result I need two different files...One on the server without the module business and one on the client with all the ig module stuff.

I'd like to have just one file, so as I make changes, I make them in just one file.

Does anyone have a recommended way to do this?

1 decade ago by TimJRobinson

If you're using NodeJS and the game and server files are in the same folder you can do the following:

Have a config.js or messages.js file that sits in your main game folder. Then in this file you have a json object for all your game settings / messages such as so:

var config = {
    game: {
        name: "My Game"
    },
    enemies: {
        goblin: {
            name: "gog"
        }
    }
}

Then after all that config check if the window object exists and if it does bind the config to that or otherwise bind it to module.exports like so:

if (typeof window !== "undefined") {
    window.gameConfig = config;
} else {
    module.exports = config;
}

Then in your game code you can have:

.defines(function(){
  MyGame = ig.Game.extend({
      config: window.gameConfig
  });
});

and on your server have:

config = require('config');
Page 1 of 1
« first « previous next › last »