Changeset 25191
- Timestamp:
- Apr 4, 2021, 8:52:20 AM (3 years ago)
- Location:
- ps/trunk/binaries/data/mods/public
- Files:
-
- 6 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/globalscripts/Templates.js
r25123 r25191 497 497 }; 498 498 499 500 501 502 503 504 505 506 507 508 499 509 if (template.WallSet) 500 510 { -
ps/trunk/binaries/data/mods/public/gui/common/tooltips.js
r25127 r25191 847 847 } 848 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 849 873 /** 850 874 * Returns an array of strings for a set of wall pieces. If the pieces share -
ps/trunk/binaries/data/mods/public/gui/reference/common/ReferencePage.js
r25123 r25191 66 66 getPopulationBonusTooltip, 67 67 getResourceTrickleTooltip, 68 68 69 getLootTooltip 69 70 ]; -
ps/trunk/binaries/data/mods/public/gui/session/selection_details.js
r25123 r25191 330 330 getProjectilesTooltip, 331 331 getResourceTrickleTooltip, 332 332 333 getLootTooltip 333 334 ].map(func => func(entState)).filter(tip => tip).join("\n"); -
ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js
r25123 r25191 575 575 "walk": cmpUnitMotion.GetWalkSpeed(), 576 576 "run": cmpUnitMotion.GetWalkSpeed() * cmpUnitMotion.GetRunMultiplier() 577 578 579 580 581 582 583 577 584 }; 578 585 -
ps/trunk/binaries/data/mods/public/simulation/components/Upkeep.js
-
Property svn:mime-type
set to
text/plain
r25190 r25191 1 function ResourceTrickle() {}1 function () {} 2 2 3 ResourceTrickle.prototype.Schema =4 "<a:help>Controls the resource trickle ability of the unit.</a:help>" +5 "<element name='Rates' a:help=' TrickleRates'>" +3 .prototype.Schema = 4 "<a:help>Controls the resource .</a:help>" + 5 "<element name='Rates' a:help=' Rates'>" + 6 6 Resources.BuildSchema("nonNegativeDecimal") + 7 7 "</element>" + 8 "<element name='Interval' a:help='Number of mil iseconds must pass for the player to gain the next trickle.'>" +8 "<element name='Interval' a:help='Number of mil.'>" + 9 9 "<ref name='nonNegativeDecimal'/>" + 10 10 "</element>"; 11 11 12 ResourceTrickle.prototype.Init = function()12 .prototype.Init = function() 13 13 { 14 this. trickleInterval = +this.template.Interval;14 this.Interval = +this.template.Interval; 15 15 this.CheckTimer(); 16 16 }; 17 17 18 ResourceTrickle.prototype.GetInterval = function() 18 /** 19 * @return {number} - The interval between resource subtractions, in ms. 20 */ 21 Upkeep.prototype.GetInterval = function() 19 22 { 20 return this. trickleInterval;23 return this.Interval; 21 24 }; 22 25 23 ResourceTrickle.prototype.GetRates = function() 26 /** 27 * @return {Object} - The upkeep rates in the form of { "resourceName": {number} }. 28 */ 29 Upkeep.prototype.GetRates = function() 24 30 { 25 31 return this.rates; … … 27 33 28 34 /** 29 * @return {boolean} - Whether this entity has at least one non-zero trickle rate.35 * @return {boolean} - Whether this entity has at least one non-zero . 30 36 */ 31 ResourceTrickle.prototype.ComputeRates = function()37 .prototype.ComputeRates = function() 32 38 { 33 39 this.rates = {}; 34 let has Trickle= false;40 let has = false; 35 41 for (let resource in this.template.Rates) 36 42 { 37 let rate = ApplyValueModificationsToEntity(" ResourceTrickle/Rates/" + resource, +this.template.Rates[resource], this.entity);43 let rate = ApplyValueModificationsToEntity("/Rates/" + resource, +this.template.Rates[resource], this.entity); 38 44 if (rate) 39 45 { 40 46 this.rates[resource] = rate; 41 has Trickle= true;47 has = true; 42 48 } 43 49 } 44 50 45 return has Trickle;51 return has; 46 52 }; 47 53 48 ResourceTrickle.prototype.Trickle = function(data, lateness) 54 /** 55 * Try to subtract the needed resources. 56 * Data and lateness are unused. 57 */ 58 Upkeep.prototype.Pay = function(data, lateness) 49 59 { 50 // The player entity may also have a ResourceTrickle component 51 let cmpPlayer = QueryOwnerInterface(this.entity) || Engine.QueryInterface(this.entity, IID_Player); 60 let cmpPlayer = QueryOwnerInterface(this.entity); 52 61 if (!cmpPlayer) 53 62 return; 54 63 55 cmpPlayer.AddResources(this.rates); 64 if (!cmpPlayer.TrySubtractResources(this.rates)) 65 this.HandleInsufficientUpkeep(); 66 else 67 this.HandleSufficientUpkeep(); 56 68 }; 57 69 58 ResourceTrickle.prototype.OnValueModification = function(msg) 70 /** 71 * E.g. take a hitpoint, reduce CP. 72 */ 73 Upkeep.prototype.HandleInsufficientUpkeep = function() 59 74 { 60 if (msg.component != "ResourceTrickle") 75 if (this.unpayed) 76 return; 77 78 let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 79 if (cmpIdentity) 80 cmpIdentity.SetControllable(false); 81 this.unpayed = true; 82 }; 83 84 /** 85 * Reset to the previous stage. 86 */ 87 Upkeep.prototype.HandleSufficientUpkeep = function() 88 { 89 if (!this.unpayed) 90 return; 91 92 let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 93 if (cmpIdentity) 94 cmpIdentity.SetControllable(true); 95 delete this.unpayed; 96 }; 97 98 Upkeep.prototype.OnValueModification = function(msg) 99 { 100 if (msg.component != "Upkeep") 61 101 return; 62 102 … … 64 104 }; 65 105 66 ResourceTrickle.prototype.CheckTimer = function() 106 /** 107 * Recalculate the interval and update the timer accordingly. 108 */ 109 Upkeep.prototype.CheckTimer = function() 67 110 { 68 111 if (!this.ComputeRates()) … … 77 120 } 78 121 79 let old TrickleInterval = this.trickleInterval;80 this. trickleInterval = ApplyValueModificationsToEntity("ResourceTrickle/Interval", +this.template.Interval, this.entity);81 if (this. trickleInterval < 0)122 let oldInterval; 123 this./Interval", +this.template.Interval, this.entity); 124 if (this.Interval < 0) 82 125 { 83 126 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); … … 89 132 if (this.timer) 90 133 { 91 if (this. trickleInterval == oldTrickleInterval)134 if (this.Interval) 92 135 return; 93 136 94 137 // If the timer wasn't invalidated before (interval <= 0), just update it. 95 if (old TrickleInterval > 0)138 if (oldInterval > 0) 96 139 { 97 140 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 98 cmpTimer.UpdateRepeatTime(this.timer, this. trickleInterval);141 cmpTimer.UpdateRepeatTime(this.timer, this.Interval); 99 142 return; 100 143 } … … 102 145 103 146 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 104 this.timer = cmpTimer.SetInterval(this.entity, IID_ ResourceTrickle, "Trickle", this.trickleInterval, this.trickleInterval, undefined);147 this.timer = cmpTimer.SetInterval(this.entity, IID_Interval, undefined); 105 148 }; 106 149 107 Engine.RegisterComponentType(IID_ ResourceTrickle, "ResourceTrickle", ResourceTrickle);150 Engine.RegisterComponentType(IID_); -
Property svn:mime-type
set to
-
ps/trunk/binaries/data/mods/public/simulation/components/interfaces/Upkeep.js
-
Property svn:mime-type
set to
text/plain
r25190 r25191 1 Engine.RegisterInterface(" ResourceTrickle");1 Engine.RegisterInterface(""); -
Property svn:mime-type
set to
-
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
r25123 r25191 40 40 Engine.LoadComponentScript("interfaces/UnitAI.js"); 41 41 Engine.LoadComponentScript("interfaces/Upgrade.js"); 42 42 43 Engine.LoadComponentScript("interfaces/BuildingAI.js"); 43 44 Engine.LoadComponentScript("GuiInterface.js"); -
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Upkeep.js
-
Property svn:mime-type
set to
text/plain
r25190 r25191 17 17 }; 18 18 19 Engine.LoadComponentScript("interfaces/ResourceTrickle.js"); 19 Engine.LoadComponentScript("interfaces/Player.js"); 20 Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); 20 21 Engine.LoadComponentScript("interfaces/Timer.js"); 21 Engine.LoadComponentScript("interfaces/ Player.js");22 Engine.LoadComponentScript("interfaces/.js"); 22 23 Engine.LoadComponentScript("Player.js"); 23 Engine.LoadComponentScript("ResourceTrickle.js");24 24 Engine.LoadComponentScript("Timer.js"); 25 26 // Resource Trickle requires this function to be defined before the component is built. 25 Engine.LoadComponentScript("Upkeep.js"); 26 27 // Upkeep requires this function to be defined before the component is built. 27 28 let ApplyValueModificationsToEntity = (valueName, currentValue, entity) => currentValue; 28 29 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 29 let wonderEnt = 1;30 let ; 30 31 let turnLength = 0.2; 31 let playerEnt = 1 0;32 let playerEnt = 1; 32 33 let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer", {}); 33 34 34 let cmp ResourceTrickle = ConstructComponent(wonderEnt, "ResourceTrickle", {35 let cmp", { 35 36 "Interval": "200", 36 37 "Rates": { … … 56 57 let QueryOwnerInterface = () => cmpPlayer; 57 58 Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface); 59 58 60 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 300, "metal": 300 }); 59 TS_ASSERT_EQUALS(cmp ResourceTrickle.GetInterval(), 200);61 TS_ASSERT_EQUALS(cmp.GetInterval(), 200); 60 62 61 63 // Since there is no rate > 0, nothing should change. 62 TS_ASSERT_UNEVAL_EQUALS(cmp ResourceTrickle.GetRates(), {});63 TS_ASSERT_EQUALS(cmp ResourceTrickle.ComputeRates(), false);64 TS_ASSERT_UNEVAL_EQUALS(cmp.GetRates(), {}); 65 TS_ASSERT_EQUALS(cmp.ComputeRates(), false); 64 66 cmpTimer.OnUpdate({ "turnLength": turnLength }); 65 67 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 300, "metal": 300 }); 66 68 67 // Test that only trickling food works.68 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 69 if (valueName == " ResourceTrickle/Rates/food")70 return currentValue + 1; 71 72 return currentValue; 73 }; 74 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 75 // Calling OnValueModification will reset the timer, which can then be called, thus increasing the resources of the player.76 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });77 TS_ASSERT_UNEVAL_EQUALS(cmp ResourceTrickle.GetRates(), { "food": 1 });78 cmpTimer.OnUpdate({ "turnLength": turnLength }); 79 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 301, "metal": 300 });80 TS_ASSERT_EQUALS(cmp ResourceTrickle.ComputeRates(), true);81 82 // Reset the tricklemodification.69 // Test that only ing food works. 70 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 71 if (valueName == "/Rates/food") 72 return currentValue + 1; 73 74 return currentValue; 75 }; 76 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 77 // Calling OnValueModification will reset the timer, which can then be called, thus creasing the resources of the player. 78 cmp" }); 79 TS_ASSERT_UNEVAL_EQUALS(cmp.GetRates(), { "food": 1 }); 80 cmpTimer.OnUpdate({ "turnLength": turnLength }); 81 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 82 TS_ASSERT_EQUALS(cmp.ComputeRates(), true); 83 84 // Reset the modification. 83 85 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => currentValue; 84 86 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 85 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });86 TS_ASSERT_UNEVAL_EQUALS(cmp ResourceTrickle.GetRates(), {});87 TS_ASSERT_EQUALS(cmp ResourceTrickle.ComputeRates(), false);88 cmpTimer.OnUpdate({ "turnLength": turnLength }); 89 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 301, "metal": 300 });90 91 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 92 if (valueName == " ResourceTrickle/Interval")87 cmp" }); 88 TS_ASSERT_UNEVAL_EQUALS(cmp.GetRates(), {}); 89 TS_ASSERT_EQUALS(cmp.ComputeRates(), false); 90 cmpTimer.OnUpdate({ "turnLength": turnLength }); 91 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 92 93 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 94 if (valueName == "/Interval") 93 95 return currentValue + 200; 94 if (valueName == " ResourceTrickle/Rates/food")95 return currentValue + 1; 96 97 return currentValue; 98 }; 99 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 100 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });101 TS_ASSERT_EQUALS(cmp ResourceTrickle.GetInterval(), 400);102 cmpTimer.OnUpdate({ "turnLength": turnLength }); 103 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 301, "metal": 300 });104 cmpTimer.OnUpdate({ "turnLength": turnLength }); 105 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 302, "metal": 300 });96 if (valueName == "/Rates/food") 97 return currentValue + 1; 98 99 return currentValue; 100 }; 101 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 102 cmp" }); 103 TS_ASSERT_EQUALS(cmp.GetInterval(), 400); 104 cmpTimer.OnUpdate({ "turnLength": turnLength }); 105 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 106 cmpTimer.OnUpdate({ "turnLength": turnLength }); 107 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 106 108 107 109 // Interval becomes a normal timer, thus cancelled after the first execution. 108 110 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 109 if (valueName == " ResourceTrickle/Interval")111 if (valueName == "/Interval") 110 112 return currentValue - 200; 111 if (valueName == " ResourceTrickle/Rates/food")112 return currentValue + 1; 113 114 return currentValue; 115 }; 116 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 117 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });118 TS_ASSERT_EQUALS(cmp ResourceTrickle.GetInterval(), 0);119 cmpTimer.OnUpdate({ "turnLength": turnLength }); 120 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 302, "metal": 300 });121 cmpTimer.OnUpdate({ "turnLength": turnLength }); 122 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 303, "metal": 300 });123 cmpTimer.OnUpdate({ "turnLength": turnLength }); 124 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 303, "metal": 300 });113 if (valueName == "/Rates/food") 114 return currentValue + 1; 115 116 return currentValue; 117 }; 118 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 119 cmp" }); 120 TS_ASSERT_EQUALS(cmp.GetInterval(), 0); 121 cmpTimer.OnUpdate({ "turnLength": turnLength }); 122 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 123 cmpTimer.OnUpdate({ "turnLength": turnLength }); 124 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 125 cmpTimer.OnUpdate({ "turnLength": turnLength }); 126 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 125 127 126 128 // Timer became invalidated, check whether it's recreated properly after that. 127 129 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 128 if (valueName == " ResourceTrickle/Interval")130 if (valueName == "/Interval") 129 131 return currentValue - 100; 130 if (valueName == " ResourceTrickle/Rates/food")131 return currentValue + 1; 132 133 return currentValue; 134 }; 135 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 136 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });137 TS_ASSERT_EQUALS(cmp ResourceTrickle.GetInterval(), 100);138 cmpTimer.OnUpdate({ "turnLength": turnLength }); 139 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 305, "metal": 300 });140 cmpTimer.OnUpdate({ "turnLength": turnLength }); 141 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 307, "metal": 300 });142 cmpTimer.OnUpdate({ "turnLength": turnLength }); 143 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 309, "metal": 300 });132 if (valueName == "/Rates/food") 133 return currentValue + 1; 134 135 return currentValue; 136 }; 137 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 138 cmp" }); 139 TS_ASSERT_EQUALS(cmp.GetInterval(), 100); 140 cmpTimer.OnUpdate({ "turnLength": turnLength }); 141 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 5, "metal": 300 }); 142 cmpTimer.OnUpdate({ "turnLength": turnLength }); 143 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 144 cmpTimer.OnUpdate({ "turnLength": turnLength }); 145 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 144 146 145 147 // Value is now invalid, timer should be cancelled. 146 148 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 147 if (valueName == " ResourceTrickle/Interval")149 if (valueName == "/Interval") 148 150 return currentValue - 201; 149 if (valueName == " ResourceTrickle/Rates/food")150 return currentValue + 1; 151 152 return currentValue; 153 }; 154 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 155 cmp ResourceTrickle.OnValueModification({ "component": "ResourceTrickle" });156 TS_ASSERT_EQUALS(cmp ResourceTrickle.GetInterval(), -1);157 cmpTimer.OnUpdate({ "turnLength": turnLength }); 158 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 309, "metal": 300 });159 cmpTimer.OnUpdate({ "turnLength": turnLength }); 160 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 309, "metal": 300 });151 if (valueName == "/Rates/food") 152 return currentValue + 1; 153 154 return currentValue; 155 }; 156 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 157 cmp" }); 158 TS_ASSERT_EQUALS(cmp.GetInterval(), -1); 159 cmpTimer.OnUpdate({ "turnLength": turnLength }); 160 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 161 cmpTimer.OnUpdate({ "turnLength": turnLength }); 162 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": , "metal": 300 }); 161 163 162 164 // Timer became invalidated, check whether it's recreated properly after that. 163 165 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 164 if (valueName == "ResourceTrickle/Rates/food") 165 return currentValue + 1; 166 167 return currentValue; 168 }; 169 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 170 cmpResourceTrickle.OnValueModification({ "component": "ResourceTrickle" }); 171 TS_ASSERT_EQUALS(cmpResourceTrickle.GetInterval(), 200); 172 cmpTimer.OnUpdate({ "turnLength": turnLength }); 173 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 310, "metal": 300 }); 174 cmpTimer.OnUpdate({ "turnLength": turnLength }); 175 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 311, "metal": 300 }); 176 cmpTimer.OnUpdate({ "turnLength": turnLength }); 177 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 312, "metal": 300 }); 166 if (valueName == "Upkeep/Rates/food") 167 return currentValue + 1; 168 169 return currentValue; 170 }; 171 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 172 cmpUpkeep.OnValueModification({ "component": "Upkeep" }); 173 TS_ASSERT_EQUALS(cmpUpkeep.GetInterval(), 200); 174 cmpTimer.OnUpdate({ "turnLength": turnLength }); 175 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 290, "metal": 300 }); 176 cmpTimer.OnUpdate({ "turnLength": turnLength }); 177 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 289, "metal": 300 }); 178 cmpTimer.OnUpdate({ "turnLength": turnLength }); 179 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 288, "metal": 300 }); 180 181 // Test multiple upkeep resources. 182 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 183 if (valueName == "Upkeep/Rates/food") 184 return currentValue + 1; 185 if (valueName == "Upkeep/Rates/metal") 186 return currentValue + 2; 187 188 return currentValue; 189 }; 190 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 191 cmpUpkeep.OnValueModification({ "component": "Upkeep" }); 192 TS_ASSERT_EQUALS(cmpUpkeep.GetInterval(), 200); 193 cmpTimer.OnUpdate({ "turnLength": turnLength }); 194 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 287, "metal": 298 }); 195 cmpTimer.OnUpdate({ "turnLength": turnLength }); 196 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 286, "metal": 296 }); 197 cmpTimer.OnUpdate({ "turnLength": turnLength }); 198 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 285, "metal": 294 }); 199 200 // Test we don't go into negative resources. 201 let cmpGUI = AddMock(SYSTEM_ENTITY, IID_GuiInterface, { 202 "PushNotification": () => {} 203 }); 204 let notificationSpy = new Spy(cmpGUI, "PushNotification"); 205 ApplyValueModificationsToEntity = (valueName, currentValue, entity) => { 206 if (valueName == "Upkeep/Rates/food") 207 return currentValue + 1; 208 209 return currentValue; 210 }; 211 Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); 212 cmpUpkeep.OnValueModification({ "component": "Upkeep" }); 213 TS_ASSERT_EQUALS(cmpUpkeep.GetInterval(), 200); 214 cmpTimer.OnUpdate({ "turnLength": turnLength * 285 }); 215 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 0, "metal": 294 }); 216 cmpTimer.OnUpdate({ "turnLength": turnLength }); 217 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 0, "metal": 294 }); 218 TS_ASSERT_EQUALS(notificationSpy._called, 1); 219 cmpTimer.OnUpdate({ "turnLength": turnLength }); 220 TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetResourceCounts(), { "food": 0, "metal": 294 }); 221 TS_ASSERT_EQUALS(notificationSpy._called, 2); -
Property svn:mime-type
set to
Note:
See TracChangeset
for help on using the changeset viewer.