0ad/binaries/data/mods/public/globalscripts/tests/test_resources.js
wraitii 077c4f2576 Adds a "properties"-property to resources and let mods be able to prevent resources from being bartered, traded and/or tributed.
Patch By: Freagarach
Comments By: elexis, Stan`, Nescio
Reviewed By: wraitii, Angen
Fixes #4370

Differential Revision: https://code.wildfiregames.com/D1846
This was SVN commit r22970.
2019-09-22 14:53:47 +00:00

46 lines
958 B
JavaScript
Executable file

let resources = {
"res_A": {
"code": "a",
"name": "A",
"subtypes": {
"aa": "AA",
"aaa": "AAA"
},
"order": 2,
"properties": ["barterable", "tributable"]
},
"res_B": {
"code": "b",
"name": "B",
"subtypes": {
"bb": "BB",
"bbb": "BBB"
},
"order": 1,
"properties": ["tributable"]
}
};
Engine.ListDirectoryFiles = () => Object.keys(resources);
Engine.ReadJSONFile = (file) => resources[file];
let res = new Resources();
TS_ASSERT_EQUALS(res.GetResources().length, 2);
TS_ASSERT_EQUALS(res.GetResources()[0].code, "b");
TS_ASSERT_EQUALS(res.GetResource("b").order, 1);
TS_ASSERT_UNEVAL_EQUALS(res.GetCodes(), ["b", "a"]);
TS_ASSERT_UNEVAL_EQUALS(res.GetTributableCodes(), ["b", "a"]);
TS_ASSERT_UNEVAL_EQUALS(res.GetBarterableCodes(), ["a"]);
TS_ASSERT_UNEVAL_EQUALS(res.GetTradableCodes(), []);
TS_ASSERT_UNEVAL_EQUALS(res.GetNames(), {
"a": "A",
"aa": "AA",
"aaa": "AAA",
"b": "B",
"bb": "BB",
"bbb": "BBB"
});