Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Player.js
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | |||||
Player.prototype.SubtractResourcesOrNotify = function(amounts) | Player.prototype.SubtractResourcesOrNotify = function(amounts) | ||||
{ | { | ||||
var amountsNeeded = this.GetNeededResources(amounts); | var amountsNeeded = this.GetNeededResources(amounts); | ||||
// If we don't have enough resources, send a notification to the player | // If we don't have enough resources, send a notification to the player | ||||
if (amountsNeeded) | if (amountsNeeded) | ||||
{ | { | ||||
var parameters = {}; | let i = Object.keys(amountsNeeded).length; | ||||
var i = 0; | let msg = ""; | ||||
for (var type in amountsNeeded) | |||||
{ | |||||
++i; | |||||
parameters["resourceType"+i] = this.resourceNames[type]; | |||||
parameters["resourceAmount"+i] = amountsNeeded[type]; | |||||
} | |||||
var msg = ""; | |||||
// when marking strings for translations, you need to include the actual string, | |||||
// not some way to derive the string | |||||
if (i < 1) | if (i < 1) | ||||
warn("Amounts needed but no amounts given?"); | warn("Amounts needed but no amounts given?"); | ||||
else if (i == 1) | else if (i == 1) | ||||
msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s"); | msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s"); | ||||
else if (i == 2) | else if (i == 2) | ||||
msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s"); | msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s"); | ||||
else if (i == 3) | else if (i == 3) | ||||
msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s, %(resourceAmount3)s %(resourceType3)s"); | msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s, %(resourceAmount3)s %(resourceType3)s"); | ||||
else if (i == 4) | else if (i == 4) | ||||
msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s, %(resourceAmount3)s %(resourceType3)s, %(resourceAmount4)s %(resourceType4)s"); | msg = markForTranslation("Insufficient resources - %(resourceAmount1)s %(resourceType1)s, %(resourceAmount2)s %(resourceType2)s, %(resourceAmount3)s %(resourceType3)s, %(resourceAmount4)s %(resourceType4)s"); | ||||
else | else | ||||
warn("Localisation: Strings are not localised for more than 4 resources"); | warn("Localisation: Strings are not localised for more than 4 resources"); | ||||
// Send as time-notification | |||||
let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | ||||
cmpGUIInterface.PushNotification({ | cmpGUIInterface.PushTimeNotification({ | ||||
"players": [this.playerID], | "players": [this.playerID], | ||||
"message": msg, | "message": msg, | ||||
"parameters": parameters, | "parameters": Object.assign( | ||||
"translateMessage": true, | {}, | ||||
...Object.keys(amountsNeeded).map((resCode, i) => ({ | |||||
Stan: Spread operator bad and slow ? https://code.wildfiregames.com/rP20351 | |||||
elexisAuthorUnsubmitted Done Inline ActionsThis function is called every 100k turns, the function in that commit is called 100k times per turn? elexis: This function is called every 100k turns, the function in that commit is called 100k times per… | |||||
["resourceType" + (i+1)]: this.resourceNames[resCode], | |||||
["resourceAmount" + (i+1)]: amountsNeeded[resCode], | |||||
}))), | |||||
"translateParameters": { | "translateParameters": { | ||||
"resourceType1": "withinSentence", | "resourceType1": "withinSentence", | ||||
"resourceType2": "withinSentence", | "resourceType2": "withinSentence", | ||||
"resourceType3": "withinSentence", | "resourceType3": "withinSentence", | ||||
"resourceType4": "withinSentence", | "resourceType4": "withinSentence", | ||||
}, | } | ||||
}); | }); | ||||
return false; | return false; | ||||
} | } | ||||
for (var type in amounts) | for (var type in amounts) | ||||
this.resourceCount[type] -= amounts[type]; | this.resourceCount[type] -= amounts[type]; | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 591 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Spread operator bad and slow ? https://code.wildfiregames.com/rP20351