Ticket #3180: auravisualisation.2.diff
File auravisualisation.2.diff, 19.7 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/AuraManager.js
39 39 return k; 40 40 }; 41 41 42 AuraManager.prototype.ApplyBonus = function(value, ent , data, key)42 AuraManager.prototype.ApplyBonus = function(value, ents, data, key) 43 43 { 44 var dataList = this.ensureExists("modifications", value, ent, key, {"add":0, "multiply":1}); 44 for (let ent of ents) 45 { 46 var dataList = this.ensureExists("modifications", value, ent, key, {"add":0, "multiply":1}); 45 47 46 dataList.push(data);48 dataList.push(data); 47 49 48 if (dataList.length > 1)49 return;50 if (dataList.length > 1) 51 continue; 50 52 51 // first time added this aura52 if (data.multiply)53 this.modificationsCache[value][ent].multiply *= data.multiply;53 // first time added this aura 54 if (data.multiply) 55 this.modificationsCache[value][ent].multiply *= data.multiply; 54 56 55 if (data.add)56 this.modificationsCache[value][ent].add += data.add;57 58 // post message to the entity to notify it about the change59 Engine.PostMessage(ent, MT_ValueModification, { "entities": [ent], "component": value.split("/")[0], "valueNames": [value] });57 if (data.add) 58 this.modificationsCache[value][ent].add += data.add; 59 // post message to the entity to notify it about the change 60 Engine.PostMessage(ent, MT_ValueModification, { "entities": [ent], "component": value.split("/")[0], "valueNames": [value] }); 61 } 60 62 }; 61 63 62 64 AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, data, key) … … 84 86 Engine.PostMessage(SYSTEM_ENTITY, MT_TemplateModification, { "player": player, "component": value.split("/")[0], "valueNames": [value] }); 85 87 }; 86 88 87 AuraManager.prototype.RemoveBonus = function(value, ent , key)89 AuraManager.prototype.RemoveBonus = function(value, ents, key) 88 90 { 89 var v = this.modifications[value]; 90 if (!v) 91 return; 92 var e = v[ent]; 93 if (!e) 94 return; 95 var dataList = e[key]; 96 if (!dataList || !dataList.length) 97 return; 91 for (let ent of ents) 92 { 93 var v = this.modifications[value]; 94 if (!v) 95 continue; 96 var e = v[ent]; 97 if (!e) 98 continue; 99 var dataList = e[key]; 100 if (!dataList || !dataList.length) 101 continue; 98 102 99 // get the applied data to remove again100 var data = dataList.pop();103 // get the applied data to remove again 104 var data = dataList.pop(); 101 105 102 if (dataList.length > 0)103 return;106 if (dataList.length > 0) 107 continue; 104 108 105 // out of last aura of this kind, remove modifications106 if (data.add)107 this.modificationsCache[value][ent].add -= data.add;109 // out of last aura of this kind, remove modifications 110 if (data.add) 111 this.modificationsCache[value][ent].add -= data.add; 108 112 109 if (data.multiply)110 this.modificationsCache[value][ent].multiply /= data.multiply;111 112 // post message to the entity to notify it about the change113 Engine.PostMessage(ent, MT_ValueModification, { "entities": [ent], "component": value.split("/")[0], "valueNames": [value] });113 if (data.multiply) 114 this.modificationsCache[value][ent].multiply /= data.multiply; 115 // post message to the entity to notify it about the change 116 Engine.PostMessage(ent, MT_ValueModification, { "entities": [ent], "component": value.split("/")[0], "valueNames": [value] }); 117 } 114 118 }; 115 119 116 120 AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key) -
binaries/data/mods/public/simulation/components/Auras.js
47 47 "<text/>" + 48 48 "</element>" + 49 49 "</optional>" + 50 "<optional>" + 51 "<element name='OverlayIcon' a:help='Icon to show on the entities affected by this aura'>" + 52 "<text/>" + 53 "</element>" + 54 "</optional>" + 50 55 "<element name='Affects' a:help='Affected classes'>" + 51 56 "<text/>" + 52 57 "</element>" + … … 103 108 return Object.keys(this.template); 104 109 }; 105 110 111 Auras.prototype.GetOverlayIcon = function(name) 112 { 113 return this.template[name].OverlayIcon || ""; 114 }; 115 116 Auras.prototype.GetAffectedEntities = function(name) 117 { 118 return this[name].targetUnits; 119 }; 120 106 121 Auras.prototype.GetRange = function(name) 107 122 { 108 123 if (!this.IsRangeAura(name)) … … 136 151 137 152 this.affectedPlayers[name] = []; 138 153 139 var cmpPlayer = QueryOwnerInterface(this.entity , IID_Player);154 var cmpPlayer = QueryOwnerInterface(this.entity); 140 155 141 156 if (!cmpPlayer) 142 157 return; 143 158 144 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 145 var numPlayers = cmpPlayerManager.GetNumPlayers(); 159 var numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); 146 160 147 161 for (var i = 0; i < numPlayers; ++i) 148 162 { 149 for each (var p inaffectedPlayers)163 for (let p of affectedPlayers) 150 164 { 151 165 if (p == "Player" ? cmpPlayer.GetPlayerID() == i : cmpPlayer["Is" + p](i)) 152 166 { … … 159 173 160 174 Auras.prototype.HasFormationAura = function() 161 175 { 162 return this.GetAuraNames().some( this.IsFormationAura.bind(this));176 return this.GetAuraNames().some(n => this.IsFormationAura(n)); 163 177 }; 164 178 165 179 Auras.prototype.HasGarrisonAura = function() 166 180 { 167 return this.GetAuraNames().some( this.IsGarrisonAura.bind(this));181 return this.GetAuraNames().some(n => this.IsGarrisonAura(n)); 168 182 }; 169 183 170 184 Auras.prototype.HasGarrisonedUnitsAura = function() 171 185 { 172 return this.GetAuraNames().some( this.IsGarrisonedUnitsAura.bind(this));186 return this.GetAuraNames().some(n => this.IsGarrisonedUnitsAura(n)); 173 187 }; 174 188 175 189 Auras.prototype.GetType = function(name) … … 211 225 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 212 226 var auraNames = this.GetAuraNames(); 213 227 // remove all bonuses 214 for each (var name inauraNames)228 for (let name of auraNames) 215 229 { 216 230 if (!this[name]) 217 231 continue; … … 219 233 if (this.IsGlobalAura(name)) 220 234 this.RemoveTemplateBonus(name); 221 235 222 for each(var ent in this[name].targetUnits) 223 this.RemoveBonus(name, ent); 236 this.RemoveBonus(name, this[name].targetUnits); 224 237 225 238 if (this[name].rangeQuery) 226 239 cmpRangeManager.DestroyActiveQuery(this[name].rangeQuery); 227 240 } 228 241 229 for each (var name inauraNames)242 for (let name of auraNames) 230 243 { 231 244 // only calculate the affected players on re-applying the bonuses 232 245 // this makes sure the template bonuses are removed from the correct players … … 277 290 278 291 Auras.prototype.OnRangeUpdate = function(msg) 279 292 { 280 var auraNames = this.GetAuraNames() ;281 for each (var n inauraNames)293 var auraNames = this.GetAuraNames().filter(n => msg.tag == this[n].rangeQuery); 294 for (let name of auraNames) 282 295 { 283 if (msg.tag == this[n].rangeQuery) 284 { 285 var name = n; 286 break; 287 } 296 this.ApplyBonus(name, msg.added); 297 this.RemoveBonus(name, msg.removed); 288 298 } 289 290 if (!name)291 return;292 293 var targetUnits = this[name].targetUnits;294 var classes = this.GetClasses(name);295 296 if (msg.added.length > 0)297 {298 var validList = this.GiveMembersWithValidClass(name, msg.added);299 for each (var e in validList)300 {301 targetUnits.push(e);302 this.ApplyBonus(name, e);303 }304 }305 306 if (msg.removed.length > 0)307 {308 for each (var e in msg.removed)309 {310 targetUnits.splice(targetUnits.indexOf(e), 1);311 this.RemoveBonus(name, e);312 }313 }314 315 299 }; 316 300 317 301 Auras.prototype.OnGarrisonedUnitsChanged = function(msg) 318 302 { 319 var auraNames = this.GetAuraNames() ;320 for each (var name inauraNames)303 var auraNames = this.GetAuraNames().filter(n => this.IsGarrisonedUnitsAura(n)); 304 for (let name of auraNames) 321 305 { 322 if (!this.IsGarrisonedUnitsAura(name)) 323 continue; 324 for each (var ent in msg.added) 325 this.ApplyBonus(name, ent); 326 for each (var ent in msg.removed) 327 this.RemoveBonus(name, ent); 306 this.ApplyBonus(name, msg.added); 307 this.RemoveBonus(name, msg.removed); 328 308 } 329 309 }; 330 310 331 311 Auras.prototype.ApplyFormationBonus = function(memberList) 332 312 { 333 var auraNames = this.GetAuraNames(); 334 for each (var name in auraNames) 335 { 336 if (!this.IsFormationAura(name)) 337 continue; 338 339 var validList = this.GiveMembersWithValidClass(name, memberList); 340 for each (var ent in validList) 341 { 342 this[name].targetUnits.push(ent); 343 this.ApplyBonus(name,ent); 344 } 345 } 313 var auraNames = this.GetAuraNames().filter(n => this.IsFormationAura(n)); 314 for (let name of auraNames) 315 this.ApplyBonus(name, memberList); 346 316 }; 347 317 348 318 Auras.prototype.ApplyGarrisonBonus = function(structure) 349 319 { 350 var auraNames = this.GetAuraNames(); 351 for each (var name in auraNames) 352 { 353 if (!this.IsGarrisonAura(name)) 354 continue; 355 356 var validList = this.GiveMembersWithValidClass(name, [structure]); 357 if (validList.length) 358 { 359 this[name].targetUnits.push(validList[0]); 360 this.ApplyBonus(name,validList[0]); 361 } 362 } 320 var auraNames = this.GetAuraNames().filter(n => this.IsGarrisonAura(n)); 321 for (let name of auraNames) 322 this.ApplyBonus(name, [structure]); 363 323 }; 364 324 365 325 Auras.prototype.ApplyTemplateBonus = function(name, players) … … 370 330 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 371 331 var classes = this.GetClasses(name); 372 332 373 for each (var mod inmodifications)374 for each (var player inplayers)333 for (let mod of modifications) 334 for (let player of players) 375 335 cmpAuraManager.ApplyTemplateBonus(mod.value, player, classes, mod, this.templateName + "/" + name + "/" + mod.value); 376 336 }; 377 337 378 338 Auras.prototype.RemoveFormationBonus = function(memberList) 379 339 { 380 var auraNames = this.GetAuraNames(); 381 for each (var name in auraNames) 382 { 383 if (!this.IsFormationAura(name)) 384 continue; 385 386 for each (var ent in memberList) 387 { 388 this.RemoveBonus(name,ent); 389 this[name].targetUnits.splice(this[name].targetUnits.indexOf(ent), 1); 390 } 391 } 340 var auraNames = this.GetAuraNames().filter(n => this.IsFormationAura(n)); 341 for (let name of auraNames) 342 this.RemoveBonus(name, memberList); 392 343 }; 393 344 394 345 Auras.prototype.RemoveGarrisonBonus = function(structure) 395 346 { 396 var auraNames = this.GetAuraNames(); 397 for each (var name in auraNames) 398 { 399 if (!this.IsGarrisonAura(name)) 400 continue; 401 402 this.RemoveBonus(name,structure); 403 this[name].targetUnits.splice(this[name].targetUnits.indexOf(structure), 1); 404 } 347 var auraNames = this.GetAuraNames().filter(n => this.IsGarrisonAura(n)); 348 for (let name of auraNames) 349 this.RemoveBonus(name, [structure]); 405 350 }; 406 351 407 352 Auras.prototype.RemoveTemplateBonus = function(name) … … 419 364 cmpAuraManager.RemoveTemplateBonus(mod.value, player, classes, this.templateName + "/" + name + "/" + mod.value); 420 365 }; 421 366 422 Auras.prototype.ApplyBonus = function(name, ent )367 Auras.prototype.ApplyBonus = function(name, ents) 423 368 { 369 var validEnts = this.GiveMembersWithValidClass(name, ents); 370 if (!validEnts.length) 371 return; 372 this[name].targetUnits = this[name].targetUnits.concat(validEnts); 424 373 var modifications = this.GetModifications(name); 425 374 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 426 for each (var mod in modifications) 427 cmpAuraManager.ApplyBonus(mod.value, ent, mod, this.templateName + "/" + name + "/" + mod.value); 428 375 for each (let mod in modifications) 376 cmpAuraManager.ApplyBonus(mod.value, validEnts, mod, this.templateName + "/" + name + "/" + mod.value); 377 // update status bars if this has an icon 378 if (!this.GetOverlayIcon(name)) 379 return; 380 for (let ent of validEnts) 381 { 382 var cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars) 383 if (cmpStatusBars) 384 cmpStatusBars.AddAuraSource(this.entity, name); 385 } 429 386 }; 430 387 431 Auras.prototype.RemoveBonus = function(name, ent )388 Auras.prototype.RemoveBonus = function(name, ents) 432 389 { 390 var validEnts = this.GiveMembersWithValidClass(name, ents); 391 if (!validEnts.length) 392 return; 393 this[name].targetUnits = this[name].targetUnits.filter(v => validEnts.indexOf(v) == -1); 433 394 var modifications = this.GetModifications(name); 434 395 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 435 436 for each (var mod in modifications) 437 cmpAuraManager.RemoveBonus(mod.value, ent, this.templateName + "/" + name + "/" + mod.value); 396 for each (let mod in modifications) 397 cmpAuraManager.RemoveBonus(mod.value, validEnts, this.templateName + "/" + name + "/" + mod.value); 398 // update status bars if this has an icon 399 if (!this.GetOverlayIcon(name)) 400 return; 401 for (let ent of validEnts) 402 { 403 var cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars) 404 if (cmpStatusBars) 405 cmpStatusBars.RemoveAuraSource(this.entity, name); 406 } 438 407 }; 439 408 440 409 Auras.prototype.OnOwnershipChanged = function(msg) -
binaries/data/mods/public/simulation/components/GuiInterface.js
32 32 this.timeNotificationID = 1; 33 33 this.timeNotifications = []; 34 34 this.entsRallyPointsDisplayed = []; 35 this.entsWithAuraAndStatusBars = new Set(); 35 36 }; 36 37 37 38 /* … … 855 856 } 856 857 }; 857 858 859 GuiInterface.prototype.GetEntitiesWithStatusBars = function() 860 { 861 return [...this.entsWithAuraAndStatusBars]; 862 }; 863 858 864 GuiInterface.prototype.SetStatusBars = function(player, cmd) 859 865 { 860 for each (var ent in cmd.entities) 866 let affectedEnts = []; 867 for (let ent of cmd.entities) 861 868 { 862 var cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); 869 let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); 870 if (!cmpStatusBars) 871 continue; 872 cmpStatusBars.SetEnabled(cmd.enabled); 873 874 let cmpAuras = Engine.QueryInterface(ent, IID_Auras); 875 if (!cmpAuras) 876 continue; 877 878 for (let name of cmpAuras.GetAuraNames()) 879 { 880 if (!cmpAuras.GetOverlayIcon(name)) 881 continue; 882 affectedEnts = affectedEnts.concat(cmpAuras.GetAffectedEntities(name)); 883 if (cmd.enabled) 884 this.entsWithAuraAndStatusBars.add(ent); 885 else 886 this.entsWithAuraAndStatusBars.delete(ent); 887 } 888 } 889 890 // make the affected ents unique 891 affectedEnts = new Set(affectedEnts); 892 for (let ent of affectedEnts) 893 { 894 let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars) 863 895 if (cmpStatusBars) 864 cmpStatusBars. SetEnabled(cmd.enabled);896 cmpStatusBars.RegenerateSprites(); 865 897 } 866 898 }; 867 899 -
binaries/data/mods/public/simulation/components/StatusBars.js
14 14 StatusBars.prototype.Init = function() 15 15 { 16 16 this.enabled = false; 17 this.auraSources = {}; 17 18 }; 18 19 19 // Because this is enabled directly by the GUI and is not 20 // network-synchronised (it only affects local rendering), 21 // we disable serialization in order to prevent OOS errors 22 StatusBars.prototype.Serialize = null;20 StatusBars.prototype.Serialize = function() 21 { 22 return {"auraSources": this.auraSources}; 23 }; 23 24 24 StatusBars.prototype.Deserialize = function( )25 StatusBars.prototype.Deserialize = function(data) 25 26 { 26 // Use default initialisation27 27 this.Init(); 28 this.auraSources = data.auraSources; 28 29 }; 29 30 30 31 StatusBars.prototype.SetEnabled = function(enabled) … … 33 34 if (enabled == this.enabled) 34 35 return; 35 36 37 this.enabled = enabled; 38 36 39 // Update the displayed sprites 40 this.RegenerateSprites(); 41 }; 37 42 38 this.enabled = enabled; 39 40 if ( enabled)41 this. RegenerateSprites();43 StatusBars.prototype.AddAuraSource = function(source, auraName) 44 { 45 if (this.auraSources[source]) 46 this.auraSources[source].push(auraName); 42 47 else 43 this.ResetSprites(); 48 this.auraSources[source] = [auraName]; 49 this.RegenerateSprites(); 44 50 }; 45 51 52 StatusBars.prototype.RemoveAuraSource = function(source, auraName) 53 { 54 let names = this.auraSources[source]; 55 names.splice(names.indexOf(auraName), 1); 56 this.RegenerateSprites(); 57 }; 58 46 59 StatusBars.prototype.OnHealthChanged = function(msg) 47 60 { 48 61 if (this.enabled) … … 61 74 this.RegenerateSprites(); 62 75 }; 63 76 64 StatusBars.prototype.Re setSprites = function()77 StatusBars.prototype.RegenerateSprites = function() 65 78 { 66 varcmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);79 let cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer); 67 80 cmpOverlayRenderer.Reset(); 81 82 let yoffset = 0; 83 if (this.enabled) 84 yoffset = this.AddBars(cmpOverlayRenderer, yoffset); 85 yoffset = this.AddAuraIcons(cmpOverlayRenderer, yoffset); 86 return yoffset; 68 87 }; 69 88 70 StatusBars.prototype.RegenerateSprites = function() 89 // Internal helper functions 90 StatusBars.prototype.AddAuraIcons = function(cmpOverlayRenderer, yoffset) 71 91 { 72 var cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);73 cmpOverlayRenderer.Reset();92 let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 93 let sources = cmpGuiInterface.GetEntitiesWithStatusBars().filter(e => this.auraSources[e] && this.auraSources[e].length); 74 94 95 if (!sources.length) 96 return yoffset; 97 98 let iconSet = new Set(); 99 for (let ent of sources) 100 { 101 let cmpAuras = Engine.QueryInterface(ent, IID_Auras); 102 if (!cmpAuras) // probably the ent just died 103 continue; 104 for (let name of this.auraSources[ent]) 105 iconSet.add(cmpAuras.GetOverlayIcon(name)); 106 } 107 108 // World-space offset from the unit's position 109 var offset = { "x": 0, "y": +this.template.HeightOffset, "z": 0 }; 110 111 let iconSize = +this.template.BarWidth / 2; 112 let xoffset = -iconSize * (iconSet.size - 1) * 0.6 113 for (let icon of iconSet) 114 { 115 cmpOverlayRenderer.AddSprite( 116 icon, 117 { "x": xoffset - iconSize/2, "y": yoffset }, 118 { "x": xoffset + iconSize/2, "y": yoffset + iconSize }, 119 offset 120 ); 121 xoffset += iconSize * 1.2; 122 } 123 124 return yoffset + iconSize + this.template.BarHeight / 2; 125 }; 126 127 StatusBars.prototype.AddBars = function(cmpOverlayRenderer, yoffset) 128 { 75 129 // Size of health bar (in world-space units) 76 130 var width = +this.template.BarWidth; 77 131 var height = +this.template.BarHeight; … … 79 133 // World-space offset from the unit's position 80 134 var offset = { "x": 0, "y": +this.template.HeightOffset, "z": 0 }; 81 135 82 // Billboard offset of next bar83 var yoffset = 0;84 85 136 var AddBar = function(type, amount) 86 137 { 87 138 cmpOverlayRenderer.AddSprite( 88 139 "art/textures/ui/session/icons/"+type+"_bg.png", 89 { "x": -width/2, "y": -height/2 +yoffset },90 { "x": width/2, "y": height /2+ yoffset },140 { "x": -width/2, "y":yoffset }, 141 { "x": width/2, "y": height + yoffset }, 91 142 offset 92 143 ); 93 144 94 145 cmpOverlayRenderer.AddSprite( 95 146 "art/textures/ui/session/icons/"+type+"_fg.png", 96 { "x": -width/2, "y": -height/2 +yoffset },97 { "x": width*(amount - 0.5), "y": height /2+ yoffset },147 { "x": -width/2, "y": yoffset }, 148 { "x": width*(amount - 0.5), "y": height + yoffset }, 98 149 offset 99 150 ); 100 151 101 yoffset -= height * 1.2;152 yoffset += height * 1.2; 102 153 }; 103 154 104 155 var cmpMirage = Engine.QueryInterface(this.entity, IID_Mirage); … … 119 170 else if (cmpMirage && cmpMirage.ResourceSupply()) 120 171 AddBar("supply", cmpMirage.IsInfinite() ? 1 : cmpMirage.GetAmount() / cmpMirage.GetMaxAmount()); 121 172 173 return yoffset; 122 174 /* 123 175 // Rank icon disabled for now - see discussion around 124 176 // http://www.wildfiregames.com/forum/index.php?s=&showtopic=13608&view=findpost&p=212154 -
binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml
10 10 </Modifications> 11 11 <AuraName>Healing Aura</AuraName> 12 12 <AuraDescription>Heals nearby units at 1 HP per second.</AuraDescription> 13 <OverlayIcon>art/textures/ui/session/auras/heal.png</OverlayIcon> 13 14 </heal> 14 15 </Auras> 15 16 <BuildRestrictions>