0ad/binaries/data/mods/public/simulation/components/ResourceDropsite.js
elexis 52f311da2b Merge resource agnostic branch by s0600204, fixes #3934.
Remove all occurances of hardcoded resources in the simulation, GUI and
AI code by
specifying resources as JSON files in a new simulation subdirectory and
accessing them through a globally defined prototype.

This was SVN commit r18964.
2016-11-19 14:29:45 +00:00

58 lines
1.5 KiB
JavaScript

function ResourceDropsite() {}
ResourceDropsite.prototype.Schema =
"<element name='Types'>" +
"<list>" +
"<zeroOrMore>" +
Resources.BuildChoicesSchema() +
"</zeroOrMore>" +
"</list>" +
"</element>" +
"<element name='Sharable' a:help='Allows allies to use this entity.'>" +
"<data type='boolean'/>" +
"</element>";
ResourceDropsite.prototype.Init = function()
{
this.sharable = this.template.Sharable == "true";
this.shared = this.sharable;
};
/**
* Returns the list of resource types accepted by this dropsite,
* as defined by it being referred to in the template and the resource being enabled.
*/
ResourceDropsite.prototype.GetTypes = function()
{
let types = ApplyValueModificationsToEntity("ResourceDropsite/Types", this.template.Types, this.entity);
let resources = Resources.GetCodes();
return types.split(/\s+/).filter(type => resources.indexOf(type) != -1);
};
/**
* Returns whether this dropsite accepts the given generic type of resource.
*/
ResourceDropsite.prototype.AcceptsType = function(type)
{
return this.GetTypes().indexOf(type) != -1;
};
ResourceDropsite.prototype.IsSharable = function()
{
return this.sharable;
};
ResourceDropsite.prototype.IsShared = function()
{
return this.shared;
};
ResourceDropsite.prototype.SetSharing = function(value)
{
if (!this.sharable)
return;
this.shared = value;
Engine.PostMessage(this.entity, MT_DropsiteSharingChanged, { "shared": this.shared });
};
Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite);