Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Walls.js
/** | /** | ||||
* Returns the wall piece entities needed to construct a wall between start.pos and end.pos. Assumes start.pos != end.pos. | * Returns the wall piece entities needed to construct a wall between start.position and end.position. Assumes start.pos != end.position. | ||||
* The result is an array of objects, each one containing the following information about a single wall piece entity: | * The result is an array of objects, each one containing the following information about a single wall piece entity: | ||||
* - 'template': the template name of the entity | * - 'template': the template name of the entity | ||||
* - 'pos': position of the entity, as an object with keys 'x' and 'z' | * - 'pos': position of the entity, as an object with keys 'x' and 'z' | ||||
* - 'angle': orientation of the entity, as an angle in radians | * - 'angle': orientation of the entity, as an angle in radians | ||||
* | * | ||||
* All the pieces in the resulting array are ordered left-to-right (or right-to-left) as they appear in the physical wall. | * All the pieces in the resulting array are ordered left-to-right (or right-to-left) as they appear in the physical wall. | ||||
* | * | ||||
* @param placementData Object that associates the wall piece template names with information about those kinds of pieces. | * @param placementData Object that associates the wall piece template names with information about those kinds of pieces. | ||||
Show All 12 Lines | function GetWallPlacement(placementData, wallSet, start, end) | ||||
let candidateSegments = ["long", "medium", "short"].map(size => ({ | let candidateSegments = ["long", "medium", "short"].map(size => ({ | ||||
"template": wallSet.templates[size], | "template": wallSet.templates[size], | ||||
"len": placementData[wallSet.templates[size]].templateData.wallPiece.length | "len": placementData[wallSet.templates[size]].templateData.wallPiece.length | ||||
})); | })); | ||||
let towerWidth = placementData[wallSet.templates.tower].templateData.wallPiece.length; | let towerWidth = placementData[wallSet.templates.tower].templateData.wallPiece.length; | ||||
let dir = { | let dir = { | ||||
"x": end.pos.x - start.pos.x, | "x": end.position.x - start.position.x, | ||||
"z": end.pos.z - start.pos.z | "z": end.position.z - start.position.z | ||||
}; | }; | ||||
let len = Math.sqrt(dir.x * dir.x + dir.z * dir.z); | let len = Math.sqrt(dir.x * dir.x + dir.z * dir.z); | ||||
// we'll need room for at least our starting and ending towers to fit next to eachother | // we'll need room for at least our starting and ending towers to fit next to eachother | ||||
if (len <= towerWidth) | if (len <= towerWidth) | ||||
return []; | return []; | ||||
Show All 34 Lines | function GetWallPlacement(placementData, wallSet, start, end) | ||||
let result = []; | let result = []; | ||||
for (let i = 0; i < placedEntities.length; ++i) | for (let i = 0; i < placedEntities.length; ++i) | ||||
{ | { | ||||
let placedEntity = placedEntities[i]; | let placedEntity = placedEntities[i]; | ||||
result.push({ | result.push({ | ||||
"template": placedEntity.template, | "template": placedEntity.template, | ||||
"pos": { | "position": { | ||||
"x": start.pos.x + (progress + spacing + placedEntity.len/2) * dirNormalized.x, | "x": start.position.x + (progress + spacing + placedEntity.len/2) * dirNormalized.x, | ||||
"z": start.pos.z + (progress + spacing + placedEntity.len/2) * dirNormalized.z | "z": start.position.z + (progress + spacing + placedEntity.len/2) * dirNormalized.z | ||||
}, | }, | ||||
"angle": angle, | "angle": angle, | ||||
}); | }); | ||||
if (i < placedEntities.length - 1) | if (i < placedEntities.length - 1) | ||||
{ | { | ||||
result.push({ | result.push({ | ||||
"template": wallSet.templates.tower, | "template": wallSet.templates.tower, | ||||
"pos": { | "position": { | ||||
"x": start.pos.x + (progress + placedEntity.len + 2 * spacing) * dirNormalized.x, | "x": start.position.x + (progress + placedEntity.len + 2 * spacing) * dirNormalized.x, | ||||
"z": start.pos.z + (progress + placedEntity.len + 2 * spacing) * dirNormalized.z | "z": start.position.z + (progress + placedEntity.len + 2 * spacing) * dirNormalized.z | ||||
}, | }, | ||||
"angle": angle, | "angle": angle, | ||||
}); | }); | ||||
} | } | ||||
progress += placedEntity.len + 2 * spacing; | progress += placedEntity.len + 2 * spacing; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator