Most of ETA’s map editor/builder script is complete. The only thing to do now is to add a delete functionality.
See, ETA’s Builder works by spawning a cyan “ghost” tile, moving it with the arrow keys, q, & e, and rotating with middle and right mouse buttons. That all works fine, and the tiles behave exactly the same as the ones made in the Editor. The only problem is that function to delete tiles (by overlapping the ghost tile and then pressing the delete key) doesn’t seem to work.
Currently, I am trying to make it work by using entity’s find() function, and using it to return a tile that shares the same position and rotation as the ghost tile, if such a tile does exist. if it does exist, that tile (not the ghost tile) is then deleted (builder.js, lines 81-95). However, I get an uncaught TypeError when I try it: “Cannot read property ‘type’ of undefined.” Clearly, I seem to misunderstood how Entity’s find() function works. I would be very thankful to anyone who could help me understand how to make the find() function work in this context.
Here is my script: https://playcanvas.com/editor/code/600366?tabs=18801293
EDIT: Here’s the script for my passiveDelete() function:
// script to delete passive tile at same position as ghost when delete is pressed
Builder.prototype.passiveDelete = function() {
var ghost = this.app.root.findByName("Ghost");
var tileToDelete = this.app.root.find(function(node) {
return node.model.type === "box" && node.getLocalPosition() === ghost.getLocalPosition() && node.getLocalRotation() === ghost.getLocalRotation() !== -1; // return any box models (tiles) that have the same position as the ghos tile.
});
// if there is a tile that has the same position as ghost
if (tileToDelete)
// ghost.getLocalPosition() === this.app.root.findByName("Passive_Tile").getLocalPosition()
{
// delete that specific tiles (don't delete tokens, ghost, or UI elements)
tileToDelete.destroy();
}
};