Ticket #1201: hasClass.patch
File hasClass.patch, 4.4 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
255 255 switch (action) 256 256 { 257 257 case "garrison": 258 if ( isUnit(entState) && targetState.garrisonHolder && playerOwned)258 if (hasClass(entState, "Unit") && targetState.garrisonHolder && playerOwned) 259 259 { 260 260 var allowedClasses = targetState.garrisonHolder.allowedClasses; 261 261 for each (var unitClass in entState.identity.classes) … … 474 474 var entState = GetEntityState(ent); 475 475 if (!entState) 476 476 continue; 477 if ( isUnit(entState))477 if (hasClass(entState, "Unit")) 478 478 preferredEnts.push(ent); 479 479 480 480 entStateList.push(entState); … … 483 483 // If there are no units, check if there are defensive entities in the selection 484 484 if (!preferredEnts.length) 485 485 for (var i = 0; i < ents.length; i++) 486 if ( isDefensive(entStateList[i]))486 if (hasClass(entStateList[i], "Defensive")) 487 487 preferredEnts.push(ents[i]); 488 488 489 489 return preferredEnts; … … 496 496 for each (var ent in ents) 497 497 { 498 498 var entState = GetEntityState(ent); 499 if (! isSupport(entState))499 if (!hasClass(entState, "Support")) 500 500 militaryEnts.push(ent); 501 501 } 502 502 return militaryEnts; … … 1355 1355 if (entity) 1356 1356 { 1357 1357 var entState = GetEntityState(entity); 1358 if (entState && isUnit(entState))1358 if (entState && hasClass(entState, "Unit")) 1359 1359 { 1360 1360 Engine.CameraFollow(entity); 1361 1361 return; -
binaries/data/mods/public/gui/session/unit_commands.js
512 512 } 513 513 514 514 var formations = getEntityFormationsList(entState); 515 if ( isUnit(entState) && !isAnimal(entState) && !entState.garrisonHolder && formations.length)515 if (hasClass(entState, "Unit") && !hasClass(entState, "Animal") && !entState.garrisonHolder && formations.length) 516 516 { 517 517 setupUnitPanel("Formation", usedPanels, entState, formations, 518 518 function (item) { performFormation(entState.id, item); } ); … … 521 521 // TODO: probably should load the stance list from a data file, 522 522 // and/or vary depending on what units are selected 523 523 var stances = ["violent", "aggressive", "passive", "defensive", "stand"]; 524 if ( isUnit(entState) && !isAnimal(entState) && !entState.garrisonHolder && stances.length)524 if (hasClass(entState, "Unit") && !hasClass(entState, "Animal") && !entState.garrisonHolder && stances.length) 525 525 { 526 526 setupUnitPanel("Stance", usedPanels, entState, stances, 527 527 function (item) { performStance(entState.id, item); } ); -
binaries/data/mods/public/gui/session/utility_functions.js
94 94 return false; 95 95 } 96 96 97 function isUnit(entState)98 {99 if (entState.identity)100 {101 var classes = entState.identity.classes;102 if (classes && classes.length)103 return (classes.indexOf("Unit") != -1);104 }105 return false;106 }107 108 function isAnimal(entState)109 {110 if (entState.identity)111 {112 var classes = entState.identity.classes;113 if (classes && classes.length)114 return (classes.indexOf("Animal") != -1);115 }116 return false;117 }118 119 function isStructure(entState)120 {121 if (entState.identity)122 {123 var classes = entState.identity.classes;124 if (classes && classes.length)125 return (classes.indexOf("Structure") != -1);126 }127 return false;128 }129 130 function isDefensive(entState)131 {132 if (entState.identity)133 {134 var classes = entState.identity.classes;135 if (classes && classes.length)136 return (classes.indexOf("Defensive") != -1);137 }138 return false;139 }140 141 function isSupport(entState)142 {143 if (entState.identity)144 {145 var classes = entState.identity.classes;146 if (classes && classes.length)147 return (classes.indexOf("Support") != -1);148 }149 return false;150 }151 152 97 function damageTypesToTextStacked(dmg) 153 98 { 154 99 if (!dmg) … … 253 198 "icon": "kill_small.png" 254 199 }); 255 200 256 if ( isUnit(entState))201 if (hasClass(entState, "Unit")) 257 202 { 258 203 commands.push({ 259 204 "name": "garrison",