[Fix] Patch globalscripts technology template helper after 8d80a2186e
and the ProductionQueue split
Patch by @s0600204. This lets all technologies show up correctly in-game and in the structure tree again. accepted by: @marder @Freagarach Fixes: #6587 Differential Revision: https://code.wildfiregames.com/D4755 This was SVN commit r27042.
This commit is contained in:
parent
95106b2d9b
commit
a80ce526b7
@ -107,13 +107,14 @@ function MatchesClassList(classes, match)
|
||||
*
|
||||
* @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 @@ function GetBaseTemplateDataValue(template, value_path)
|
||||
* @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 @@ function GetModifiedTemplateDataValue(template, value_path, mod_key, player, mod
|
||||
* @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 @@ function GetTemplateDataHelper(template, player, auraTemplates, modifiers = {})
|
||||
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 @@ function GetTechnologyBasicDataHelper(template, civ)
|
||||
* 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)
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ class TemplateParser
|
||||
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 @@ class TemplateParser
|
||||
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 @@ class TemplateParser
|
||||
{
|
||||
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;
|
||||
|
@ -15,7 +15,7 @@ var g_Page;
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,14 @@
|
||||
* @file Contains functionality to place walls on random maps.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@ -40,7 +48,7 @@ function loadWallsetsFromCivData()
|
||||
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 getWallElement(element, style)
|
||||
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({
|
||||
|
@ -645,7 +645,7 @@ GuiInterface.prototype.GetTemplateData = function(player, data)
|
||||
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 @@ GuiInterface.prototype.GetTemplateData = function(player, data)
|
||||
aurasTemplate[name] = auraTemplate;
|
||||
}
|
||||
|
||||
return GetTemplateDataHelper(template, owner, aurasTemplate);
|
||||
return GetTemplateDataHelper(template, owner, aurasTemplate, Resources);
|
||||
};
|
||||
|
||||
GuiInterface.prototype.IsTechnologyResearched = function(player, data)
|
||||
|
@ -137,11 +137,11 @@ cmpUpgrade.OnOwnershipChanged({ "to": playerID });
|
||||
* 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 @@ cmpUpgrade.Upgrade("structures/" + civCode + "/defense_tower");
|
||||
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...
|
||||
|
Loading…
Reference in New Issue
Block a user