Index: ps/trunk/binaries/data/mods/public/globalscripts/Templates.js =================================================================== --- ps/trunk/binaries/data/mods/public/globalscripts/Templates.js +++ ps/trunk/binaries/data/mods/public/globalscripts/Templates.js @@ -107,13 +107,14 @@ * * @param {Object} template - A valid template as returned from a template loader. * @param {string} value_path - Route to value within the xml template structure. + * @param {number} default_value - A value to use if one is not specified in the template. * @return {number} */ -function GetBaseTemplateDataValue(template, value_path) +function GetBaseTemplateDataValue(template, value_path, default_value) { let current_value = template; for (let property of value_path.split("/")) - current_value = current_value[property] || 0; + current_value = current_value[property] || default_value; return +current_value; } @@ -126,11 +127,12 @@ * @param {number} player - Optional player id. * @param {Object} modifiers - Value modifiers from auto-researched techs, unit upgrades, * etc. Optional as only used if no player id provided. + * @param {number} default_value - A value to use if one is not specified in the template. * @return {number} Modifier altered value. */ -function GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers={}) +function GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers={}, default_value) { - let current_value = GetBaseTemplateDataValue(template, value_path); + let current_value = GetBaseTemplateDataValue(template, value_path, default_value); mod_key = mod_key || value_path; if (player) @@ -152,17 +154,19 @@ * @param {number} player - An optional player id to get the technology modifications * of properties. * @param {Object} auraTemplates - In the form of { key: { "auraName": "", "auraDescription": "" } }. + * @param {Object} resources - An instance of the Resources class. * @param {Object} modifiers - Modifications from auto-researched techs, unit upgrades * etc. Optional as only used if there's no player * id provided. */ -function GetTemplateDataHelper(template, player, auraTemplates, modifiers = {}) +function GetTemplateDataHelper(template, player, auraTemplates, resources, modifiers = {}) { // Return data either from template (in tech tree) or sim state (ingame). // @param {string} value_path - Route to the value within the template. // @param {string} mod_key - Modification key, if not the same as the value_path. - let getEntityValue = function(value_path, mod_key) { - return GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers); + // @param {number} default_value - A value to use if one is not specified in the template. + const getEntityValue = function(value_path, mod_key, default_value = 0) { + return GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers, default_value); }; let ret = {}; @@ -481,8 +485,8 @@ if (template.Researcher) { ret.techCostMultiplier = {}; - for (const res in template.Researcher.TechCostMultiplier) - ret.techCostMultiplier[res] = getEntityValue("Researcher/TechCostMultiplier/" + res); + for (const res of resources.GetCodes().concat(["time"])) + ret.techCostMultiplier[res] = getEntityValue("Researcher/TechCostMultiplier/" + res, null, 1); } if (template.Trader) @@ -570,6 +574,7 @@ * Get information about a technology template. * @param {Object} template - A valid template as obtained by loading the tech JSON file. * @param {string} civ - Civilization for which the specific name and tech requirements should be returned. + * @param {Object} resources - An instance of the Resources class. */ function GetTechnologyDataHelper(template, civ, resources) { Index: ps/trunk/binaries/data/mods/public/gui/reference/common/TemplateParser.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/reference/common/TemplateParser.js +++ ps/trunk/binaries/data/mods/public/gui/reference/common/TemplateParser.js @@ -60,7 +60,7 @@ return null; let template = this.TemplateLoader.loadEntityTemplate(templateName, civCode); - let parsed = GetTemplateDataHelper(template, null, this.TemplateLoader.auraData, this.modifiers[civCode] || {}); + const parsed = GetTemplateDataHelper(template, null, this.TemplateLoader.auraData, g_ResourceData, this.modifiers[civCode] || {}); parsed.name.internal = templateName; parsed.history = template.Identity.History; @@ -180,7 +180,7 @@ return this.techs[civCode][technologyName]; let template = this.TemplateLoader.loadTechnologyTemplate(technologyName); - let tech = GetTechnologyDataHelper(template, civCode, g_ResourceData); + const tech = GetTechnologyDataHelper(template, civCode, g_ResourceData, this.modifiers[civCode] || {}); tech.name.internal = technologyName; if (template.pair !== undefined) @@ -251,7 +251,7 @@ { upgrade.entity = upgrade.entity.replace(/\{(civ|native)\}/g, civCode); - let data = GetTemplateDataHelper(this.TemplateLoader.loadEntityTemplate(upgrade.entity, civCode), null, this.TemplateLoader.auraData, this.modifiers[civCode] || {}); + const data = GetTemplateDataHelper(this.TemplateLoader.loadEntityTemplate(upgrade.entity, civCode), null, this.TemplateLoader.auraData, g_ResourceData, this.modifiers[civCode] || {}); data.name.internal = upgrade.entity; data.cost = upgrade.cost; data.icon = upgrade.icon || data.icon; Index: ps/trunk/binaries/data/mods/public/gui/reference/common/common.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/reference/common/common.js +++ ps/trunk/binaries/data/mods/public/gui/reference/common/common.js @@ -15,7 +15,7 @@ function GetTemplateData(templateName) { let template = g_Page.TemplateLoader.loadEntityTemplate(templateName, g_Page.activeCiv); - return GetTemplateDataHelper(template, null, g_Page.TemplateLoader.auraData, g_Page.TemplateParser.getModifiers(g_Page.activeCiv)); + return GetTemplateDataHelper(template, null, g_Page.TemplateLoader.auraData, g_ResourceData, g_Page.TemplateParser.getModifiers(g_Page.activeCiv)); } /** Index: ps/trunk/binaries/data/mods/public/maps/random/rmgen-common/wall_builder.js =================================================================== --- ps/trunk/binaries/data/mods/public/maps/random/rmgen-common/wall_builder.js +++ ps/trunk/binaries/data/mods/public/maps/random/rmgen-common/wall_builder.js @@ -3,6 +3,14 @@ */ /** + * Provide the bare minimum so we can load templates without error. + * We don't actually need to know the actual resource codes. + */ +const g_Resources = { + "GetCodes": () => [], +}; + +/** * Set some globals for this module. */ var g_WallStyles = loadWallsetsFromCivData(); @@ -40,7 +48,7 @@ function loadWallset(wallsetPath, civ) { let newWallset = { "curves": [] }; - let wallsetData = GetTemplateDataHelper(wallsetPath).wallSet; + const wallsetData = GetTemplateDataHelper(wallsetPath, null, null, g_Resources).wallSet; for (let element in wallsetData.templates) if (element == "curves") @@ -263,7 +271,7 @@ function readyWallElement(path, civCode) { path = path.replace(/\{civ\}/g, civCode); - let template = GetTemplateDataHelper(Engine.GetTemplate(path), null, null); + const template = GetTemplateDataHelper(Engine.GetTemplate(path), null, null, g_Resources); let length = template.wallPiece ? template.wallPiece.length : template.obstruction.shape.width; return deepfreeze({ Index: ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js +++ ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -645,7 +645,7 @@ let aurasTemplate = {}; if (!template.Auras) - return GetTemplateDataHelper(template, owner, aurasTemplate); + return GetTemplateDataHelper(template, owner, aurasTemplate, Resources); let auraNames = template.Auras._string.split(/\s+/); @@ -658,7 +658,7 @@ aurasTemplate[name] = auraTemplate; } - return GetTemplateDataHelper(template, owner, aurasTemplate); + return GetTemplateDataHelper(template, owner, aurasTemplate, Resources); }; GuiInterface.prototype.IsTechnologyResearched = function(player, data) Index: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js @@ -137,11 +137,11 @@ * To start with, no techs are researched... */ // T1: Check the cost of the upgrade without a player value being passed (as it would be in the structree). -let parsed_template = GetTemplateDataHelper(template, null, {}); +let parsed_template = GetTemplateDataHelper(template, null, {}, Resources); TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); // T2: Check the value, with a player ID (as it would be in-session). -parsed_template = GetTemplateDataHelper(template, playerID, {}); +parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources); TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); // T3: Check that the value is correct within the Update Component. @@ -155,11 +155,11 @@ isResearched = true; // T4: Check that the player-less value hasn't increased... -parsed_template = GetTemplateDataHelper(template, null, {}); +parsed_template = GetTemplateDataHelper(template, null, {}, Resources); TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); // T5: ...but the player-backed value has. -parsed_template = GetTemplateDataHelper(template, playerID, {}); +parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources); TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 160, "wood": 25, "time": 90 }); // T6: The upgrade component should still be using the old resource cost (but new time cost) for the upgrade in progress...