Fixes incorrect and inconsistent tests for undefined.
Removes unused buggy GUI script. Corrects some inconsistent formatting. This was SVN commit r11241.
This commit is contained in:
parent
24f0e123cb
commit
f3a52dd440
@ -1,134 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION : Utility functions that manipulate GUI objects.
|
||||
NOTES :
|
||||
*/
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Hide GUI object.
|
||||
function guiHide (objectName)
|
||||
{
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
if( guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined" )
|
||||
console.write ("guiHide(): GUI Object not found: " + objectName);
|
||||
if( !guiObject.hidden )
|
||||
guiObject.hidden = true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Reveal GUI object.
|
||||
function guiUnHide (objectName)
|
||||
{
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiUnHide(): GUI Object not found: " + objectName);
|
||||
if( guiObject.hidden )
|
||||
guiObject.hidden = false;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Toggle visibility of GUI object.
|
||||
function guiToggle (objectName)
|
||||
{
|
||||
// Get our GUI object
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiToggle(): GUI Object not found: " + objectName);
|
||||
|
||||
// Toggle it
|
||||
guiObject.hidden = !guiObject.hidden;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Enable GUI object.
|
||||
function guiEnable (objectName)
|
||||
{
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiEnable(): GUI Object not found: " + objectName);
|
||||
guiObject.enabled = true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Disable GUI object.
|
||||
function guiDisable (objectName)
|
||||
{
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiDisable(): GUI Object not found: " + objectName);
|
||||
guiObject.enabled = false;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Change caption of GUI object and then make it visible.
|
||||
function guiRenameAndReveal (objectName, objectCaption)
|
||||
{
|
||||
// Get our GUI object
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiRenameAndReveal(): GUI Object not found: " + objectName);
|
||||
|
||||
// Rename it
|
||||
guiObject.caption = objectCaption;
|
||||
|
||||
// Toggle it
|
||||
guiObject.hidden = false;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Increment/decrement the numeric caption of a GUI object.
|
||||
function guiModifyCaption (objectName, objectModifier, objectPlaces)
|
||||
{
|
||||
// Adds a modifier to a GUI object's caption (eg increase a number by 1).
|
||||
// Obviously don't use this unless you're sure the caption contains a number.
|
||||
// objectPlaces specifies the number of decimal places to use for a floating point number.
|
||||
// If not specified, it defaults to zero (whole number).
|
||||
|
||||
// Get our GUI object
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiModifyCaption(): GUI Object not found: " + objectName);
|
||||
|
||||
if (!objectPlaces)
|
||||
objectPlaces = 0;
|
||||
objectPlaces = Math.pow (10, objectPlaces);
|
||||
|
||||
guiObject.caption = (Math.round (objectPlaces * guiObject.caption)
|
||||
+ Math.round (objectPlaces * objectModifier) ) / objectPlaces;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Set caption of a GUI object.
|
||||
function guiSetCaption (objectName, objectCaption)
|
||||
{
|
||||
// Sets an object's caption to the specified value.
|
||||
|
||||
// Get our GUI object
|
||||
var guiObject = getGUIObjectByName (objectName);
|
||||
|
||||
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
|
||||
console.write ("guiSetCaption(): GUI Object not found: " + objectName);
|
||||
|
||||
guiObject.caption = objectCaption;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Helper function that closes a given window (usually the current parent) and opens another one.
|
||||
function guiSwitch (closeWindowName, openWindowName)
|
||||
{
|
||||
guiHide (closeWindowName);
|
||||
guiUnHide (openWindowName);
|
||||
}
|
||||
|
||||
// ====================================================================
|
@ -14,8 +14,6 @@
|
||||
|
||||
<script file="gui/common/functions_utility_list.js" />
|
||||
|
||||
<script file="gui/common/functions_utility_object.js" />
|
||||
|
||||
<script file="gui/common/functions_utility_music.js" />
|
||||
|
||||
<!--
|
||||
|
@ -236,22 +236,6 @@ function blendSubmenuIntoMain(topPosition, bottomPosition)
|
||||
bottomSprite.size = "100%-2 " + (bottomPosition) + " 100% 100%";
|
||||
}
|
||||
|
||||
// Reveals submenu
|
||||
//function openMainMenuSubWindow (windowName)
|
||||
//{
|
||||
// guiUnHide("pgSubWindow");
|
||||
// guiUnHide(windowName);
|
||||
//}
|
||||
|
||||
// Hides submenu
|
||||
//function closeMainMenuSubWindow (windowName)
|
||||
//{
|
||||
// guiHide("pgSubWindow");
|
||||
// guiHide(windowName);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTIONS BELOW DO NOT WORK YET
|
||||
*/
|
||||
|
@ -405,9 +405,9 @@ function getCivCode(player)
|
||||
|
||||
function areAllies(player1, player2)
|
||||
{
|
||||
if ((g_MapSettings.PlayerData[player1].Team == undefined)||(g_MapSettings.PlayerData[player2].Team == undefined)||(g_MapSettings.PlayerData[player2].Team == -1)||(g_MapSettings.PlayerData[player1].Team == -1))
|
||||
if ((g_MapSettings.PlayerData[player1].Team === undefined) || (g_MapSettings.PlayerData[player2].Team === undefined) || (g_MapSettings.PlayerData[player2].Team == -1) || (g_MapSettings.PlayerData[player1].Team == -1))
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -417,7 +417,7 @@ function areAllies(player1, player2)
|
||||
|
||||
function getPlayerTeam(player)
|
||||
{
|
||||
if (g_MapSettings.PlayerData[player].Team == undefined)
|
||||
if (g_MapSettings.PlayerData[player].Team === undefined)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
var EntityTemplate = Class({
|
||||
|
||||
_init: function(template)
|
||||
{
|
||||
_init: function(template) {
|
||||
this._template = template;
|
||||
},
|
||||
|
||||
@ -163,15 +162,13 @@ var EntityTemplate = Class({
|
||||
return this._template.ResourceDropsite.Types.split(/\s+/);
|
||||
},
|
||||
|
||||
garrisonableClasses: function()
|
||||
{
|
||||
garrisonableClasses: function() {
|
||||
if (!this._template.GarrisonHolder)
|
||||
return undefined;
|
||||
return this._template.GarrisonHolder.List._string.split(/\s+/);
|
||||
},
|
||||
|
||||
garrisonMax: function()
|
||||
{
|
||||
garrisonMax: function() {
|
||||
if (!this._template.GarrisonHolder)
|
||||
return undefined;
|
||||
|
||||
@ -179,9 +176,8 @@ var EntityTemplate = Class({
|
||||
},
|
||||
|
||||
//"Population Bonus" is how much a building raises your population cap.
|
||||
getPopulationBonus: function()
|
||||
{
|
||||
if(!this._template.Cost)
|
||||
getPopulationBonus: function() {
|
||||
if (!this._template.Cost)
|
||||
return undefined;
|
||||
|
||||
return this._template.Cost.PopulationBonus;
|
||||
@ -243,8 +239,7 @@ var EntityTemplate = Class({
|
||||
var Entity = Class({
|
||||
_super: EntityTemplate,
|
||||
|
||||
_init: function(baseAI, entity)
|
||||
{
|
||||
_init: function(baseAI, entity) {
|
||||
this._super.call(this, baseAI.GetTemplate(entity.template));
|
||||
|
||||
this._ai = baseAI;
|
||||
@ -289,8 +284,8 @@ var Entity = Class({
|
||||
position: function() { return this._entity.position; },
|
||||
|
||||
isIdle: function() {
|
||||
if (typeof this._entity.idle === "undefined")
|
||||
return undefined;
|
||||
if (this._entity.idle === undefined)
|
||||
return undefined; // Prevent warning about reference to undefined property
|
||||
return this._entity.idle;
|
||||
},
|
||||
|
||||
@ -317,22 +312,25 @@ var Entity = Class({
|
||||
},
|
||||
|
||||
foundationProgress: function() {
|
||||
if (typeof this._entity.foundationProgress === "undefined")
|
||||
return undefined;
|
||||
if (this._entity.foundationProgress === undefined)
|
||||
return undefined; // Prevent warning about reference to undefined property
|
||||
return this._entity.foundationProgress;
|
||||
},
|
||||
|
||||
owner: function() {
|
||||
return this._entity.owner;
|
||||
},
|
||||
|
||||
isOwn: function() {
|
||||
if (typeof this._entity.owner === "undefined")
|
||||
if (this._entity.owner === undefined)
|
||||
return false;
|
||||
return this._entity.owner === this._ai._player;
|
||||
},
|
||||
|
||||
isFriendly: function() {
|
||||
return this.isOwn(); // TODO: diplomacy
|
||||
},
|
||||
|
||||
isEnemy: function() {
|
||||
return !this.isOwn(); // TODO: diplomacy
|
||||
},
|
||||
@ -340,7 +338,7 @@ var Entity = Class({
|
||||
resourceSupplyAmount: function() { return this._entity.resourceSupplyAmount; },
|
||||
|
||||
resourceCarrying: function() { return this._entity.resourceCarrying; },
|
||||
|
||||
|
||||
//Garrison related
|
||||
|
||||
garrisoned: function() { return new EntityCollection(this._ai, this._entity.garrisoned); },
|
||||
@ -349,20 +347,19 @@ var Entity = Class({
|
||||
{
|
||||
return (this.garrisonMax() - this.garrisoned().length);
|
||||
},
|
||||
|
||||
canGarrisonInto: function(target)
|
||||
{
|
||||
|
||||
canGarrisonInto: function(target) {
|
||||
var allowedClasses = target.garrisonableClasses();
|
||||
// return false if the target is full or doesn't have any allowed classes
|
||||
if( target.garrisonSpaceAvaliable() <=0 || allowedClasses == undefined )
|
||||
if (target.garrisonSpaceAvaliable() <=0 || allowedClasses === undefined)
|
||||
return false;
|
||||
|
||||
// Check that this unit is a member of at least one of the allowed garrison classes
|
||||
var hasClasses = this.classes();
|
||||
for( var i = 0; i < hasClasses.length; i++)
|
||||
for (var i = 0; i < hasClasses.length; i++)
|
||||
{
|
||||
var hasClass = hasClasses[i];
|
||||
if( allowedClasses.indexOf(hasClass) >= 0 )
|
||||
if (allowedClasses.indexOf(hasClass) >= 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -370,9 +367,8 @@ var Entity = Class({
|
||||
},
|
||||
|
||||
// TODO: visibility
|
||||
|
||||
attack: function(target)
|
||||
{
|
||||
|
||||
attack: function(target) {
|
||||
Engine.PostCommand({"type": "attack", "entities": [this.id()], "target": target.id(), "queued": false});
|
||||
return this;
|
||||
},
|
||||
@ -400,8 +396,7 @@ var Entity = Class({
|
||||
return this;
|
||||
},
|
||||
|
||||
train: function(type, count, metadata)
|
||||
{
|
||||
train: function(type, count, metadata) {
|
||||
var trainable = this.trainableEntities();
|
||||
if (!trainable)
|
||||
{
|
||||
@ -423,18 +418,16 @@ var Entity = Class({
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
//ungarrison a specific unit in this building
|
||||
unload: function(unit)
|
||||
{
|
||||
unload: function(unit) {
|
||||
if (!this._template.GarrisonHolder)
|
||||
return;
|
||||
|
||||
Engine.PostCommand({"type": "unload", "garrisonHolder": this.id(), "entity": unit.id()});
|
||||
},
|
||||
|
||||
unloadAll: function()
|
||||
{
|
||||
unloadAll: function() {
|
||||
if (!this._template.GarrisonHolder)
|
||||
return;
|
||||
|
||||
|
@ -230,7 +230,7 @@ var GameState = Class({
|
||||
findFoundations: function(template)
|
||||
{
|
||||
return this.getOwnEntities().filter(function(ent) {
|
||||
return (typeof ent.foundationProgress() !== "undefined");
|
||||
return (ent.foundationProgress() !== undefined);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -236,7 +236,7 @@ GameState.prototype.findBuilders = function(template) {
|
||||
|
||||
GameState.prototype.findFoundations = function(template) {
|
||||
return this.getOwnEntities().filter(function(ent) {
|
||||
return (typeof ent.foundationProgress() !== "undefined");
|
||||
return (ent.foundationProgress() !== undefined);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -48,7 +48,7 @@ var Timer = function() {
|
||||
// Check if a alarm has reached its interval.
|
||||
this.checkTimer = function(gameState,id) {
|
||||
var alarm = get_alarm(id);
|
||||
if (alarm == undefined)
|
||||
if (alarm === undefined)
|
||||
return false;
|
||||
if (!alarm.active)
|
||||
return false;
|
||||
|
@ -175,7 +175,7 @@ var GameState = Class({
|
||||
findFoundations: function(template)
|
||||
{
|
||||
return this.getOwnEntities().filter(function(ent) {
|
||||
return (typeof ent.foundationProgress() !== "undefined");
|
||||
return (ent.foundationProgress() !== undefined);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -106,7 +106,7 @@ Barter.prototype.ExchangeResources = function(playerEntity, resourceToSell, reso
|
||||
this.priceDifferences[resourceToBuy] = Math.min(99-CONSTANT_DIFFERENCE, Math.max(CONSTANT_DIFFERENCE-99, this.priceDifferences[resourceToBuy]));
|
||||
}
|
||||
|
||||
if (this.restoreTimer == undefined)
|
||||
if (this.restoreTimer === undefined)
|
||||
{
|
||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
this.restoreTimer = cmpTimer.SetInterval(this.entity, IID_Barter, "ProgressTimeout", RESTORE_TIMER_INTERVAL, RESTORE_TIMER_INTERVAL, {});
|
||||
|
@ -1895,11 +1895,11 @@ UnitAI.prototype.SelectAnimation = function(name, once, speed, sound)
|
||||
}
|
||||
|
||||
// Set default values if unspecified
|
||||
if (typeof once == "undefined")
|
||||
if (once === undefined)
|
||||
once = false;
|
||||
if (typeof speed == "undefined")
|
||||
if (speed === undefined)
|
||||
speed = 1.0;
|
||||
if (typeof soundgroup == "undefined")
|
||||
if (soundgroup === undefined)
|
||||
soundgroup = "";
|
||||
|
||||
cmpVisual.SelectAnimation(name, once, speed, soundgroup);
|
||||
|
Loading…
Reference in New Issue
Block a user