From: Paul Hänsch Date: Mon, 10 Feb 2020 21:50:46 +0000 (+0100) Subject: code shortening X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=c41a891b9f9721581368634b021ffe8f0d8dc658;p=flarejs code shortening --- diff --git a/engine.js b/engine.js index 46cb229..7c92632 100644 --- a/engine.js +++ b/engine.js @@ -1,17 +1,13 @@ var gamedata = { - load: function(def) { - if (this[def]) return this[def]; - else return this[def] = new Textfile(def); - } + load: def => this[def] ? this[def] : this[def] = new Textfile(def) } var gfx = { load: function(def) { - if (this[def]) return this[def]; - else { + if (!this[def]) { this[def] = document.createElement("img"); this[def].setAttribute("src", def); - return this[def]; } + return this[def]; } }; @@ -194,14 +190,14 @@ function Mob(textdef) { f[2], f[3]); } - this.block = function() { this.animate("block" ); return this; }; - this.cast = function() { this.animate("cast" ); return this; }; - this.die = function() { this.animate("die" ); return this; }; - this.hit = function() { this.animate("hit" ); return this; }; - this.run = function() { this.animate("run" ); return this; }; - this.shoot = function() { this.animate("shoot" ); return this; }; - this.stance = function() { this.animate("stance"); return this; }; - this.swing = function() { this.animate("swing" ); return this; }; + this.block = () => this.animate("block" ); + this.cast = () => this.animate("cast" ); + this.die = () => this.animate("die" ); + this.hit = () => this.animate("hit" ); + this.run = () => this.animate("run" ); + this.shoot = () => this.animate("shoot" ); + this.stance = () => this.animate("stance"); + this.swing = () => this.animate("swing" ); } function Hero(gender = "female", hair = "short"){ @@ -248,14 +244,14 @@ function Hero(gender = "female", hair = "short"){ return this; } - this.block = function() { this.animate("block" ); return this; }; - this.cast = function() { this.animate("cast" ); return this; }; - this.die = function() { this.animate("die" ); return this; }; - this.hit = function() { this.animate("hit" ); return this; }; - this.run = function() { this.animate("run" ); return this; }; - this.shoot = function() { this.animate("shoot" ); return this; }; - this.stance = function() { this.animate("stance"); return this; }; - this.swing = function() { this.animate("swing" ); return this; }; + this.block = () => this.animate("block" ); + this.cast = () => this.animate("cast" ); + this.die = () => this.animate("die" ); + this.hit = () => this.animate("hit" ); + this.run = () => this.animate("run" ); + this.shoot = () => this.animate("shoot" ); + this.stance = () => this.animate("stance"); + this.swing = () => this.animate("swing" ); } function Controls(hero, map){