0ad/binaries/data/mods/public/gui/reference/common/common.js
Vantha a89ce596a4
Revamp GetTemplateDataHelper
This patch is primarily meant as preparation in order to be able to
reuse this logic for GetEntityState calls in the future.

Key changes:
- Clearer API by providing different functions for different purposes.
- Slight performance optimisation by storing parameters in a context
object and pulling the info from there instead of redeclaring a lambda
each time, which it seems Spidermonkey struggled to optimise well.
- Allow computing only partial template data, specified by passing a
list of desired components. (to be used more in the future)
- Make it so the naming and structure of template data and matches 1:1
with the data in entity states. This makes accessing values from them
more consistent and would also allow e.g. adopting data between the two
in the future.
2026-08-08 17:21:44 +02:00

33 lines
1.1 KiB
JavaScript

/**
* This needs to stay in the global scope, as it is used by various functions
* within gui/common/tooltip.js
*/
var g_ResourceData = new Resources();
var g_Page;
/**
* This is needed because getEntityCostTooltip in tooltip.js needs to get
* the template data of the different wallSet pieces. In the session this
* function does some caching, but here we do that in the TemplateLoader
* class already.
*/
function GetTemplateData(templateName)
{
const template = g_Page.TemplateLoader.loadEntityTemplate(templateName, g_Page.activeCiv);
return g_TemplateHelper.computeDataFromModifiers(template, g_Page.TemplateLoader.auraData, g_ResourceData, g_Page.TemplateParser.getModifiers(g_Page.activeCiv));
}
/**
* This would ideally be an Engine method.
* Or part of globalscripts. Either would be better than here.
*/
function TechnologyTemplateExists(templateName)
{
return Engine.FileExists(g_Page.TemplateLoader.TechnologyPath + templateName + ".json");
}
function AuraTemplateExists(templateName)
{
return Engine.FileExists(g_Page.TemplateLoader.AuraPath + templateName + ".json");
}