Re: Progress
Posted: Tue Jul 24, 2012 1:05 pm
Viz:Ahruman wrote:The obvious use case is for tagging subentities of interest to a script, instead of relying on indices.
Code: Select all
/*
findSubEntityGroups(ship)
Find subentities identified by tags in shipdata.plist.
In shipdata.plist, tags take the form:
script_info =
{
tags = ( "tag1", "tag2" );
};
findSubEntityGroups() returns an object with one array of subentities
for each used tag. Each subentity may have any number of tags.
*/
function findSubEntityGroups(ship)
{
let groups = {};
ship.subEntities.forEach(function (sub)
{
let tags = sub.scriptInfo.tags;
if (tags && tags.length) tags.forEach(function (tag)
{
let groupForTag = groups[tag];
if (groupForTag) groupForTag.push(sub);
else groups[tag] = [sub];
});
});
return groups;
}