Refactor away from '== null' checks towards isSet
This commit is contained in:
@@ -48,7 +48,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var viewrect = this.viewRectangle();
|
var viewrect = this.viewRectangle();
|
||||||
if ( viewrect == null ) {
|
if ( isSet(viewrect) == false ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var sprrect = positiveRectangle(spr.x, spr.y, 32, 32);
|
var sprrect = positiveRectangle(spr.x, spr.y, 32, 32);
|
||||||
@@ -64,7 +64,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
|
|
||||||
this.startAwarenessTimer = function() {
|
this.startAwarenessTimer = function() {
|
||||||
this.awareness_change_enabled = false;
|
this.awareness_change_enabled = false;
|
||||||
if ( this.awareness_timer !== null )
|
if ( isSet(this.awareness_timer) )
|
||||||
this.awareness_timer.stop();
|
this.awareness_timer.stop();
|
||||||
this.awareness_timer = game.time.create(false);
|
this.awareness_timer = game.time.create(false);
|
||||||
this.awareness_timer.add(this.sprite_awareness_duration,
|
this.awareness_timer.add(this.sprite_awareness_duration,
|
||||||
@@ -94,7 +94,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.startAwarenessTimer();
|
this.startAwarenessTimer();
|
||||||
setAwarenessState(this, state);
|
setAwarenessState(this, state);
|
||||||
|
|
||||||
if ( this.awareness_effect !== null ) {
|
if ( isSet(this.awareness_effect) ) {
|
||||||
this.awareness_effect.alive = false;
|
this.awareness_effect.alive = false;
|
||||||
this.awareness_effect.destroy();
|
this.awareness_effect.destroy();
|
||||||
this.awareness_effect = null;
|
this.awareness_effect = null;
|
||||||
@@ -138,7 +138,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.clearWordBubble = function() {
|
this.clearWordBubble = function() {
|
||||||
if ( this.bubble_text !== null )
|
if ( isSet(this.bubble_text) )
|
||||||
this.clear_bubble = true;
|
this.clear_bubble = true;
|
||||||
this.enable_word_bubble = false;
|
this.enable_word_bubble = false;
|
||||||
this.timer = game.time.create(false);
|
this.timer = game.time.create(false);
|
||||||
@@ -148,7 +148,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
|
|
||||||
this.setWordBubble = function()
|
this.setWordBubble = function()
|
||||||
{
|
{
|
||||||
if ( this.bubble_text !== null ||
|
if ( isSet(this.bubble_text) ||
|
||||||
this.sprite_group == undefined ||
|
this.sprite_group == undefined ||
|
||||||
this.enable_world_bubble == false) {
|
this.enable_world_bubble == false) {
|
||||||
return;
|
return;
|
||||||
@@ -336,7 +336,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.animations.stop();
|
this.animations.stop();
|
||||||
this.animations.play(getMovingAnimationName(this));
|
this.animations.play(getMovingAnimationName(this));
|
||||||
this.animations.stop();
|
this.animations.stop();
|
||||||
if ( this.rotation_timer !== null ) {
|
if ( isSet(this.rotation_timer) ) {
|
||||||
this.rotation_timer.stop();
|
this.rotation_timer.stop();
|
||||||
this.rotation_timer = null;
|
this.rotation_timer = null;
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.path_set(target, true, maxsteps, useNearestWalkable);
|
this.path_set(target, true, maxsteps, useNearestWalkable);
|
||||||
this.path_tween_start(movingstate);
|
this.path_tween_start(movingstate);
|
||||||
} else {
|
} else {
|
||||||
if ( this.rotation_timer == null ) {
|
if ( isSet(this.rotation_timer) == false ) {
|
||||||
this.rotation_timer = game.time.create(false);
|
this.rotation_timer = game.time.create(false);
|
||||||
timerev = this.rotation_timer.add(250, this.turnUnseenDirection, this);
|
timerev = this.rotation_timer.add(250, this.turnUnseenDirection, this);
|
||||||
this.rotation_timer.start()
|
this.rotation_timer.start()
|
||||||
@@ -406,26 +406,27 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.action_reportplayer = function()
|
this.action_reportplayer = function()
|
||||||
{
|
{
|
||||||
if ( (this.path.length < 1) || this.path_index >= this.path.length) {
|
if ( (this.path.length < 1) || this.path_index >= this.path.length) {
|
||||||
if ( this.target == null &&
|
if ( isSet(this.target) == false &&
|
||||||
hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
||||||
var aiSprites = game.state.states.game.aiSprites;
|
var aiSprites = game.state.states.game.aiSprites;
|
||||||
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
|
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
|
||||||
} else if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
} else if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
||||||
if ( this.target.rotation_timer !== null ) {
|
if ( isSet(this.target) ) {
|
||||||
this.target.rotation_timer.stop();
|
if ( isSet(this.target.rotation_timer) ) {
|
||||||
this.target.rotation_timer = null;
|
this.target.rotation_timer.stop();
|
||||||
|
this.target.rotation_timer = null;
|
||||||
|
}
|
||||||
|
if ( isSet(this.target.sprite_group) ) {
|
||||||
|
this.target.path_purge();
|
||||||
|
this.target.setAwarenessEffect(STATE_ALERTED);
|
||||||
|
this.target.target = this.lastSawPlayerAt;
|
||||||
|
addState(this.target, STATE_RUNNINGTOREPORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.target.path_purge();
|
|
||||||
this.target.setAwarenessEffect(STATE_ALERTED);
|
|
||||||
this.target.target = this.lastSawPlayerAt;
|
|
||||||
addState(this.target, STATE_RUNNINGTOREPORT);
|
|
||||||
|
|
||||||
this.path_tween_stop();
|
this.path_tween_stop();
|
||||||
this.path_purge();
|
this.path_purge();
|
||||||
var staticLights = game.state.states.game.staticLights;
|
var staticLights = game.state.states.game.staticLights;
|
||||||
this.target = nearestInGroup(this, staticLights);
|
this.target = nearestInGroup(this, staticLights);
|
||||||
console.log("Running to the nearest light");
|
|
||||||
console.log(this.target);
|
|
||||||
addState(this, STATE_RUNNINGTOLIGHT);
|
addState(this, STATE_RUNNINGTOLIGHT);
|
||||||
} else {
|
} else {
|
||||||
this.awareness_timer.stop();
|
this.awareness_timer.stop();
|
||||||
@@ -437,7 +438,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( this.target !== null ) {
|
if ( isSet(this.target) ) {
|
||||||
this.chasetarget(this.target,
|
this.chasetarget(this.target,
|
||||||
STATE_ALERTED,
|
STATE_ALERTED,
|
||||||
STATE_MOVING | STATE_RUNNING,
|
STATE_MOVING | STATE_RUNNING,
|
||||||
@@ -469,7 +470,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
{
|
{
|
||||||
if ( this.ready_to_update == false )
|
if ( this.ready_to_update == false )
|
||||||
return;
|
return;
|
||||||
if ( this.awareness_effect !== null ) {
|
if ( isSet(this.awareness_effect) ) {
|
||||||
if ( this.awareness_effect.alive == false ) {
|
if ( this.awareness_effect.alive == false ) {
|
||||||
this.awareness_effect.destroy();
|
this.awareness_effect.destroy();
|
||||||
this.awareness_effect = null;
|
this.awareness_effect = null;
|
||||||
@@ -479,7 +480,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.bubble_text !== null ) {
|
if ( isSet(this.bubble_text) ) {
|
||||||
if ( this.clear_bubble == true ) {
|
if ( this.clear_bubble == true ) {
|
||||||
this.bubble_text.destroy();
|
this.bubble_text.destroy();
|
||||||
this.bubble_sprite.destroy();
|
this.bubble_sprite.destroy();
|
||||||
@@ -505,7 +506,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.update_new_values = function() {
|
this.update_new_values = function() {
|
||||||
if ( this.timer !== null )
|
if ( isSet(this.timer) )
|
||||||
this.timer.stop();
|
this.timer.stop();
|
||||||
this.animations.destroy();
|
this.animations.destroy();
|
||||||
this.clearWordBubble();
|
this.clearWordBubble();
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ GameState.prototype.update = function()
|
|||||||
if ( this.aiSprites.debug == true ) {
|
if ( this.aiSprites.debug == true ) {
|
||||||
function _draw_viewrect(x) {
|
function _draw_viewrect(x) {
|
||||||
var r = x.viewRectangle();
|
var r = x.viewRectangle();
|
||||||
if ( r == null )
|
if ( isSet(r) )
|
||||||
return;
|
return;
|
||||||
this.shadowTexture.context.fillStyle = 'rgb(128, 128, 128)';
|
this.shadowTexture.context.fillStyle = 'rgb(128, 128, 128)';
|
||||||
this.shadowTexture.context.fillRect(r.left,
|
this.shadowTexture.context.fillRect(r.left,
|
||||||
@@ -292,7 +292,7 @@ GameState.prototype.update = function()
|
|||||||
this.aiSprites.forEach(_draw_viewrect, this);
|
this.aiSprites.forEach(_draw_viewrect, this);
|
||||||
function _draw_aipath(x) {
|
function _draw_aipath(x) {
|
||||||
var p = x.path;
|
var p = x.path;
|
||||||
if ( p == null )
|
if ( isSet(p) )
|
||||||
return;
|
return;
|
||||||
this.shadowTexture.context.fillStyle = 'rgb(255, 128, 128)';
|
this.shadowTexture.context.fillStyle = 'rgb(255, 128, 128)';
|
||||||
p.forEach(function(r) {
|
p.forEach(function(r) {
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ SoundSprite.prototype = Object.create(Phaser.Sprite.prototype);
|
|||||||
SoundSprite.prototype.constructor = Light;
|
SoundSprite.prototype.constructor = Light;
|
||||||
|
|
||||||
SoundSprite.prototype.update_new_values = function() {
|
SoundSprite.prototype.update_new_values = function() {
|
||||||
if ( this.sound_key == null ) {
|
if ( isSet(this.sound_key) == false ) {
|
||||||
if ( this.sound !== null ) {
|
if ( isSet(this.sound) ) {
|
||||||
this.sound.stop();
|
this.sound.stop();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -42,7 +42,7 @@ SoundSprite.prototype.update_new_values = function() {
|
|||||||
this.sound_forcerestart = parseBoolean(this.sound_forcerestart);
|
this.sound_forcerestart = parseBoolean(this.sound_forcerestart);
|
||||||
this.sound_nofade = parseBoolean(this.sound_nofade);
|
this.sound_nofade = parseBoolean(this.sound_nofade);
|
||||||
|
|
||||||
if ( this.sound !== null )
|
if ( isSet(this.sound) )
|
||||||
this.sound.stop();
|
this.sound.stop();
|
||||||
this.sound = game.add.audio(this.sound_key, this.sound_volume, this.sound_loop);
|
this.sound = game.add.audio(this.sound_key, this.sound_volume, this.sound_loop);
|
||||||
this.sound.play(
|
this.sound.play(
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ function nearestWalkableTile(spr)
|
|||||||
|
|
||||||
for ( var i = 1 ; i < 100 ; i++ ) {
|
for ( var i = 1 ; i < 100 ; i++ ) {
|
||||||
var rv = _walkable_inner(i);
|
var rv = _walkable_inner(i);
|
||||||
if ( rv !== null ) {
|
if ( isSet(rv) ) {
|
||||||
console.log("Found near walkable tile");
|
console.log("Found near walkable tile");
|
||||||
console.log([rv] + [spr.x / 32, spr.y / 32]);
|
console.log([rv] + [spr.x / 32, spr.y / 32]);
|
||||||
return rv
|
return rv
|
||||||
|
|||||||
Reference in New Issue
Block a user