Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Transform.js
// Helper functions to change an entity's template and check if the transformation is possible | // Helper functions to change an entity's template and check if the transformation is possible | ||||
// returns the ID of the new entity or INVALID_ENTITY. | // returns the ID of the new entity or INVALID_ENTITY. | ||||
function ChangeEntityTemplate(oldEnt, newTemplate) | function ChangeEntityTemplate(oldEnt, newTemplate) | ||||
{ | { | ||||
// Done un/packing, copy our parameters to the final entity | const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
const oldTemplate = cmpTemplateManager.GetCurrentTemplateName(oldEnt) | |||||
Engine.UpdateEntityTemplate(newTemplate, oldEnt); | |||||
Engine.PostMessage(oldEnt, MT_TemplateChanged, { "entity": oldEnt, "from": oldTemplate, "to": newTemplate }); | |||||
return oldEnt; | |||||
var newEnt = Engine.AddEntity(newTemplate); | var newEnt = Engine.AddEntity(newTemplate); | ||||
if (newEnt == INVALID_ENTITY) | if (newEnt == INVALID_ENTITY) | ||||
{ | { | ||||
error("Transform.js: Error replacing entity " + oldEnt + " for a '" + newTemplate + "'"); | error("Transform.js: Error replacing entity " + oldEnt + " for a '" + newTemplate + "'"); | ||||
return INVALID_ENTITY; | return INVALID_ENTITY; | ||||
} | } | ||||
Engine.ProfileStart("Transform"); | Engine.ProfileStart("Transform"); | ||||
▲ Show 20 Lines • Show All 309 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator