mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-20 15:23: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
72 lines
2 KiB
JavaScript
72 lines
2 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.LoadComponentScript("interfaces/Loot.js");
|
|
Engine.LoadComponentScript("Loot.js");
|
|
Engine.LoadHelperScript("ValueModification.js");
|
|
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
|
|
|
|
let applyModifierOverride = (key, val, ent) =>
|
|
{
|
|
return val;
|
|
};
|
|
|
|
AddMock(SYSTEM_ENTITY, IID_ModifiersManager, {
|
|
"ApplyModifiers": (key, val, ent) =>
|
|
{
|
|
return applyModifierOverride(key, val, ent);
|
|
}
|
|
});
|
|
|
|
const cmpLoot = ConstructComponent(30, "Loot", {
|
|
"xp": 35,
|
|
"metal": 10
|
|
});
|
|
|
|
TS_ASSERT_EQUALS(cmpLoot.GetResources().xp, undefined);
|
|
TS_ASSERT_EQUALS(cmpLoot.GetResources().metal, 10);
|
|
TS_ASSERT_EQUALS(cmpLoot.GetResources().wood, 0);
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpLoot.GetResources(), { "food": 0, "metal": 10, "stone": 0, "wood": 0 });
|
|
TS_ASSERT_EQUALS(cmpLoot.GetXp(), 35);
|
|
|
|
const cmpLootNoXp = ConstructComponent(30, "Loot", {
|
|
"metal": 10,
|
|
"wood": 20
|
|
});
|
|
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetResources().xp, undefined);
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetResources().metal, 10);
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetResources().wood, 20);
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetResources().stone, 0);
|
|
TS_ASSERT_UNEVAL_EQUALS(cmpLootNoXp.GetResources(), { "food": 0, "metal": 10, "stone": 0, "wood": 20 });
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetXp(), 0);
|
|
|
|
applyModifierOverride = (key, val, ent) =>
|
|
{
|
|
return key == "Loot/xp" ? 100 : val;
|
|
};
|
|
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetXp(), 100);
|
|
|
|
applyModifierOverride = (key, val, ent) =>
|
|
{
|
|
return key == "Loot/wood" ? 100 : val;
|
|
};
|
|
|
|
TS_ASSERT_EQUALS(cmpLootNoXp.GetResources().wood, 100);
|