Author Topic: Use JavaScript Function Notation (JSFN) instead of XML  (Read 1068 times)

MuwuM

  • Ornithopter
  • *****
  • Posts: 426
  • No Game without Move(ment)
    • View Profile
    • MuwuM - Lexicons
I recommend to use JavaScript Function Notation (JSFN) instead of XML in MegaGlest.

Here is a sample unit.jsfn
Code: [Select]

function jsfnUnit(){
this.parameters = function(){
this.size = function(){return 2;};
this.height = function(){return 2;};
this['max-hp'] = function(){return 800;};
this['max-hp-regeneration'] = function(){return 2;};
this['max-ep'] = function(){return 100;};
this['max-ep-regeneration'] = function(){return 5;};
this.armor = function(){return 20;};
this['armor-type']  = function(){return 20;};
this.sight = function(){return 15;};
this.time = function(){return 100;};
...
};
this.skills = function(){
return [
function(){
this.type =  function(){return 'stop';};
this.name =  function(){return 'stop_skill';};
this.speed =  function(){return 100;};
...
},function(){
this.type =  function(){return 'attack';};
this.name =  function(){return 'attack_skill';};
this.speed =  function(){return 150;};
...
},
...
];
};
this.commands = function(){
return [...];
};
}


Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Use JavaScript Function Notation (JSFN) instead of XML
« Reply #1 on: 1 April 2014, 17:44:39 »
That could be very interesting. We could modify the values returned by using conditionals and such. However, I don't think this provides much difference unless an API is also provided to allow access to data like the player type (then mega CPUs could be given units with higher stats), map size, scenario name (if any; would allow the same faction to work differently in a scenario), etc.

It would create a bit of overhead, though, as we'd have to run a JavaScript engine when loading everything in the beginning, which I imagine would be far slower than parsing a static file.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

MoLAoS

  • Ornithopter
  • *****
  • Posts: 433
    • View Profile
Re: Use JavaScript Function Notation (JSFN) instead of XML
« Reply #2 on: 1 April 2014, 17:51:13 »
That could be very interesting. We could modify the values returned by using conditionals and such. However, I don't think this provides much difference unless an API is also provided to allow access to data like the player type (then mega CPUs could be given units with higher stats), map size, scenario name (if any; would allow the same faction to work differently in a scenario), etc.

It would create a bit of overhead, though, as we'd have to run a JavaScript engine when loading everything in the beginning, which I imagine would be far slower than parsing a static file.

The MegaCPU thing is possible with XML, too. And the other stuff you mentioned.

In order to justify a large change, there should be obvious benefits to functionality or performance or usability. I wish Muwum would have explained in his original post what he expects the benefits of such a change to be.

MuwuM

  • Ornithopter
  • *****
  • Posts: 426
  • No Game without Move(ment)
    • View Profile
    • MuwuM - Lexicons
Re: Use JavaScript Function Notation (JSFN) instead of XML
« Reply #3 on: 1 April 2014, 19:39:10 »
This actually was meant to be an april fool (as JSFN combines giant overhead with bad performance with big security risk)

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Use JavaScript Function Notation (JSFN) instead of XML
« Reply #4 on: 2 April 2014, 11:49:21 »
Oh. Haha.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: Use JavaScript Function Notation (JSFN) instead of XML
« Reply #5 on: 2 April 2014, 14:40:32 »
 :O
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

 

anything