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 crowbar_of_irony

Hi all,

I am looking for a way to add custom level information to a level - I could edit the level JS file directly, but it will be overriden the next I save to it. The information I am adding are quite a bit - about two or three arrays, so I don't want to add it via a void entity.

Any advice will be welcomed!

1 decade ago by Joncom

so I don't want to add it via a void entity
I don't see what other option you have...

1 decade ago by jerev

Something like this? http://www.screenr.com/VkxH

Then check out: http://impactjs.com/forums/code/weltmeister-plugins-setting-a-standard

Even if the UI is not good enouhg to enter your arrays, editing the level file directly with this plugin, will make sure it stays in it.

1 decade ago by dominic

You can just add some additional properties in the level files with your text editor. Weltmeister will leave those properties as they are when loading and saving levels:
Level1=/*JSON[*/{
	"info": { 
		"title": "My Awesome Level 1"
	}
	"entities": [...],
	"layer": [...]
}/*]JSON*/;

Turn on "prettyPrint" in your lib/weltmeister/config.js to have a better oveview.

You can then grab the info by overwriting your Game&039;s #.loadLevel() method:

loadLevel: function( data ) {
	console.log( data.info.title );
	this.parent( data );
}

1 decade ago by nmoliveira

Weltmeister will leave those properties as they are when loading and saving levels


It doesn't work for me.. Weltmeister overrides my custom properties as soon as I save the level! Working with ImpactJS 1.23

Any thoughts about this?

1 decade ago by dominic

Somehow, this feature got lost some time ago. I apologize.

I have fixed this in the git repo on your download page.

1 decade ago by nmoliveira

@Dominic Awesome! I've downloaded and tested, works as expected! Thank you for the quick feedback!

Regards,

Nuno Oliveira

1 decade ago by stahlmanDesign

Another way that does not require modifying the level file is to create a simple entity called Levelname and put it in the level. Then give its name the name of the level.

Now in the function loadLevel(data) you can check for the entity of type EntityLevelname and get the value.
/><br />
<pre class= loadLevel: function(data) { var levelJustLoaded = ""; if (data.entities){ for (var i = 0; i < data.entities.length; i ++){ if (data.entities[i].type == "EntityLevelname") { levelJustLoaded = data.entities[i].settings.name; } } } }
Page 1 of 1
« first « previous next › last »