mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 22:03:56 -07:00
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace style for JavaScript code. This plugin was however updated the last time over 9 years ago and will be incompatible with ESLint v10, as that [removes `context.getSourceCode()`][1], the plugin relies on. To keep the eslint config working with ESLint v10, this replaces `eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule from `@stylistic/eslint-plugin`, a package we already use. While `@stylistic/brace-style` doesn't offer an option to format braces in exactly the same way as before, the "allman" style seems to be the one closest to the existing code. [1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members [2]: https://eslint.style/rules/brace-style
89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
Resources = {
|
|
"GetCodes": () => ["food", "metal", "stone", "wood"],
|
|
"GetTradableCodes": () => ["food", "metal", "stone", "wood"],
|
|
"GetBarterableCodes": () => ["food", "metal", "stone", "wood"],
|
|
"GetResource": () => ({}),
|
|
"BuildSchema": (type) =>
|
|
{
|
|
let schema = "";
|
|
for (const res of Resources.GetCodes())
|
|
schema +=
|
|
"<optional>" +
|
|
"<element name='" + res + "'>" +
|
|
"<ref name='" + type + "'/>" +
|
|
"</element>" +
|
|
"</optional>";
|
|
return "<interleave>" + schema + "</interleave>";
|
|
}
|
|
};
|
|
|
|
Engine.LoadHelperScript("ValueModification.js");
|
|
Engine.LoadComponentScript("interfaces/Player.js");
|
|
Engine.LoadComponentScript("interfaces/Cost.js");
|
|
Engine.LoadComponentScript("interfaces/Foundation.js");
|
|
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
|
|
Engine.LoadComponentScript("Player.js");
|
|
|
|
var cmpPlayer = ConstructComponent(10, "Player", {
|
|
"SpyCostMultiplier": 1,
|
|
"BarterMultiplier": {
|
|
"Buy": {
|
|
"wood": 1.0,
|
|
"stone": 1.0,
|
|
"metal": 1.0
|
|
},
|
|
"Sell": {
|
|
"wood": 1.0,
|
|
"stone": 1.0,
|
|
"metal": 1.0
|
|
}
|
|
},
|
|
"Formations": { "_string": "" },
|
|
});
|
|
|
|
var playerID = 1;
|
|
cmpPlayer.SetPlayerID(playerID);
|
|
TS_ASSERT_EQUALS(cmpPlayer.GetPlayerID(), playerID);
|
|
|
|
TS_ASSERT_EQUALS(cmpPlayer.GetPopulationCount(), 0);
|
|
TS_ASSERT_EQUALS(cmpPlayer.GetPopulationLimit(), 0);
|
|
|
|
TS_ASSERT_EQUALS(cmpPlayer.GetSpyCostMultiplier(), 1);
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetBarterMultiplier(), {
|
|
"buy": {
|
|
"wood": 1.0,
|
|
"stone": 1.0,
|
|
"metal": 1.0
|
|
},
|
|
"sell": {
|
|
"wood": 1.0,
|
|
"stone": 1.0,
|
|
"metal": 1.0
|
|
}
|
|
});
|
|
|
|
AddMock(60, IID_Identity, {
|
|
"GetClassesList": () => {},
|
|
"HasClass": (cl) => true
|
|
});
|
|
AddMock(60, IID_Ownership);
|
|
AddMock(60, IID_Foundation, {});
|
|
cmpPlayer.OnGlobalOwnershipChanged({ "entity": 60, "from": INVALID_PLAYER, "to": playerID });
|
|
TS_ASSERT(!cmpPlayer.CanBarter());
|
|
|
|
AddMock(61, IID_Identity, {
|
|
"GetClassesList": () => {},
|
|
"HasClass": (cl) => false
|
|
});
|
|
cmpPlayer.OnGlobalOwnershipChanged({ "entity": 61, "from": INVALID_PLAYER, "to": playerID });
|
|
TS_ASSERT(!cmpPlayer.CanBarter());
|
|
|
|
AddMock(62, IID_Identity, {
|
|
"GetClassesList": () => {},
|
|
"HasClass": (cl) => true
|
|
});
|
|
cmpPlayer.OnGlobalOwnershipChanged({ "entity": 62, "from": INVALID_PLAYER, "to": playerID });
|
|
TS_ASSERT(cmpPlayer.CanBarter());
|
|
|
|
cmpPlayer.OnGlobalOwnershipChanged({ "entity": 62, "from": playerID, "to": INVALID_PLAYER });
|
|
TS_ASSERT(!cmpPlayer.CanBarter());
|