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 dominic

You could create a module, so the file loads on the client, and then write a bit of code for nodejs, so that it understands Impact's module loader. Could be as simple as this:
ig = {
	module: function() { return ig; },
	requires: function() { return ig; },
	defines: function( func ) { 
		func(); // immediately execute
	},
};

1 decade ago by ooker

I just came across node-impact-emu:
http://impactjs.com/forums/code/impactjs-emulation-layer-for-node-js-use-modules-and-classes-on-both-client-and-server

Which sounds exactly what I am looking for.

Has anyone else tried node-impact-emu?

The example that comes with it works fine, but as soon as I try to require a module that uses impact (e.g. game.entities.player) I get this error:


node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: window is not defined

Am I doing something wrong? Has anyone else been able to get node-impact-emu to work with impact classes and modules?

Thanks!

1 decade ago by ShawnSwander

ooker it looks awesome but I dont understand what files I put where to make it work

1 decade ago by Joncom

Quote from dominic
You could create a module, so the file loads on the client, and then write a bit of code for nodejs, so that it understands Impact's module loader. Could be as simple as this:
ig = {
	module: function() { return ig; },
	requires: function() { return ig; },
	defines: function( func ) { 
		func(); // immediately execute
	},
};

Would you be so kind as to elabourate on how to do this? I understand that that is the format a module takes, but how does one go about "parsing" its parts.

Would we, for example, end up with something like var execute which would contain the code:
func(); // immediately execute

...in the form of a string?
Page 1 of 1
« first « previous next › last »